Tic Tac Toe - With "Undo Move"

All that remains is to implement the "undo" feature. We'll flesh out the undo_move() function. undo_move() converts the last_move variable into a row and column. It "erases" the move in that position, changes whose turn it is, decreases the move count, and redraws the status and board position.

We now have a fully functional tic tac toe game!

Return to GIL.


[...]
bool undo_move()
{
	int move_r, move_c;
	
	if (last_move != NO_MOVE) {
		move_r = last_move / 3;
		move_c = last_move % 3;
		board[move_r][move_c] = PNONE;
		last_move = NO_MOVE;
		x_turn = !x_turn;
		move_count--;
		winner = PNONE;
		
		show_move(move_r, move_c);
		show_status();
		}
	GSdisablemenuitem(GAME_MENU, UNDO);
	return TRUE;
}
[...]

forward