stellar

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

move.hpp (2392B)


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