Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Gomoku in C++

Gomoku in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++game-devquestionlounge
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 14965004
    wrote on last edited by
    #1

    Hi . Recently i've got to make a game called gomoku between two players . Now i need to edit it and change it from PVP to versus computer . I understand that in order of getting a random number from computer i can use and rand() , and the letter by something like this :

    char letters[] = "abcdefghijklmnopqrstuvwxyz";
    char x = letters[rand() % 26];

    Now my question is how i can add it in my program , i tried to put them in but it still is not generating a move from computer . Here's my code,maybe u have some ideas

    #include
    #include
    using namespace std;

    void print_table(int x[][15]) {
    system("cls");
    for (int i = 0; i < 15; i++) {//the loop that use to print out the english character row
    if (i == 0)
    cout << setw(4) << "A";
    else if (i == 1)
    cout << " B";
    else if (i == 2)
    cout << " C";
    else if (i == 3)
    cout << " D";
    else if (i == 4)
    cout << " E";
    else if (i == 5)
    cout << " F";
    else if (i == 6)
    cout << " G";
    else if (i == 7)
    cout << " H";
    else if (i == 8)
    cout << " I";
    else if (i == 9)
    cout << " J";
    else if (i == 10)
    cout << " K";
    else if (i == 11)
    cout << " L";
    else if (i == 12)
    cout << " M";
    else if (i == 13)
    cout << " N";
    else if (i == 14)
    cout << " O";
    else if (i == 15)
    cout << " P";
    }
    cout << endl;
    for (int i = 0; i < 15; i++) {
    cout << setw(2) << i;//print out the row number
    for (int j = 0; j < 15; j++) {//print out the board game.
    if (x[i][j] == 0) {//the inital value is 0, so when the block is 0 then print out the '.'
    cout << " .";
    }
    else if (x[i][j] == 1) {//when the player O input the block then the value will adding one then if check the block is one then output the 'o'
    cout << " O";
    }
    else if (x[i][j] == 2) {//when the player X input the block then the value will adding two then if check the block is two then output the 'x'
    cout << " X";
    }
    }
    cout << endl;
    }
    }
    int check_player(int p) {
    if (p == 1) {//change the player everytime before the next loop compile
    p++;
    }
    else {
    p--;
    }
    return p;
    }
    void input_value(int &t, int &n, int p, int x[][15]) {
    char eng;
    int number;
    do {//the loop that ask for the user input the location.
    cout << "player ";
    if (p == 1) {
    cout << "O";
    }
    else {
    cout << "X";
    }
    cout << ", make a move: ";
    cin >> eng;//input the location
    cin >> number;
    if (eng == 'A')//

    Greg UtasG 1 Reply Last reply
    0
    • U User 14965004

      Hi . Recently i've got to make a game called gomoku between two players . Now i need to edit it and change it from PVP to versus computer . I understand that in order of getting a random number from computer i can use and rand() , and the letter by something like this :

      char letters[] = "abcdefghijklmnopqrstuvwxyz";
      char x = letters[rand() % 26];

      Now my question is how i can add it in my program , i tried to put them in but it still is not generating a move from computer . Here's my code,maybe u have some ideas

      #include
      #include
      using namespace std;

      void print_table(int x[][15]) {
      system("cls");
      for (int i = 0; i < 15; i++) {//the loop that use to print out the english character row
      if (i == 0)
      cout << setw(4) << "A";
      else if (i == 1)
      cout << " B";
      else if (i == 2)
      cout << " C";
      else if (i == 3)
      cout << " D";
      else if (i == 4)
      cout << " E";
      else if (i == 5)
      cout << " F";
      else if (i == 6)
      cout << " G";
      else if (i == 7)
      cout << " H";
      else if (i == 8)
      cout << " I";
      else if (i == 9)
      cout << " J";
      else if (i == 10)
      cout << " K";
      else if (i == 11)
      cout << " L";
      else if (i == 12)
      cout << " M";
      else if (i == 13)
      cout << " N";
      else if (i == 14)
      cout << " O";
      else if (i == 15)
      cout << " P";
      }
      cout << endl;
      for (int i = 0; i < 15; i++) {
      cout << setw(2) << i;//print out the row number
      for (int j = 0; j < 15; j++) {//print out the board game.
      if (x[i][j] == 0) {//the inital value is 0, so when the block is 0 then print out the '.'
      cout << " .";
      }
      else if (x[i][j] == 1) {//when the player O input the block then the value will adding one then if check the block is one then output the 'o'
      cout << " O";
      }
      else if (x[i][j] == 2) {//when the player X input the block then the value will adding two then if check the block is two then output the 'x'
      cout << " X";
      }
      }
      cout << endl;
      }
      }
      int check_player(int p) {
      if (p == 1) {//change the player everytime before the next loop compile
      p++;
      }
      else {
      p--;
      }
      return p;
      }
      void input_value(int &t, int &n, int p, int x[][15]) {
      char eng;
      int number;
      do {//the loop that ask for the user input the location.
      cout << "player ";
      if (p == 1) {
      cout << "O";
      }
      else {
      cout << "X";
      }
      cout << ", make a move: ";
      cin >> eng;//input the location
      cin >> number;
      if (eng == 'A')//

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      You need to learn how to use a debugger to find your problem. It will allow you to step through your code, one line at a time, to find out where it's doing something unexpected. I will point out, however, that you can map a char to a range that starts at 0 like this:

      t = eng - 'A';

      'A' through 'Z' have contiguous values, so this maps eng to 0 to 25, assuming that it was an uppercase letter. You can check for invalid input with

      if((t < 0) || (t > 14))... // or t > ('O' - 'A')

      Similarly, you can write

      cout << ' ' << i + 'A';

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups