stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE |
move.hpp (2427B)
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 source, Square target, Flag flags) : source_i(source), target_i(target), flags_i(flags) {}
32 friend bool operator==(const Move a, const Move b) {
33 return a.source_i == b.source_i && a.target_i == b.target_i && a.flags_i == b.flags_i;
34 }
36 [[nodiscard]] constexpr Square source() const { return static_cast<Square>(source_i); }
37 [[nodiscard]] constexpr Square target() const { return static_cast<Square>(target_i); }
39 [[nodiscard]] constexpr bool is_capture() const { return flags_i != PQUIET && (flags_i & CAPTURE); }
40 [[nodiscard]] constexpr bool is_promote() const { return flags_i & 0x8; }
42 [[nodiscard]] constexpr bool is_double() const { return flags_i == DOUBLE; }
43 [[nodiscard]] constexpr bool is_repeatable() const { return flags_i == QUIET; }
44 [[nodiscard]] constexpr bool is_quiet() const { return flags_i == QUIET || flags_i == PQUIET; }
46 [[nodiscard]] constexpr bool is_castle() const { return flags_i == CASTLEK || flags_i == CASTLEQ; }
47 [[nodiscard]] constexpr bool is_castle_king() const { return flags_i == CASTLEK; }
48 [[nodiscard]] constexpr bool is_castle_queen() const { return flags_i == CASTLEQ; }
50 [[nodiscard]] constexpr bool is_enpassant() const { return flags_i == ENPASSANT; }
52 [[nodiscard]] constexpr const Type promoted() const { return static_cast<Type>((flags_i & 0x3) + 1); }
54 bool make(Board &board) const;
56 operator std::string() const;
57 friend std::ostream &operator<<(std::ostream &os, Move move);
58 void print() const;
60 private:
61 inline void piece_remove(Board &board, Type type, Color color, Square square) const;
62 inline void piece_set(Board &board, Type type, Color color, Square square) const;
63 inline void piece_move(Board &board, Type type, Color color, Square source, Square target) const;
65 unsigned source_i : 6;
66 unsigned target_i : 6;
67 unsigned flags_i : 4;
68 };
70 #endif