-
Notifications
You must be signed in to change notification settings - Fork 0
/
position.h
109 lines (85 loc) · 2.79 KB
/
position.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
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include <string>
#include <map>
using namespace std;
// constants
// encode pieces
enum pieces {
e, p, n, b, r, q, k, P, N, B, R, Q, K, o
};
// encode squares
enum squares : int {
a8 = 0, b8, c8, d8, e8, f8, g8, h8,
a7 = 16, b7, c7, d7, e7, f7, g7, h7,
a6 = 32, b6, c6, d6, e6, f6, g6, h6,
a5 = 48, b5, c5, d5, e5, f5, g5, h5,
a4 = 64, b4, c4, d4, e4, f4, g4, h4,
a3 = 80, b3, c3, d3, e3, f3, g3, h3,
a2 = 96, b2, c2, d2, e2, f2, g2, h2,
a1 = 112, b1, c1, d1, e1, f1, g1, h1, no_sq
};
// castling binary representation
//
// bin dec
// 0001 1 white king can castle to the king side
// 0010 2 white king can castle to the queen side
// 0100 4 black king can castle to the king side
// 1000 8 black king can castle to the queen side
//
// examples
// 1111 both sides an castle both directions
// 1001 black king => queen side
// white king => king side
// 1111 & 0001 = 1 (not 0)
// 0000 & 0001 = 0
// if (castle & Kc)... for example
enum castling : int { Kc = 1, Qc = 2, kc = 4, qc = 8};
enum sides : int { white, black };
struct Position {
static string square_to_coord[128];
static string ascii_pieces;
static string unicode_pieces[13];
// status
int board[128] = {
r, n, b, q, k, b, n, r, o, o, o, o, o, o, o, o,
p, p, p, p, p, p, p, p, o, o, o, o, o, o, o, o,
e, e, e, e, e, e, e, e, o, o, o, o, o, o, o, o,
e, e, e, e, e, e, e, e, o, o, o, o, o, o, o, o,
e, e, e, e, e, e, e, e, o, o, o, o, o, o, o, o,
e, e, e, e, e, e, e, e, o, o, o, o, o, o, o, o,
P, P, P, P, P, P, P, P, o, o, o, o, o, o, o, o,
R, N, B, Q, K, B, N, R, o, o, o, o, o, o, o, o
};
// side to move
int side = white;
// enpassant square
int enpassant = no_sq;
// castling rights dec 15 = bin 1111 all can castle
int castle = 15;
// both king's squares
int king_squares[2] = { e1, e8 };
// e, p, n, b, r, q, k, P, N, B, R, Q, K
int piece_values[13] = { 0, -100, -350, -350, -525, -1000, -10000, 100, 350, 350, 525, 1000, 10000 };
// material score from white's perspective
int material_score = 0;
// "almost unique" position identifier aka hash key or position key
uint64_t hash_key;
// repetitions
int rep_index = 0;
uint64_t rep_stack[512] = { 0 };
// copies for unmake
int previous_enpassant[64] = { 0 };
int previous_castle[64] = { 0 };
int previous_piece[64] = { 0 };
// following defined in board.cpp
void print_board();
void reset_board();
void parse_fen(string fen);
void print_board_stats();
int make_move(int move, int depth);
void unmake_move(int move, int depth);
void set_material();
};
#endif