#include #include #include using namespace std; // move class specification to header file class Board { public: char at(int x, int y) const; bool game_over(char& winner) const; void print() const; bool place_brick(int column, char player); private: bool is_horizontal_win_at(int x, int y) const; bool is_vertical_win_at(int x, int y) const; bool is_down_right_diagonal_win_at(int x, int y) const; bool is_up_right_diagonal_win_at(int x, int y) const; bool is_full_board() const; }; // move class implementation to cc-file // return character at row y and column x on the board // return space if out of range char Board::at(int x, int y) const { } // return true if x,x+1,x+2,x+3 on row y are equal bool Board::is_horizontal_win_at(int x, int y) const { char c = at(x, y); for ( int i = 1; i < 4; ++i ) { if ( at(x + i, y) != c ) return false; } return true; } // return true if y,y+1,y+2,y+3 on column x are equal bool Board::is_vertical_win_at(int x, int y) const { char c = at(x, y); for ( int i = 1; i < 4; ++i ) { if ( at(x, y + i) != c ) return false; } return true; } // return true if four values on the diagonal down to right starting // at x,y are equal bool Board::is_down_right_diagonal_win_at(int x, int y) const { char c = at(x, y); for ( int i = 1; i < 4; ++i ) { if ( at(x + i, y + i) != c ) return false; } return true; } // return true if four values on the diagonal up to right starting // at x,y are equal bool Board::is_up_right_diagonal_win_at(int x, int y) const { char c = at(x, y); for ( int i = 1; i < 4; ++i ) { if ( at(x + i, y - i) != c ) return false; } return true; } // return true if no more bricks can be placed bool Board::is_full_board() const { } // return true if one player won (and set the winner) // return true if it was a draw (but do not set the winner) bool Board::game_over(char& winner) const { } // drop players brick at colum, make sure it falls to correct place bool Board::place_brick(int column, char player) { } // print the game board void Board::print() const { cout << "|0123456|" << endl; for every row // fixme, still pseudo code { cout << '|'; for every column in current row // fixme, still pseudo code { cout << col; } cout << '|' << endl; } cout << "+-------+" << endl; } // the main program will work if the class is okay // no modifications needed int main() { Board board; char turn{'x'}; char winner{' '}; while ( ! board.game_over( winner ) ) { int column; cout << turn << " chose column: "; cin >> column; cout << turn << " picked column " << column << endl; if ( board.place_brick( column, turn) ) { board.print(); if ( turn == 'x' ) turn = 'o'; else turn = 'x'; } } if (winner == ' ') cout << "It's a draw." << endl; else cout << "'" << winner << "' wins!" << endl; cout << endl; return 0; }