summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam T. Carpenter <Commodore@chunkybluegiant>2025-04-28 19:05:31 -0400
committerAdam T. Carpenter <Commodore@chunkybluegiant>2025-04-28 19:05:31 -0400
commita29cbeb61004d53a0afb1b7fe2339bf591a21007 (patch)
treed0ad017d180f1a95fb769b6f4e72d0e74219acf9 /src
parentd770b616f4ee72e4ef5ab0e6b8bed205c7ac4429 (diff)
downloadttt-c64-master.tar.xz
ttt-c64-master.zip
feat: validate player moveHEADmaster
Diffstat (limited to 'src')
-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;
}