Skip to content
Snippets Groups Projects
Commit e4260e7a authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Changed implementation for function move_penguin()

parent 4f27362e
No related branches found
No related tags found
No related merge requests found
......@@ -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));
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment