summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files 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;
}