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

Started migration towards array of penguins for every player instead of different variables

parent a8a03539
No related branches found
No related tags found
No related merge requests found
......@@ -28,17 +28,13 @@ namespace game
{
if(json_state["penguins"].count("red"))
{
state.p1_red = json_state["penguins"]["red"][0];
state.p2_red = json_state["penguins"]["red"][1];
state.p3_red = json_state["penguins"]["red"][2];
state.p4_red = json_state["penguins"]["red"][3];
for(int i = 0; i < 4; i++)
state.peng_red[i] = json_state["penguins"]["red"][i];
}
if(json_state["penguins"].count("blue"))
{
state.p1_blue = json_state["penguins"]["blue"][0];
state.p2_blue = json_state["penguins"]["blue"][1];
state.p3_blue = json_state["penguins"]["blue"][2];
state.p4_blue = json_state["penguins"]["blue"][3];
for(int i = 0; i < 4; i++)
state.peng_blue[i] = json_state["penguins"]["blue"][i];
}
}
if(json_state.count("score"))
......@@ -46,7 +42,7 @@ namespace game
if(json_state["score"].count("red")) { state.score_red = json_state["score"]["red"]; }
if(json_state["score"].count("blue")) { state.score_blue = json_state["score"]["blue"]; }
}
//Update moves on all penguins
uint64_t obstacles = (~(state.one_fish | state.two_fish | state.three_fish));
obstacles |= ((uint64_t) 1) << (state.p1_red & 63);
......@@ -68,7 +64,7 @@ namespace game
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_red == 0)
{
state.canPlay_red = false;
......@@ -388,7 +384,7 @@ namespace game
state.nb_moves_red = 0;
state.nb_moves_blue = 0;
if (state.current_player_red) //Red just played
{
if(state.canPlay_blue)
......@@ -407,7 +403,7 @@ namespace game
{
state.nb_moves_blue = 1;
}
state.current_player_red = false;
}
else //Blue just played
......@@ -428,7 +424,7 @@ namespace game
{
state.nb_moves_red = 1;
}
state.current_player_red = true;
}
}
......@@ -476,7 +472,7 @@ namespace game
json_state["possible_moves"]["blue"] = state.nb_moves_blue;
json_state["current_player"] = state.current_player_red ? "Red" : "Blue";
json_state["can_play"]["red"] = state.canPlay_red;
json_state["can_play"]["blue"] = state.canPlay_blue;
......
......@@ -18,6 +18,9 @@ namespace game
uint64_t three_fish = 0; //Position of three-fish tiles (bitboard)
//Penguins
uint32_t peng_red[4] = {0, 1, 6, 7};
uint32_t peng_blue[4] = {59, 58, 53, 54};
//TODO: delete
uint32_t p1_red = 0;
uint32_t p2_red = 1;
uint32_t p3_red = 6;
......@@ -67,6 +70,7 @@ namespace game
std::uint64_t hash() const;
private:
//TODO: modify/delete functions
penguin_state state;
uint32_t* penguin_that_moves(uint16_t move_number);
void move_penguin(uint32_t* p);
......
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