Skip to content
Snippets Groups Projects
Commit 727022ab authored by Felton Samuel's avatar Felton Samuel
Browse files

fixed !

parent d7cffbf0
No related branches found
No related tags found
No related merge requests found
ai_vs_ai=1
ai_think_time=1000
ai_think_time=3000
ai_vs_ai_game_count=100
heuristic_ai_1=left_up
heuristic_ai_2=default
......
#include "penguin.hpp"
#include <sstream>
#include <random>
#include <algorithm>
using namespace std;
namespace game
......@@ -446,4 +447,57 @@ namespace game
os << pen.to_string();
return os;
}
penguin_state penguin::random_start_state()
{
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(0,59);
std::vector<int> free;
free.resize(60);
for(int i = 0; i < 60; i++)
{
free[i] = i;
}
int max1Fish = 30, max2Fish = 20, max3Fish = 10;
penguin_state s = {};
s.current_player_red = true;
s.score_red = 0;
s.score_blue = 0;
s.one_fish = 0;
s.two_fish = 0;
s.three_fish = 0;
for(int i = 0; i < 60; i++)
{
distribution = std::uniform_int_distribution<int>(0,free.size() -1 );
int rand = distribution(generator);
int tile =free[rand];
free.erase(std::remove(free.begin(),free.end(),tile),free.end());
if(i < max1Fish) {
s.one_fish |= (long) 1 << tile;
} else if( i < max1Fish + max2Fish) {
s.two_fish |= (long) 1 << tile;
} else {
s.three_fish |= (long) 1 << tile;
}
}
uint32_t* tab_peng = s.peng_red;
std::vector<int> pengPos;
pengPos.reserve(8);
distribution = std::uniform_int_distribution<int>(0,59);
for(int i = 0; i < 8; i++)
{
if(i == 4) tab_peng = s.peng_blue;
int pos = distribution(generator);
while(std::find(pengPos.begin(),pengPos.end(),pos) != pengPos.end())
{
pos = distribution(generator);
}
pengPos.push_back(pos);
tab_peng[i%4] = pos;
}
return s;
}
}
......@@ -77,6 +77,7 @@ namespace game
j : the column, between 0 and 7 if i is pair else between 0 and 8
*/
const tile_content get_tile(std::uint8_t tile_index) const;
static penguin_state random_start_state();
private:
penguin_state state;
......
......@@ -13,6 +13,7 @@
#include "config.hpp"
#include "test_statistics.hpp"
#include <unistd.h>
#include "penguin.hpp"
namespace mcts
{
......@@ -210,12 +211,13 @@ void test_mcts_two_players<Game>::self_play(Game g, const heuristic<Game>& h1, c
int nb_win_v1 = 0, nb_win_v2 = 0, nb_draw = 0;
for (unsigned int i = 0; i < c.get_game_count(); ++i)
{
/*if(i%2 == 0)
//std::cout << i << std::endl;
if(i%2 == 1)
{
std::cout << "New";
sleep(100);
state = g.get_state();
}*/
state = game::penguin::random_start_state();
}
g.set_state(state);
the_turk_v1.reset();
the_turk_v2.reset();
......
......@@ -101,12 +101,11 @@ public class Controller implements Initializable
}).start();
//DO WE WANT TO LOAD A STATE?
/*TextInputDialog dialog = new TextInputDialog();
TextInputDialog dialog = new TextInputDialog();
dialog.setHeaderText("Do you want to load a state?");
dialog.setContentText("Enter JSON (or leave blank for random)");
dialog.showAndWait();
String result = dialog.getResult();*/
String result = "";
String result = dialog.getResult();
if (result == null) //If the user clicked exit
System.exit(0);
try
......@@ -119,7 +118,7 @@ public class Controller implements Initializable
} catch (JSONException e)
{
//WE DON'T WANT TO LOAD A STATE
/*gameState.clearFish();
gameState.clearFish();
gameState.setScore(Player.Red, 0);
gameState.setScore(Player.Blue, 0);
//Generating random fish values
......@@ -147,8 +146,8 @@ public class Controller implements Initializable
t.getFxTile().setOnMouseClicked(phandl);
t.getFishLabel().setOnMouseClicked(phandl);
}
statusLabel.setText("Click to place RED penguins");*/
randomGame();
statusLabel.setText("Click to place RED penguins");
}
}
......@@ -221,7 +220,6 @@ public class Controller implements Initializable
penguinGenCounter++;
excludedPositions.add(rand);
}
System.out.println("JSON : " + gameState.toGameInputJSON());
gameInput.println(gameState.toGameInputJSON());
//Platform.runLater(() -> startGame());
......
......@@ -44,10 +44,10 @@ public class UpdateThread extends Thread
{
gameRunning = false;
Platform.runLater(() -> controller.gameEnd());
}/* else if (line.contains("New")){
} /*else if (line.contains("New")){
Platform.runLater(() -> controller.randomGame());
}*/ else if (line.contains("{")) //Line contains JSON
} */else if (line.contains("{")) //Line contains JSON
{
......
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