stellar

UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

move.hpp (2392B)


0 #ifndef STELLAR_MOVES_H
1 #define STELLAR_MOVES_H
3 #include "board.hpp"
4 #include "piece.hpp"
5 #include "utils.hpp"
7 #include <iostream>
8 #include <vector>
10 struct Move {
11 enum Flag : uint8_t {
12 QUIET,
13 DOUBLE,
14 CASTLEK,
15 CASTLEQ,
16 CAPTURE,
17 ENPASSANT,
18 PQUIET,
19 PKNIGHT = 8,
20 PBISHOP,
21 PROOK,
22 PQUEEN,
23 PCKNIGHT,
24 PCBISHOP,
25 PCROOK,
26 PCQUEEN,
27 };
29 Move() : source_i(0), target_i(0), flags_i(0) {}
30 Move(square::Square source, square::Square target, Flag flags)
31 : source_i(to_underlying(source)), target_i(to_underlying(target)), flags_i(flags) {}
33 friend bool operator==(const Move a, const Move b) {
34 return a.source_i == b.source_i && a.target_i == b.target_i && a.flags_i == b.flags_i;
35 }
37 square::Square source(void) const { return static_cast<square::Square>(source_i); }
38 square::Square target(void) const { return static_cast<square::Square>(target_i); }
40 bool is_capture(void) const { return flags_i != PQUIET && (flags_i & CAPTURE); }
41 bool is_promote(void) const { return flags_i & 0x8; }
43 bool is_double(void) const { return flags_i == DOUBLE; }
44 bool is_repeatable(void) const { return flags_i == QUIET; }
45 bool is_quiet(void) const { return flags_i == QUIET || flags_i == PQUIET; }
47 bool is_castle(void) const { return flags_i == CASTLEK || flags_i == CASTLEQ; }
48 bool is_castle_king(void) const { return flags_i == CASTLEK; }
49 bool is_castle_queen(void) const { return flags_i == CASTLEQ; }
51 bool is_enpassant(void) const { return flags_i == ENPASSANT; }
53 const piece::Type promoted(void) const { return static_cast<piece::Type>((flags_i & 0x3) + 1); }
55 bool make(Board &board) const;
57 operator std::string() const;
58 friend std::ostream &operator<<(std::ostream &os, Move move);
59 void print(void) const;
61 private:
62 inline void piece_remove(Board &board, piece::Type type, color::Color color, square::Square square) const;
63 inline void piece_set(Board &board, piece::Type type, color::Color color, square::Square square) const;
64 inline void piece_move(Board &board, piece::Type type, color::Color color, square::Square source,
65 square::Square target) const;
67 unsigned source_i : 6;
68 unsigned target_i : 6;
69 unsigned flags_i : 4;
70 };
72 #endif