From a29cbeb61004d53a0afb1b7fe2339bf591a21007 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Mon, 28 Apr 2025 19:05:31 -0400 Subject: feat: validate player move --- src/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 9d02aa9..ae530a2 100644 --- a/src/main.c +++ b/src/main.c @@ -96,14 +96,15 @@ void player_move(BOARD board) { char move_x = EMPTY; char move_y = EMPTY; - printf("Enter a move..."); - - move = cgetc() - '0' - 1; - // if move is not a number then bail - // if (move < 1 || move > 8) { invalid! } - move_x = move % 3; - move_y = move / 3; - // if move not already taken + do { + printf("\nEnter a valid move..."); + + move = cgetc() - '0' - 1; + printf("%d\n", move); + move_x = move % 3; + move_y = move / 3; + } while (0 <= move_x <= move_y <= 2 && board[move_y][move_x] != EMPTY); + board[move_y][move_x] = X; } -- cgit v1.2.3