#include <iostream>
class Board
{
private:
static const int NO_ROWS{3};
static const int NO_COLS{3};
const int COLS = 3;
const int ROWS = 3;
const int MAX_MOVES = COLS * ROWS; //total cells on the board
char symbol[3]{'*', 'O', 'X'};
char board[NO_ROWS][NO_COLS];
int NO_MOVES{0};
int MAX_NO_MOVES;
public:
Board()
{
for(int row = 0; row < NO_ROWS; row++)
{
for(int col = 0; col < NO_COLS; col++)
{
board[row][col] = symbol[0];
}
}
};
~Board(){};
void display()
{
for(int row = 0; row < NO_ROWS; row++)
{
for(int col = 0; col < NO_COLS; col++)
{
std::cout << board[row][col] << ' ';
}
std::cout << '\n';
}
}
bool move(int player, int row, int col)
{
if( isValidMove(row,col) )
{
board[row][col] = symbol[player];
NO_MOVES++;
display();
return true;
}
else
{
std::cout
<< row << '-' << col << " is not a valid move ... try again\n\n";
return false;
}
}
bool isValidMove(int row, int col)
{
if( board[row][col] == symbol[0])
return true;
else
return false;
}
int getMoveCount()
{
return NO_MOVES;
}
void SwapPlayer(int player)
{
if (player == 1)
{
player = 2;
}
else if (player == 2)
{
player = 1;
}
}
};
using namespace std;
int main()
{
cout << "Let's Play Connect 3. Below is the initial game board.\n"
<<"Select column number 1, 2, 3; along the top; to indicate your move.\n"
<< endl;
// display #'s on game board
cout<<"1 2 3\n";
cout <<"-----\n";
// displays board
Board playingBoard;
playingBoard.display();
cout<<endl;
cout << "The two player tokens are X and O. X begins.";
return 0;
}
/*
not sure if this will be what i need in my code but it checks for wins
i-1] [j-1] [i-1][j] [i-1][j+1]
[i][j-1] [i][j] [i][j+1]
[i+1][j-1] [i+1][j] [i+1][j+1]
// horizontalCheck
for (int j = 0; j<getHeight()-1 ; j++ ){
for (int i = 0; i<getWidth(); i++){
if (this.board[i][j] == player && this.board[i][j+1] == player && this.board[i][j+1] == player && this.board[i][j+1] == player){
return true;
}
}
}
// verticalCheck
for (int i = 0; i<getWidth()-1 ; i++ ){
for (int j = 0; j<this.getHeight(); j++){
if (this.board[i][j] == player && this.board[i+1][j] == player && this.board[i+1][j] == player && this.board[i+1][j] == player){
return true;
}
}
}
// ascendingDiagonalCheck
for (int i=1; i<getWidth(); i++){
for (int j=0; j<getHeight()-3; j++){
if (this.board[i][j] == player && this.board[i-1][j+1] == player && this.board[i-1][j+1] == player && this.board[i-1][j+1] == player)
return true;
}
}
// descendingDiagonalCheck
for (int i=1; i<getWidth(); i++){
for (int j=3; j<getHeight(); j++){
if (this.board[i][j] == player && this.board[i-1][j-1] == player && this.board[i-1][j-1] == player && this.board[i-1][j-1] == player)
return true;
}
}
return false;
}
*/