Next step in this program

So I've decided that the next program that I'm going to make is a traditional checkered board game. The first thing that I knew I had to do was to display the board with the checkered pieces placed at the appropriate spots. The next thing I know I need to do is to set up the traditional rules of the game. What I'm asking is how should go about setting up the rules? should I do a separate class or a nested class? Much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>

using namespace std;

class CheckerBoard
{
public:
    void setBoard() // Initializes the board.
    {
        for(int x=0; x<8; x++)
        {
            for(int y=0; y<8; y++)
            {
                if ((x < 3) && ((y + x) % 2) == 0)
                {
                    board[x][y] = "R"; // Red Checkered piece

                }
                else if ((x > 4) && ((y + x) % 2) == 0)
                {
                    board[x][y] = "B"; // Black Checkered piece
                }
                else if(((y + x) % 2) == 0)
                {
                    board[x][y] = "+"; // white spot

                }
                else if ((y + x) % 2 == 1)
                {
                    board[x][y] = "-"; // black spot
                }

            }
        }
    }

    void PrintBoard() // Displays the board.
    {
        for(int x=0; x<8; x++)
        {
            for(int y=0; y<8; y++)
            {
                cout << board[x][y] << "    ";
            }
            cout << endl; // end line.
        }
    }

private:
    string board[8][8];
};

int main()
{
    CheckerBoard board;
    board.setBoard();
    board.PrintBoard();
    return 0;
}
Last edited on
You could make a function to get the players input (player 1 one turn, player 2 the next) and then another function to validate the move, and any other sub functions you may need for additional rules.
the logic of the game.
Is there any way to validate each players move without doing a lot of if/else if statements?
Depends what is being validated. You can probably use loops and ifs or switch
I think I much rather use loops seeing as though as this is a big grid. Even though you're not allowing to move on every tile in checkers, that is still alot of tiles to check. Oh, and sorry for the late reply.
Topic archived. No new replies allowed.