From 48c6360b0d81ae3cc2b78395160d1e48d490d4de Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 1 Oct 2021 16:19:21 +0200 Subject: [PATCH] update is_move_valid --- src/model.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/model.c b/src/model.c index 709c768..b357fd3 100644 --- a/src/model.c +++ b/src/model.c @@ -129,6 +129,27 @@ e_status is_move_valid(s_utictactoe *p_uttt, s_move *p_move){ if ( get_next_player_to_play(p_uttt) != p_move->player ) { return NO; } + if ( p_uttt->inception_level == 1 ) { + if ( p_uttt->outer_tictactoe->winner == NOBODY + && p_uttt->outer_tictactoe->content[p_move->outer_position] == NOBODY) { + return YES; + } + else { + return NO; + } + } + else { + if (p_uttt->outer_tictactoe->winner == NOBODY + && p_uttt->inner_tictactoes[p_move->outer_position]->content[p_move->inner_position] == NOBODY + && p_uttt->inner_tictactoes[p_move->outer_position]->winner == NOBODY ) + { + return YES; + } + else + { + return NO; + } + } return YES; } @@ -187,7 +208,7 @@ void set_tictactoe_winner(s_tictactoe *p_ttt){ find = true; for (int c = 1; c < TICTACTOE_WIDTH; c++ ) { next = TICTACTOE_WIDTH * c + i; - if ( p_ttt->content[i] != p_ttt->content[next] ) { + if ( p_ttt->content[i] != p_ttt->content[next]) { find = false; break; } @@ -219,6 +240,15 @@ void set_tictactoe_winner(s_tictactoe *p_ttt){ } } -e_status play_move(s_utictactoe *p_ttt, s_move *p_move) { +e_status play_move(s_utictactoe *p_uttt, s_move *p_move) { + if (is_move_valid(p_uttt, p_move) == YES) { + // we can process things + if ( p_uttt->inception_level == 1 ) { + p_uttt->outer_tictactoe->content[p_move->outer_position] = p_move->player; + } + else { + + } + } return YES; }