Call checkForWinner
after each turn. Once you get back true
, you know that whoever was the last one to move is the winner.
This is because you have checked the board before the last move, and there has been no winner at the time (otherwise, you would have exited the game earlier). Now that we have a winner, whoever made the last move must be the player who won.
Note that your current call of checkForWinner
is useless, because you ignored the return value. Currently, the flag
remains unassigned.
The call of displayWinner
needs to take the winner number, not a flag
.