Skip to content
Snippets Groups Projects
Commit 910ba2b9 authored by Salard Xavier's avatar Salard Xavier
Browse files
parents 5250a535 a6f517f3
No related branches found
No related tags found
No related merge requests found
#include "config.hpp"
#include <iostream>
#include <fstream>
#include <algorithm>
<<<<<<< HEAD
#include "points_heuristic.hpp"
=======
#include "movement_freedom_heuristic.hpp"
>>>>>>> 34412ade6e5941a3c916b90b915655977cb2068c
namespace game {
config::config(std::string& filename) : ai_vs_ai(false), think_time(5000), game_count(100), heuristic_ai_1(nullptr), heuristic_ai_2(nullptr)
{
std::ifstream file;
std::string line;
file.open(filename);
if(file.is_open()){
while(std::getline(file,line)) {
line.erase(std::remove_if(line.begin(),line.end(),[](char c) {return std::isspace(c);}),
line.end());
size_t indexEqual = line.find_first_of('=');
const std::string& lvalue = line.substr(0,indexEqual);
const std::string& rvalue = line.substr(indexEqual+1);
handle_line(lvalue,rvalue);
}
file.close();
}
if(heuristic_ai_1 == nullptr) {
std::cout << "H1";
heuristic_ai_1 = new mcts::penguin_heuristic();
}
if(heuristic_ai_2 == nullptr) {
heuristic_ai_2 = new mcts::penguin_heuristic();
}
}
void config::handle_line(const std::string& option_name, const std::string& option_value)
{
if(option_name == "ai_vs_ai") {
set_game_mode(option_value);
} else if(option_name == "ai_think_time") {
set_think_time(option_value);
} else if(option_name == "ai_vs_ai_game_count") {
set_game_count(option_value);
} else if (option_name == "heuristic_ai_1") {
set_heuristic(option_value,1);
} else if (option_name == "heuristic_ai_2") {
set_heuristic(option_value,2);
} else if(option_name == "send_game_to_gui"){
set_send_game(option_value);
} else {
std::cerr << "Unknown option : " << option_name << std::endl;
}
}
void config::set_game_mode(const std::string& value)
{
int v = std::stoi(value);
ai_vs_ai = v;
}
void config::set_think_time(const std::string& value)
{
int v = std::stoi(value);
think_time = v;
}
void config::set_game_count(const std::string& value)
{
int v = std::stoi(value);
game_count = v;
}
void config::set_heuristic(const std::string& value, short player)
{
mcts::penguin_heuristic** h = player == 1 ? &heuristic_ai_1 : &heuristic_ai_2;
if(value == "left_up") {
*h = new mcts::go_left_up_heuristic();
}
<<<<<<< HEAD
if(value == "points") {
std::cout << "POINTS" << std::endl;
*h = new mcts::points_heuristic();
}
=======
if(value == "movement_freedom") {
*h = new mcts::movement_freedom_heuristic();
}
>>>>>>> 34412ade6e5941a3c916b90b915655977cb2068c
if(value == "default") {
*h = new mcts::penguin_heuristic();
} else {
std::cerr << "Unknown heuristic : " << value << std::endl;
}
}
void config::set_send_game(const std::string& value)
{
int v = std::stoi(value);
send_game_to_gui = v;
}
}
#include "penguin_heuristic.hpp"
#include "penguin.hpp"
using namespace std;
namespace mcts
{
float penguin_heuristic::get_value(const game::penguin& game, uint8_t move) const
{
return 0.f;
}
int penguin_heuristic::get_count(const game::penguin& game, uint8_t move) const
{
return 1;
}
float go_left_up_heuristic::get_value(const game::penguin& game, uint8_t move) const
{
<<<<<<< HEAD
std::shared_ptr<game::penguin> played = game::copy(game);
played->play(move);
game::penguin_state state = played->get_state();
uint32_t* penguins = state.peng_blue;
if(!state.current_player_red) {
penguins = state.peng_red;
}
uint32_t sPos = 0;
for(int i=0; i< 4; i++) {
sPos+=PENGUIN_POS(penguins[i]);
}
double res = (double) (-(-118.0 + sPos) / 118.0);
return res;
=======
std::shared_ptr<game::penguin> played = game::copy(game);
played->play(move);
game::penguin_state state = played->get_state();
uint32_t* penguins = state.peng_blue;
if(!state.current_player_red) {
penguins = state.peng_red;
}
uint32_t sPos = 0;
for(int i=0; i< 4; i++) {
sPos+=PENGUIN_POS(penguins[i]);
}
double res = (double) (-(-118.0 + sPos) / 118.0);
return res;
>>>>>>> 34412ade6e5941a3c916b90b915655977cb2068c
}
int go_left_up_heuristic::get_count(const game::penguin& game, uint8_t move) const
{
return 100000000;
}
}
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