diff --git a/game.c b/game.c index b0f3c4f..3af4735 100644 --- a/game.c +++ b/game.c @@ -53,7 +53,7 @@ game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { for (int j = 0; j < g2->width; j++) { - if (g1->tab_cell[i][j] == (S_BLANK | S_LIGHTBULB | S_MARK)){ + if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK){ game_play_move(g2, i, j, g1->tab_cell[i][j]); } else { @@ -172,6 +172,7 @@ void game_play_move(game g, uint i, uint j, square s) { } else { g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j)); + g->hist = history_delete_all_after(g->hist, g->hist); } } diff --git a/game_ext.c b/game_ext.c index ee7854e..9dca5b1 100644 --- a/game_ext.c +++ b/game_ext.c @@ -56,6 +56,14 @@ bool game_is_wrapping(cgame g) { } void game_undo(game g) { + if (history_prev(g->hist) == NULL){ + printf("waiting for your first move"); + } + else{ + game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); + game_update_flags(g); + g->hist = history_prev(g->hist); + } return; }