aboutsummaryrefslogtreecommitdiff
path: root/src/board.hpp
blob: 592b438df4ecb744d55be503edcfec49db9b2c0b (plain)
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
#ifndef SRC_BOARD_H_
#define SRC_BOARD_H_

#include <cstdint>
#include <string>
#include <unordered_map>
enum PieceType {
  NONE,
  PAWN,
  KNIGHT,
  BISHOP,
  ROOK,
  QUEEN,
  KING,
};

enum GameState {
  TURN,
  WHITE_WON,
  BLACK_WON,
  STALEMATE,
  DRAW,
};
std::string toChar(PieceType type, bool white);

struct Piece {
  bool color = 0;
  PieceType type = NONE;
  bool moved = false;
};

struct Position {
  uint8_t rank = 0;
  uint8_t file = 0;

  bool operator==(const Position &) const = default;
};

struct Game {
  Piece pieces[64];
  bool turn = 1; // 1 white; 0 black
  std::string castle = "";
  uint8_t halfMoveClock = 0;
  uint16_t MoveClock = 0;
  Position enPassant;
  bool canEnpassant = 0;
  GameState state = TURN;
  std::unordered_map<uint64_t, int> ThreeFoldMap;
};

struct Move {
  Position From;
  Position To;

  bool operator==(const Move &) const = default;
};
void printBoard(Game *b);
Piece createPiece(PieceType type, bool color, bool moved = false);

void PlayMove(Move move, Game *b);
int PositionToIndex(Position i);
#endif /* SRC_BOARD_H_ */