Corrections in play_move()

This commit is contained in:
Yorick Barbanneau 2021-10-15 16:39:52 +02:00
parent e9dca0371f
commit 8db53c2eaf
2 changed files with 20 additions and 13 deletions

View file

@ -45,7 +45,6 @@ char get_short_player(e_player player){
}
}
#define SHORT_VERSION(code) SHORT_##code
/*
* Create empty move
@ -265,7 +264,6 @@ e_status play_move(s_utictactoe *p_uttt, s_move *p_move) {
if (is_move_valid(p_uttt, p_move) == NO) {
return NO;
}
p_uttt->outer_tictactoe->content[p_move->outer_position] = p_move->player;
list_element_s_move *value = (list_element_s_move*)
malloc(sizeof(list_element_s_move));

View file

@ -140,15 +140,24 @@ int main(int argc, char* argv[]) {
exit (EXIT_FAILURE);
}
}
s_move *test_move = create_empty_move();
free_move(test_move);
s_tictactoe *test_ttt = create_empty_tictactoe();
free_tictactoe(test_ttt);
s_utictactoe *test_uttt = create_empty_utictactoe(1);
free_utictactoe(test_uttt);
test_uttt = create_empty_utictactoe(2);
free_utictactoe(test_uttt);
test_uttt = create_empty_utictactoe(3);
free_utictactoe(test_uttt);
FILE *f = fopen("save.txt", "w+");
s_utictactoe *s = create_empty_utictactoe(2); //replace by 2 for uttt play
s_move *m = create_empty_move();
m->outer_position = TOPLEFT + rand() % TICTACTOE_SIZE;
while (s->outer_tictactoe->winner == NOBODY) {
draw_utictactoe(s);
m->player = get_next_player_to_play(s);
m->inner_position = TOPLEFT + rand() % TICTACTOE_SIZE;
play_move(s, m);
m->outer_position = m->inner_position;
}
draw_utictactoe(s);
draw_utictactoe_history(s);
save_a_utictactoe_to_file(f, s);
printf("The winner is : %c\n", s->outer_tictactoe->winner);
free_move(m);
free_utictactoe(s);
fclose(f);
return EXIT_SUCCESS;
}
}