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

The game now loads initial state from stdin

parent c5783f97
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,10 @@ public class Controller implements Initializable
e.printStackTrace();
System.exit(1);
}
// SENDING STATE TO THE GAME
// TODO: 5/10/16 Creating a state and sending it to the game
String state = "{}";
gameInput.println(state);
//Choice: who will start?
ChoiceDialog<Player> playerChoice = new ChoiceDialog<>(Player.Red, Player.Red, Player.Blue);
playerChoice.setTitle("Penguin game!");
......
......@@ -5,8 +5,48 @@ using namespace std;
namespace game
{
/**
* Creates the game: load the state from standard input.
* Penguins in state can be composed of just their position: the moves will be updated automatically.
**/
penguin::penguin()
{
cout << "Enter penguin game state as JSON on one line" << endl;
string line;
getline(cin, line);
json json_state = json::parse(line);
//Charging every element of the state if it exists
if(json_state.count("bitboards"))
{
if(json_state["bitboards"].count("onefish")) {state.one_fish = json_state["bitboards"]["onefish"];}
if(json_state["bitboards"].count("twofish")) {state.two_fish = json_state["bitboards"]["twofish"];}
if(json_state["bitboards"].count("threefish")) {state.three_fish = json_state["bitboards"]["threefish"];}
}
if(json_state.count("current_player"))
state.current_player_red = json_state["current_player"] == "Red" ? true : false;
if(json_state.count("penguins"))
{
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];
}
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];
}
}
if(json_state.count("score"))
{
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);
......@@ -28,6 +68,17 @@ 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;
state.nb_moves_red = 1; //We create an artificial move so that the mcts works
}
if (state.nb_moves_blue == 0)
{
state.canPlay_blue = false;
state.nb_moves_blue = 1; //We create an artificial move so that the mcts works
}
}
shared_ptr<game<penguin_state>> penguin::do_copy() const
......
......@@ -13,19 +13,19 @@ namespace game
{
struct penguin_state
{
uint64_t one_fish = 533050011236269409; //Position of one-fish tiles (bitboard)
uint64_t two_fish = 40552008684274318; //Position of two-fish tiles (bitboard)
uint64_t three_fish = 579319484686303248; //Position of three-fish tiles (bitboard)
uint64_t one_fish = 1152921504606846975; //Position of one-fish tiles (bitboard)
uint64_t two_fish = 0; //Position of two-fish tiles (bitboard)
uint64_t three_fish = 0; //Position of three-fish tiles (bitboard)
//Penguins
uint32_t p1_red = 24;
uint32_t p2_red = 28;
uint32_t p3_red = 48;
uint32_t p4_red = 50;
uint32_t p1_blue = 10;
uint32_t p2_blue = 13;
uint32_t p3_blue = 35;
uint32_t p4_blue = 32;
uint32_t p1_red = 0;
uint32_t p2_red = 1;
uint32_t p3_red = 6;
uint32_t p4_red = 7;
uint32_t p1_blue = 59;
uint32_t p2_blue = 58;
uint32_t p3_blue = 53;
uint32_t p4_blue = 54;
int score_red = 0;
int score_blue = 0;
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ namespace mcts
void copy(node* n1, node* n2, unsigned int prunning = 0);
public:
allocator(unsigned int size = 10000000U);
allocator(unsigned int size = 40000000U);
~allocator();
node* allocate(unsigned int size);
void clear();
......
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