-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess_position_encoding.h
More file actions
58 lines (51 loc) · 1.77 KB
/
chess_position_encoding.h
File metadata and controls
58 lines (51 loc) · 1.77 KB
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
#ifndef CHESS_POSITION_ENCODING_H
#define CHESS_POSITION_ENCODING_H
#include <vector>
#include <string>
#include <array>
class ChessPositionEncoder {
public:
// Constant dimensions based on AlphaZero encoding
static constexpr int BOARD_SIZE = 8;
static constexpr int PIECE_TYPES = 6;
static constexpr int TOTAL_PLANES = 117;
// Plane indices for different encoding components
enum PlaneIndices {
WHITE_PAWN_PLANE = 0,
WHITE_ROOK_PLANE,
WHITE_KNIGHT_PLANE,
WHITE_BISHOP_PLANE,
WHITE_QUEEN_PLANE,
WHITE_KING_PLANE,
BLACK_PAWN_PLANE = 6,
BLACK_ROOK_PLANE,
BLACK_KNIGHT_PLANE,
BLACK_BISHOP_PLANE,
BLACK_QUEEN_PLANE,
BLACK_KING_PLANE,
REPETITION_ONCE_PLANE,
REPETITION_TWICE_PLANE,
COLOR_TO_MOVE_PLANE,
WHITE_KINGSIDE_CASTLE_PLANE,
WHITE_QUEENSIDE_CASTLE_PLANE,
BLACK_KINGSIDE_CASTLE_PLANE,
BLACK_QUEENSIDE_CASTLE_PLANE
};
// Main encoding method
std::vector<std::array<bool, BOARD_SIZE * BOARD_SIZE>> encode(
const std::string& fen,
const std::vector<std::string>& previous_positions
);
private:
// Helper methods for encoding different aspects of the position
void encodePieces(const std::string& fen, int plane_offset);
void encodeRepetitions(const std::vector<std::string>& previous_positions, int plane_offset);
void encodeCastlingRights(const std::string& fen);
void encodeColorToMove(const std::string& fen);
public: void printEncodingPlanes(int start_plane, int end_plane) const;
protected:
std::vector<std::array<bool, BOARD_SIZE * BOARD_SIZE>> encoding_planes;
float total_move_count;
float no_progress_move_count;
};
#endif // CHESS_POSITION_ENCODING_H