diff --git a/AI/src/game/penguin.cpp b/AI/src/game/penguin.cpp index 180ab435bfbfc70f17b5f2dfd8e15b6574663f3c..7e1a7e026a87fb899ffda2bf8f9d0b803e5b2c9b 100644 --- a/AI/src/game/penguin.cpp +++ b/AI/src/game/penguin.cpp @@ -135,53 +135,56 @@ namespace game return state.current_player_red ? state.nb_moves_red : state.nb_moves_blue; } - void penguin::move_penguin(uint32_t* p) + /* + Moves the penguin p (modify its position value), making it do its rel_move move. + At the end of the function the penguin will be composed of just its new position (every other bit is at 0) + */ + void penguin::move_penguin(uint32_t* p, uint16_t rel_move) { - uint8_t move_number = ((*p) >> 6) & 63; //Move number for the current penguin uint32_t penguin_copy = (*p) >> 12; //Direction A - if((penguin_copy & 7) > move_number) + if((penguin_copy & 7) > rel_move) //If the penguin total moves in this direction are greater than the move we want to do for it (not equal because moves start at 0) { //Move direction A - (*p) = (7 * (move_number +1)) + ((*p) & 63); + (*p) = (7 * (rel_move +1)) + ((*p) & 63); return; } - move_number -= penguin_copy & 7; + rel_move -= penguin_copy & 7; penguin_copy = penguin_copy >> 3; - if((penguin_copy & 7) > move_number) + if((penguin_copy & 7) > rel_move) { //Move direction B - (*p) = (-1 * (move_number +1)) + ((*p) & 63); + (*p) = (-1 * (rel_move +1)) + ((*p) & 63); return; } - move_number -= penguin_copy & 7; + rel_move -= penguin_copy & 7; penguin_copy = penguin_copy >> 3; - if((penguin_copy & 7) > move_number) + if((penguin_copy & 7) > rel_move) { //Move direction C - (*p) = (-8 * (move_number +1)) + ((*p) & 63); + (*p) = (-8 * (rel_move +1)) + ((*p) & 63); return; } - move_number -= penguin_copy & 7; + rel_move -= penguin_copy & 7; penguin_copy = penguin_copy >> 3; - if((penguin_copy & 7) > move_number) + if((penguin_copy & 7) > rel_move) { //Move direction D - (*p) = (-7 * (move_number +1)) + ((*p) & 63); + (*p) = (-7 * (rel_move +1)) + ((*p) & 63); return; } - move_number -= penguin_copy & 7; + rel_move -= penguin_copy & 7; penguin_copy = penguin_copy >> 3; - if((penguin_copy & 7) > move_number) + if((penguin_copy & 7) > rel_move) { //Move direction E - (*p) = (1 * (move_number +1)) + ((*p) & 63); + (*p) = (1 * (rel_move +1)) + ((*p) & 63); return; } - move_number -= penguin_copy & 7; + rel_move -= penguin_copy & 7; penguin_copy = penguin_copy >> 3; //Move direction F - (*p) = (8 * (move_number +1)) + ((*p) & 63); + (*p) = (8 * (rel_move +1)) + ((*p) & 63); } int penguin::update_moves(uint32_t* p, uint64_t obstacles) @@ -308,13 +311,11 @@ namespace game //We replace this tile with an empty one (0 in the bitboard) state.one_fish = state.one_fish & ~(((uint64_t) 1) << POS(*peng)); } - /* - //TODO: implements methods with arrays - //Move the current penguin - move_penguin(p); - */ + // MOVE THE PENGUIN + move_penguin(peng, rel_move); } + // END CAN_WE PLAY. We will now compute the moves for every penguin and for the player. //Update moves on all penguins of the next player uint64_t obstacles = (~(state.one_fish | state.two_fish | state.three_fish)); diff --git a/AI/src/game/penguin.hpp b/AI/src/game/penguin.hpp index 1ec2fec1b9bd05c9bd6f70ff291363f7ed016243..c8aa7a76e80357006e98a817baf09c1679315621 100644 --- a/AI/src/game/penguin.hpp +++ b/AI/src/game/penguin.hpp @@ -72,7 +72,7 @@ namespace game private: //TODO: modify/delete functions penguin_state state; - void move_penguin(uint32_t* p); + void move_penguin(uint32_t* p, uint16_t rel_move); int update_moves(uint32_t* p, uint64_t obstacles); const uint8_t RED = 0;