Skip to content
Snippets Groups Projects
Commit 5f4d6ee5 authored by Pizon Antoine's avatar Pizon Antoine
Browse files

Changes to movement freedom heuristic

parents 304d3fb5 26387090
No related branches found
No related tags found
No related merge requests found
ai_vs_ai=1
ai_think_time=5000
<<<<<<< HEAD
ai_vs_ai_game_count=100
heuristic_ai_1=movement_freedom
=======
ai_vs_ai_game_count=10
heuristic_ai_1=points
>>>>>>> 26387090f3eb3945d1382de1d372737abf83c5d0
heuristic_ai_2=default
send_game_to_gui=1
......@@ -456,7 +456,8 @@ namespace game
}
penguin_state penguin::random_start_state()
{
std::default_random_engine generator;
std::random_device rd;
std::default_random_engine generator(rd());
std::uniform_int_distribution<int> distribution(0,59);
std::vector<int> free;
free.resize(60);
......@@ -464,7 +465,7 @@ namespace game
{
free[i] = i;
}
int max1Fish = 30, max2Fish = 20, max3Fish = 10;
int max1Fish = 30, max2Fish = 20;
penguin_state s = {};
s.current_player_red = true;
s.score_red = 0;
......@@ -479,7 +480,6 @@ namespace game
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;
......@@ -491,6 +491,7 @@ namespace game
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++)
{
......@@ -504,6 +505,7 @@ namespace game
pengPos.push_back(pos);
tab_peng[i%4] = pos;
}
return s;
}
......
......@@ -40,7 +40,7 @@ namespace mcts
*/
if(!after_state.current_player_red){ //If the player was red
if(after_state.current_player_red){ //If the player was red
penguins = after_state.peng_red;
}else{ //if the player was blue
penguins = after_state.peng_blue;
......@@ -57,6 +57,7 @@ namespace mcts
// Return a float between -1.0 and 1.0 related to the change of the number of direction in which you can play before and after the move
return (-(number_of_direction_after - 12.0)/12.0);
//return (-(number_of_direction_after - number_of_direction_before)/12.0);
}
......
......@@ -23,6 +23,6 @@ namespace mcts
int points_heuristic::get_count(const game::penguin& game, uint8_t move) const
{
return 100 ;
return 10000; ;
}
}
......@@ -32,7 +32,7 @@ using namespace std;
int main(int argc, char *argv[])
{
// mcts::test_allocator(10, 2);
// omp_set_num_threads(8);
omp_set_num_threads(8);
game::config& c = game::config::get_config();
const mcts::penguin_heuristic& h1 = *(c.get_heuristic(1));
......@@ -40,5 +40,5 @@ int main(int argc, char *argv[])
std::cout << "COUCOU" << std::endl;
mcts::run_test_mcts_two_players(game::penguin(),h1,h2);
return 0;
return 0;
}
#ifndef __MCTS_SETTINGS_HPP__
#define __MCTS_SETTINGS_HPP__
// Allocated memory for the mcts. If not enough the program may crash
<<<<<<< HEAD
#define MCTS_ALLOCATOR_SIZE 100000000U
=======
#define MCTS_ALLOCATOR_SIZE 80000000U
>>>>>>> 26387090f3eb3945d1382de1d372737abf83c5d0
// Reflection time for every turn of the mcts (in ms)
#define MCTS_TURN_TIME 5000
......
......@@ -20,7 +20,7 @@ namespace mcts
template <typename Game>
class test_mcts_two_players
{
openings openings_;
openings* openings_;
void play(Game g, const heuristic<Game>& h);
void self_play(Game g);
......@@ -33,16 +33,16 @@ public:
};
template <typename Game>
test_mcts_two_players<Game>::test_mcts_two_players(const Game& g, const heuristic<Game>& h, const heuristic<Game>& h2) : openings_(g)
test_mcts_two_players<Game>::test_mcts_two_players(const Game& g, const heuristic<Game>& h, const heuristic<Game>& h2)
{
game::config& config = game::config::get_config();
std::cout << "wtf" << std::endl;
if(config.is_ai_vs_ai())
{
self_play(g, h,h2);
}
else
{
std::cout << "yolo" << std::endl;
play(g, h);
}
}
......@@ -126,13 +126,13 @@ void test_mcts_two_players<Game>::self_play_learn_openings(Game g, int n)
for (int i = 0; i < n; ++i)
{
std::cout << i << std::endl;
std::cout << openings_ << std::endl << std::endl;
std::cout << (*openings_) << std::endl << std::endl;
moves.clear();
g.set_state(state);
the_turk_1.reset();
the_turk_1.init_with_openings(openings_);
the_turk_1.init_with_openings(*openings_);
the_turk_2.reset();
the_turk_2.init_with_openings(openings_);
the_turk_2.init_with_openings(*openings_);
int the_turk_1_last_move = -1, the_turk_2_last_move = -1;
int k = 0;
while (!g.end_of_game())
......@@ -166,7 +166,7 @@ void test_mcts_two_players<Game>::self_play_learn_openings(Game g, int n)
int v = g.value(0);
std::cout << "value for first player " << v << std::endl;
g.set_state(state);
openings_.update(g, moves, v);
openings_->update(g, moves, v);
g.set_state(state);
for (std::uint16_t m : moves)
{
......@@ -206,19 +206,16 @@ void test_mcts_two_players<Game>::self_play(Game g, const heuristic<Game>& h1, c
game::config& c = game::config::get_config();
auto state = g.get_state();
auto the_turk_v1 = make_mcts_two_players(g, c.get_think_time(), 0.6, 2, h1);
auto the_turk_v1 = make_mcts_two_players(g, c.get_think_time(), 1.0, 4, h1);
auto the_turk_v2 = make_mcts_two_players(g, c.get_think_time(), 0.6, 2, h2);
std::string result_directory(get_test_results_directory());
int nb_win_v1 = 0, nb_win_v2 = 0, nb_draw = 0;
for (unsigned int i = 0; i < c.get_game_count(); ++i)
{
//std::cout << i << std::endl;
if(i%2 == 1)
if(i%2 == 0)
{
state = game::penguin::random_start_state();
}
g.set_state(state);
the_turk_v1.reset();
......@@ -228,9 +225,7 @@ void test_mcts_two_players<Game>::self_play(Game g, const heuristic<Game>& h1, c
while (!g.end_of_game())
{
++k;
// cout << c4 << endl;
if ((i % 2 == 0 && g.current_player() == 0) || (i % 2 == 1 && g.current_player() == 1))
{
if (the_turk_v1_last_move != -1 && the_turk_v2_last_move != -1)
......
......@@ -147,8 +147,6 @@ public class Controller implements Initializable
t.getFishLabel().setOnMouseClicked(phandl);
}
statusLabel.setText("Click to place RED penguins");
}
}
......@@ -175,57 +173,6 @@ public class Controller implements Initializable
}
}
public void randomGame()
{
gameState.clearFish();
gameState.setScore(Player.Red, 0);
gameState.setScore(Player.Blue, 0);
//Generating random fish values
int[] fishCount = {0,0,0};
for (int i = 0; i < 60; i++)
{
List<Integer> possibleFish = new ArrayList<>();
if(fishCount[0] < max1Fish)
possibleFish.add(1);
if(fishCount[1] < max2Fish)
possibleFish.add(2);
if(fishCount[2] < max3Fish)
possibleFish.add(3);
int nbFish = possibleFish.get(new Random().nextInt(possibleFish.size()));
gameState.setFish(i, nbFish);
board[i].setNbFish(nbFish);
boardView[i].update();
fishCount[nbFish-1]++;
}
List<Integer> excludedPositions = new ArrayList<>();
Random r = new Random();
penguinGenCounter = 0;
for(int i = 0; i < 8;++i)
{
int rand = r.nextInt(60);
Player p = Player.Red;
Tile.PenguinPresence pres = Tile.PenguinPresence.RED_PENGUIN;
if(i >= 4)
{
p = Player.Blue;
pres = Tile.PenguinPresence.BLUE_PENGUIN;
}
while(excludedPositions.contains(rand))
{
rand = r.nextInt(60);
}
gameState.setPenguin(p, penguinGenCounter % 4, rand);
board[rand].setPenguinPresence(pres);
boardView[rand].update();
penguinGenCounter++;
excludedPositions.add(rand);
}
gameInput.println(gameState.toGameInputJSON());
//Platform.runLater(() -> startGame());
}
/**
* Updates model and view from the state
......@@ -435,3 +382,4 @@ public class Controller implements Initializable
}
......@@ -44,13 +44,8 @@ public class UpdateThread extends Thread
{
gameRunning = false;
Platform.runLater(() -> controller.gameEnd());
} /*else if (line.contains("New")){
Platform.runLater(() -> controller.randomGame());
} */else if (line.contains("{")) //Line contains JSON
} else if (line.contains("{")) //Line contains JSON
{
//gameState Update
gameState.update(line.substring(line.indexOf("{"), line.lastIndexOf("}") + 1)); //Extract JSON string
Platform.runLater(() -> controller.updateModelAndView());
......@@ -73,7 +68,6 @@ public class UpdateThread extends Thread
});
}
}
}
else if (line.startsWith("(") && line.contains("value:")) //lines with values (estimation) of the computer winning chances
......@@ -212,3 +206,4 @@ public class UpdateThread extends Thread
}
}
}
#!/bin/bash
declare -a machines=("berger" "cavalier" "pion" "roi" "reine" "fou" "pat" "echiquier" "mate")
#declare -a machines=("berger" "cavalier" "pion" "roi" "reine" "fou" "pat" "echiquier" "mate")
declare -a machines=("contrex" "perrier")
echo -n User:
read user
......
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