From 7fd4f5c6aa0acdb6e5a6a36379b6803ddffebadf Mon Sep 17 00:00:00 2001 From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr> Date: Mon, 21 Mar 2016 10:42:07 +0100 Subject: [PATCH] Deleted useless penguin refresh in play --- src/game/penguin.cpp | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/game/penguin.cpp b/src/game/penguin.cpp index eacc90a..94fe0e4 100644 --- a/src/game/penguin.cpp +++ b/src/game/penguin.cpp @@ -327,9 +327,7 @@ namespace game //Move the current penguin move_penguin(p); - cout << "Penguin p :" << *p << endl; - - //Update moves on all penguins + //Update moves on all penguins of the next player uint64_t obstacles = (~(state.one_fish | state.two_fish | state.three_fish)); obstacles |= ((uint64_t) 1) << (state.p1_red & 63); obstacles |= ((uint64_t) 1) << (state.p2_red & 63); @@ -340,25 +338,41 @@ namespace game obstacles |= ((uint64_t) 1) << (state.p3_blue & 63); obstacles |= ((uint64_t) 1) << (state.p4_blue & 63); - cout << obstacles << endl; - state.nb_moves_red = 0; state.nb_moves_blue = 0; - state.nb_moves_red += update_moves(&state.p1_red, obstacles); - state.nb_moves_red += update_moves(&state.p2_red, obstacles); - state.nb_moves_red += update_moves(&state.p3_red, obstacles); - state.nb_moves_red += update_moves(&state.p4_red, obstacles); - state.nb_moves_blue += update_moves(&state.p1_blue, obstacles); - state.nb_moves_blue += update_moves(&state.p2_blue, obstacles); - state.nb_moves_blue += update_moves(&state.p3_blue, obstacles); - state.nb_moves_blue += update_moves(&state.p4_blue, obstacles); - - //Change player if the other one can play - if(state.current_player_red && state.nb_moves_blue > 0) - state.current_player_red = false; - else if(state.current_player_red == false && state.nb_moves_red > 0) - state.current_player_red = true; - + + if (state.current_player_red) //Red just played + { + state.nb_moves_blue += update_moves(&state.p1_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p2_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p3_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p4_blue, obstacles); + if (state.nb_moves_blue == 0) //If Blue can not move we update moves for red + { + state.nb_moves_red += update_moves(&state.p1_red, obstacles); + state.nb_moves_red += update_moves(&state.p2_red, obstacles); + state.nb_moves_red += update_moves(&state.p3_red, obstacles); + state.nb_moves_red += update_moves(&state.p4_red, obstacles); + } + else + { state.current_player_red = false; } + } + else //Blue just played + { + state.nb_moves_red += update_moves(&state.p1_red, obstacles); + state.nb_moves_red += update_moves(&state.p2_red, obstacles); + state.nb_moves_red += update_moves(&state.p3_red, obstacles); + state.nb_moves_red += update_moves(&state.p4_red, obstacles); + if (state.nb_moves_red == 0) + { + state.nb_moves_blue += update_moves(&state.p1_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p2_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p3_blue, obstacles); + state.nb_moves_blue += update_moves(&state.p4_blue, obstacles); + } + else + { state.current_player_red = true; } + } } string penguin::player_to_string(uint8_t player) const -- GitLab