Re-add winner test for outer_ttt in is_move_valid()

This commit is contained in:
Yorick Barbanneau 2021-10-07 23:23:18 +02:00
parent e6449a2013
commit 0e8fb22424

View file

@ -134,12 +134,10 @@ e_location get_next_outer_position(s_utictactoe *p_uttt) {
}
e_status is_move_valid(s_utictactoe *p_uttt, s_move *p_move) {
// the party is not over?
// Get back thois simple test
if ( p_uttt->outer_tictactoe->winner != NOBODY ) {
return NO;
}
// this is the awaited player that played?
if ( get_next_player_to_play(p_uttt) != p_move->player ) {
return NO;
@ -151,10 +149,22 @@ e_status is_move_valid(s_utictactoe *p_uttt, s_move *p_move) {
return NO;
}
if ( p_uttt->inception_level == 1 ) {
if ( p_uttt->outer_tictactoe->content[p_move->outer_position] != NOBODY ) {
return NO;
}
}
else {
// Already winned inner TTT
if ( p_uttt->inner_tictactoes[p_move->outer_position]->winner != NOBODY ) {
return NO;
}
// position in the inner position is free?
if ( p_uttt->inner_tictactoes[p_move->outer_position]->content[p_move->inner_position] != NOBODY ) {
return NO;
}
}
return YES;
}