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

memory fix and removed useless allocation

parent 910ba2b9
No related branches found
No related tags found
No related merge requests found
ai_vs_ai=1
ai_think_time=5000
ai_vs_ai_game_count=100
ai_vs_ai_game_count=10
heuristic_ai_1=direction_freedom
heuristic_ai_2=default
send_game_to_gui=1
......@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
const mcts::penguin_heuristic& h1 = *(c.get_heuristic(1));
const mcts::penguin_heuristic& h2 = *(c.get_heuristic(2));
std::cout << "COUCOU" << std::endl;
mcts::run_test_mcts_two_players(game::penguin(true),h1,h2);
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
#define MCTS_ALLOCATOR_SIZE 10000000U
#define MCTS_ALLOCATOR_SIZE 200000000U
// 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,7 +206,6 @@ 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_v2 = make_mcts_two_players(g, c.get_think_time(), 0.6, 2, h2);
std::string result_directory(get_test_results_directory());
......
......@@ -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=("vichy" "vittel" "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