update is_move_valid
This commit is contained in:
parent
aa72f3bc30
commit
48c6360b0d
1 changed files with 32 additions and 2 deletions
34
src/model.c
34
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue