-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastBoard.h
127 lines (102 loc) · 3.67 KB
/
FastBoard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef FASTBOARD_H_INCLUDED
#define FASTBOARD_H_INCLUDED
#include "config.h"
#include <array>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <nmmintrin.h>
#include <assert.h>
#include "pattern3x3.h"
#include "distance.h"
class FastBoard {
friend class FastState;
public:
/*
neighbor counts are up to 4, so 3 bits is ok,
but a power of 2 makes things a bit faster
*/
static constexpr int NBR_SHIFT = 4;
static constexpr int NBR_MASK = (1 << NBR_SHIFT) - 1;
/*
highest existing square
*/
static constexpr int MAXSQ = ((BOARD_SIZE + 2) * (BOARD_SIZE + 2));
/*
infinite score
*/
static constexpr int BIG = 10000000;
/*
vertex of a pass
*/
static constexpr int PASS = -1;
/*
vertex of a "resign move"
*/
static constexpr int RESIGN = -2;
/*
possible contents of a square
*/
enum square_t : char {
BLACK = 0, WHITE = 1, EMPTY = 2, INVAL = 3
};
/*
move generation types
*/
using movescore_t = std::pair<int, float>;
using scoredmoves_t = std::vector<movescore_t>;
int get_boardsize(void) const;
square_t get_square(int x, int y) const;
square_t get_square(int vertex) const ;
int get_vertex(int i, int j) const;
void set_square(int x, int y, square_t content);
void set_square(int vertex, square_t content);
std::pair<int, int> get_xy(int vertex) const;
bool is_suicide(int i, int color) const;
int count_pliberties(const int i) const;
bool is_eye(const int color, const int vtx) const;
float area_score(float komi) const;
int get_prisoners(int side) const;
bool black_to_move() const;
bool white_to_move() const;
int get_to_move() const;
void set_to_move(int color);
std::string move_to_text(int move) const;
std::string move_to_text_sgf(int move) const;
std::string get_stone_list() const;
std::string get_string(int vertex) const;
void reset_board(int size);
void display_board(int lastmove = -1);
static bool starpoint(int size, int point);
static bool starpoint(int size, int x, int y);
protected:
/*
bit masks to detect eyes on neighbors
*/
static const std::array<int, 2> s_eyemask;
static const std::array<square_t, 4> s_cinvert; /* color inversion */
std::array<square_t, MAXSQ> m_square; /* board contents */
std::array<unsigned short, MAXSQ+1> m_next; /* next stone in string */
std::array<unsigned short, MAXSQ+1> m_parent; /* parent node of string */
std::array<unsigned short, MAXSQ+1> m_libs; /* liberties per string parent */
std::array<unsigned short, MAXSQ+1> m_stones; /* stones per string parent */
std::array<unsigned short, MAXSQ> m_neighbours; /* counts of neighboring stones */
std::array<int, 4> m_dirs; /* movement directions 4 way */
std::array<int, 2> m_prisoners; /* prisoners per color */
std::array<unsigned short, MAXSQ> m_empty; /* empty squares */
std::array<unsigned short, MAXSQ> m_empty_idx; /* indexes of square */
int m_empty_cnt; /* count of empties */
int m_tomove;
int m_maxsq;
int m_boardsize;
int m_squaresize;
int calc_reach_color(int color) const;
int count_neighbours(const int color, const int i) const;
void merge_strings(const int ip, const int aip);
void add_neighbour(const int i, const int color);
void remove_neighbour(const int i, const int color);
void print_columns();
};
#endif