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

Implementation of the Zone heuristic

parent 15a4e790
No related branches found
No related tags found
No related merge requests found
......@@ -526,32 +526,32 @@ namespace game
return board;
}
uint64_t pengin::penguin_move_board(const uint32_t& pen) const
uint64_t penguin::penguin_move_board(const uint32_t& pen) const
{
uint64_t board = 0;
//Direction A
for(int i=1; i<= PENGUIN_MOVES_A(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*7);
for(uint i=1; i<= PENGUIN_MOVES_A(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*7));
}
//Direction B
for(int i=1; i<= PENGUIN_MOVES_B(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*(-1));
for(uint i=1; i<= PENGUIN_MOVES_B(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*(-1)));
}
//Direction C
for(int i=1; i<= PENGUIN_MOVES_C(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*(-8));
for(uint i=1; i<= PENGUIN_MOVES_C(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*(-8)));
}
//Direction D
for(int i=1; i<= PENGUIN_MOVES_D(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*(-7));
for(uint i=1; i<= PENGUIN_MOVES_D(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*(-7)));
}
//Direction E
for(int i=1; i<= PENGUIN_MOVES_E(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*1);
for(uint i=1; i<= PENGUIN_MOVES_E(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*1));
}
//Direction F
for(int i=1; i<= PENGUIN_MOVES_A(pen); i++){
board |= ((uint64_t)1 << PENGUIN_POS(pen) + i*8);
for(uint i=1; i<= PENGUIN_MOVES_A(pen); i++){
board |= ((uint64_t)1 << (PENGUIN_POS(pen) + i*8));
}
return board;
}
......
......@@ -82,12 +82,12 @@ namespace game
std::uint64_t penguin_board(bool) const; // true for position of blue penguin, else false
uint64_t penguin_move_board(const uint32_t& pen) const; //Bitboard of possible move of the penguin
uint8_t turns_played() const;
int update_penguin_moves(uint32_t* p, uint64_t obstacles);
uint64_t create_obstacles_bitboard();
private:
penguin_state state;
void move_penguin(uint32_t* p, uint16_t rel_move);
uint64_t create_obstacles_bitboard();
int update_penguin_moves(uint32_t* p, uint64_t obstacles);
const uint8_t RED = 0;
const uint8_t BLUE = 1;
......
#ifndef __PENGUIN_ZONE_HEURISTIC_FREEDOM_HPP__
#define __PENGUIN_ZONE_HEURISTIC_FREEDOM_HPP__
#include "penguin.hpp"
#include "heuristic.hpp"
#include "penguin_heuristic.hpp"
#include <algorithm>
namespace mcts
{
class zone_heuristic : public penguin_heuristic
{
public:
float get_value(const game::penguin& game, uint8_t move) const
{
game::penguin g = *(game::copy(game));
g.play(move);
auto s = g.get_state();
uint32_t* penguins = s.current_player_red ? s.peng_red : s.peng_blue;
uint32_t* other_peng = s.current_player_red ? s.peng_blue : s.peng_red;
uint64_t obstacles = g.create_obstacles_bitboard();
uint64_t moves_this = 0;
uint64_t moves_other = 0;
for(int i = 0; i < 4; ++i) {
//g.update_penguin_moves(&other_peng[i],obstacles);
//g.update_penguin_moves(&penguins[i],obstacles);
}
//std::cout << "CURRENT PLAYER RED : " << s.current_player_red << std::endl;
//std::cout << "NB MOVES RED : " << s.nb_moves_red << std::endl;
//std::cout << "NB MOVES BLUE : " << s.nb_moves_blue << std::endl;
for(int i = 0; i < 4; ++i) {
moves_this |= g.penguin_move_board(penguins[i]);
moves_other |= g.penguin_move_board(other_peng[i]);
}
uint64_t this_owned_moves = moves_this & ~(moves_other);
uint64_t other_owned_moves = moves_other & ~(moves_this);
int count_this = 0;
int count_other = 0;
for(int i = 0; i < 60; i++) {
count_this += (this_owned_moves>>i) & 1 ;
count_other += (other_owned_moves>>i) & 1 ;
}
std::cout << "COUNT_THIS : " << count_this << std::endl;
std::cout << "COUNT_OTHER : " << count_other << std::endl;
std::cout << clamp((float)(count_this - count_other) / (count_this + 1), -1.f, 1.f) << std::endl;
return clamp((float)(count_this - count_other) / (count_this + 1), -1.f, 1.f);
}
int get_count(const game::penguin& game, uint8_t move) const
{
return 100;
}
private:
float clamp(float v, float l, float h) const
{
return std::max(std::min(h,v),l);
}
};
};
#endif
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