Skip to content
Snippets Groups Projects
Commit 4a0088d2 authored by Salard Xavier's avatar Salard Xavier
Browse files

Added direction freedom heuristic

parent ce6162e7
No related branches found
No related tags found
Loading
......@@ -76,8 +76,9 @@ namespace game {
mcts::penguin_heuristic** h = player == 1 ? &heuristic_ai_1 : &heuristic_ai_2;
if(value == "left_up") {
*h = new mcts::go_left_up_heuristic();
}
if(value == "default") {
}else if(value == "direction_freeddom") {
*h = new mcts::number_direction_freedom_heuristic();
}else if(value == "default") {
*h = new mcts::penguin_heuristic();
} else {
std::cerr << "Unknown heuristic : " << value << std::endl;
......
#include "number_direction_freedom_heuristic.hpp"
#include "penguin.hpp"
using namespace std;
//Count the number of direction in which a penguin can move
int8_t number_of_direction_penguin(uint32_t penguin){
int8_t res = 0 ;
if(PENGUIN_MOVES_A(penguin)>0) res++;
if(PENGUIN_MOVES_B(penguin)>0) res++;
if(PENGUIN_MOVES_C(penguin)>0) res++;
if(PENGUIN_MOVES_D(penguin)>0) res++;
if(PENGUIN_MOVES_E(penguin)>0) res++;
if(PENGUIN_MOVES_F(penguin)>0) res++;
return res;
}
namespace mcts
{
float number_direction_freedom_heuristic::get_value(const game::penguin& game, uint8_t move) const
{
std::shared_ptr<game::penguin> played = game::copy(game);
game::penguin_state before_state = played->get_state();
played->play(move);
game::penguin_state after_state = played->get_state();
uint32_t* penguins;
printf("before : " );
if(before_state.current_player_red){ //If the player is red
penguins = before_state.peng_red;
printf("red ");
}else{ //if the player is blue
penguins = before_state.peng_blue;
printf("blue ");
}
//For each penguins, count the number of direction it can move
int8_t number_of_direction_before = 0;
for(int8_t i=0; i< 4; i++) {
number_of_direction_before+= number_of_direction_penguin(penguins[i]);
}
printf("with %d direction \n", number_of_direction_before );
printf("after : " );
if(!after_state.current_player_red){ //If the player was red
penguins = after_state.peng_red;
printf("red ");
}else{ //if the player was blue
penguins = after_state.peng_blue;
printf("blue ");
}
int8_t number_of_direction_after = 0;
for(int8_t i=0; i< 4; i++) {
number_of_direction_after+= number_of_direction_penguin(penguins[i]);
}
printf("with %d direction \n", number_of_direction_after);
printf("The difference is %d, the value is %f\n\n",(number_of_direction_after - number_of_direction_before),((number_of_direction_after - number_of_direction_before)/12.0));
// 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 - number_of_direction_before)/12.0);
}
int number_direction_freedom_heuristic::get_count(const game::penguin& game, uint8_t move) const
{
return 10000000;
}
}
#ifndef __PENGUIN_HEURISTIC_DIRECTION_FREEDOM_HPP__
#define __PENGUIN_HEURISTIC_DIRECTION_FREEDOM_HPP__
#include "penguin.hpp"
#include "heuristic.hpp"
#include "penguin_heuristic.hpp"
namespace mcts
{
class number_direction_freedom_heuristic : public penguin_heuristic
{
public:
float get_value(const game::penguin& game, uint8_t move) const;
int get_count(const game::penguin& game, uint8_t move) const;
};
};
#endif
......@@ -35,7 +35,7 @@ AIInclude=-I $(AISRC)/game -I $(AISRC)/util -I $(AISRC)/monte_carlo -I $(AISRC)/
# Cpp source files
AISourceFile = omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp test_two_players_game.cpp monte_carlo.cpp \
test_fast_log.cpp statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp \
test_mcts_two_players.cpp bits.cpp test_bits.cpp penguin_heuristic.cpp main.cpp config.cpp
test_mcts_two_players.cpp bits.cpp test_bits.cpp penguin_heuristic.cpp number_direction_freedom_heuristic.cpp main.cpp config.cpp
# Directories in which make will search for files
vpath %.cpp $(AISRC)/game $(AISRC)/main $(AISRC)/util $(AISRC)/monte_carlo $(AISRC)/mcts $(AISRC)/gdl
# Flags passed to the compiler
......
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