Good, so I'm incredibly close to completing this program. I understand why my program did not move, and I was able to fix it, but now I'm trying to check the winner. I understand that my winGame() function must be at some point or do a while loop to finish the game. But, when I tried to do a little debugging to figure out some things, I understand something alarming. He always says that this is a draw, even if it should not be. These are such secondary things that I am ashamed not to understand, and I would very much like to help in how I can fix this. In addition, I know that there must be some time or a cycle to complete the game if there is a victory. I just don’t know where to express it, so if you have any suggestions, please let me know.
* Please note that there is a small array in my actual move function, I plan to make it a static const array. My get functions return a value in the name (for example, getIval () returns the initial value of a cell object), while my set functions simply assign values accordingly.
bool TicTacToe::validMove(char move){ char options[9] = { '1','2', '3', '4','5','6','7', '8','9' }; bool validate = false; for ( int i = 0; i < 9; i++ ){ if ( move == options[i]){ validate = true; } } return ( validate ); } void TicTacToe::setMove( char move ){ for ( int i = 0; i < ROW; i++ ){ for ( int j = 0; j < COL; j++ ){ if ( board[i][j].getiVal() == move ){ board[i][j].setiVal( players[currentPlayer].getMarker() ); switchPlayer(); break; } } } } void TicTacToe::makeAMove(){ char move; int turns = 1; bool validate = true; do{ cout << "Player " << (getCurrentPlayer() + 1) << " make a move." << endl; cin >> move; if ( validMove( move ) ){ if ( turns > 4 ){ cout << "Nested if-else statement." << endl; winGame(); setMove( move ); } else setMove(move); } else{ cout << "Invalid Move. Please reenter." << endl; cin >> move; } DrawBoard(); turns++; } while ( turns <= 9 ); } bool TicTacToe::winGame(){ cout << "Calling winGame() " << endl; bool validate = false; int k = 0; for ( int i = 0; i < COL; i++ ){
Here is an example of starting a program for your reference.
source share