diff --git a/src/game/penguin.cpp b/src/game/penguin.cpp index eacc90ae91cca5d30c8cbbec62e1294da9492926..94fe0e454fcaff6305625358eeca3adf15962b0c 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