|
1 | 1 | #ifndef CHESSENGINE_MOVE_H
|
2 | 2 | #define CHESSENGINE_MOVE_H
|
| 3 | + |
3 | 4 | #include <cstdint>
|
4 | 5 | #include <format>
|
5 | 6 | #include <iostream>
|
6 | 7 | #include "Piece.h"
|
7 | 8 | #include "Util.h"
|
8 | 9 |
|
9 | 10 | namespace Moves {
|
10 |
| - using Pieces::Color, Pieces::Type; |
| 11 | + using Pieces::Color, Pieces::Type; |
11 | 12 |
|
12 |
| - enum MoveFlag { |
13 |
| - QUIET = 0, |
14 |
| - CAPTUREPAWN = 1, |
15 |
| - CAPTUREKNIGHT = 2, |
16 |
| - CAPTUREBISHOP = 3, |
17 |
| - CAPTUREROOK = 4, |
18 |
| - CAPTUREQUEEN = 5, |
19 |
| - ENPASSANT = 6, |
20 |
| - DOUBLEPAWNPUSH = 7, |
21 |
| - CASTLEKINGSIDE = 8, |
22 |
| - CASTLEQUEENSIDE = 9, |
23 |
| - }; |
| 13 | + enum MoveFlag { |
| 14 | + QUIET = 0, |
| 15 | + CAPTUREPAWN = 1, |
| 16 | + CAPTUREKNIGHT = 2, |
| 17 | + CAPTUREBISHOP = 3, |
| 18 | + CAPTUREROOK = 4, |
| 19 | + CAPTUREQUEEN = 5, |
| 20 | + ENPASSANT = 6, |
| 21 | + DOUBLEPAWNPUSH = 7, |
| 22 | + CASTLEKINGSIDE = 8, |
| 23 | + CASTLEQUEENSIDE = 9, |
| 24 | + }; |
24 | 25 |
|
25 |
| - struct Move { |
26 |
| - int8_t start : 8; |
27 |
| - int8_t end : 8; |
28 |
| - Type promotionType : 4; |
29 |
| - MoveFlag flag : 4; |
30 |
| - Color player : 1; |
| 26 | + struct Move { |
| 27 | + int8_t start: 8; |
| 28 | + int8_t end: 8; |
| 29 | + Type promotionType: 4; |
| 30 | + MoveFlag flag: 4; |
| 31 | + Color player: 1; |
31 | 32 |
|
32 |
| - bool operator==(const Move&other) const { |
33 |
| - return (start == other.start && end == other.end && promotionType == other.promotionType && |
34 |
| - flag == other.flag && player == other.player); |
35 |
| - } |
| 33 | + bool operator==(const Move &other) const { |
| 34 | + return (start == other.start && end == other.end && promotionType == other.promotionType && |
| 35 | + flag == other.flag && player == other.player); |
| 36 | + } |
36 | 37 |
|
37 |
| - std::string toString() const { |
38 |
| - std::string str = Util::positionToString(start); |
39 |
| - str += Util::positionToString(end); |
40 |
| - if (promotionType != Pieces::EMPTY) str += Util::pieceToString(promotionType, Color::BLACK); |
41 |
| - return str; |
42 |
| - } |
| 38 | + std::string toString() const { |
| 39 | + std::string str = Util::positionToString(start); |
| 40 | + str += Util::positionToString(end); |
| 41 | + if (promotionType != Pieces::EMPTY) str += Util::pieceToString(promotionType, Color::BLACK); |
| 42 | + return str; |
| 43 | + } |
43 | 44 |
|
44 |
| - bool tactical() const { |
45 |
| - return (flag > 0 && flag < 7) || promotionType != Pieces::EMPTY; |
46 |
| - } |
47 |
| - }; |
| 45 | + bool tactical() const { |
| 46 | + return (flag > 0 && flag < 7) || promotionType != Pieces::EMPTY; |
| 47 | + } |
| 48 | + }; |
48 | 49 |
|
49 |
| - inline std::ostream& operator<<(std::ostream&os, const Move&move) { |
50 |
| - os << move.toString(); |
51 |
| - return os; |
52 |
| - } |
| 50 | + inline std::ostream &operator<<(std::ostream &os, const Move &move) { |
| 51 | + os << move.toString(); |
| 52 | + return os; |
| 53 | + } |
53 | 54 |
|
54 | 55 |
|
55 |
| - constexpr Move NULL_MOVE = Move{0, 0, Pieces::EMPTY, QUIET, Color::WHITE}; |
| 56 | + constexpr Move NULL_MOVE = Move{0, 0, Pieces::EMPTY, QUIET, Color::WHITE}; |
56 | 57 |
|
57 |
| - constexpr int8_t MAILBOX[120] = { |
58 |
| - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
59 |
| - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
60 |
| - -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, |
61 |
| - -1, 8, 9, 10, 11, 12, 13, 14, 15, -1, |
62 |
| - -1, 16, 17, 18, 19, 20, 21, 22, 23, -1, |
63 |
| - -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, |
64 |
| - -1, 32, 33, 34, 35, 36, 37, 38, 39, -1, |
65 |
| - -1, 40, 41, 42, 43, 44, 45, 46, 47, -1, |
66 |
| - -1, 48, 49, 50, 51, 52, 53, 54, 55, -1, |
67 |
| - -1, 56, 57, 58, 59, 60, 61, 62, 63, -1, |
68 |
| - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
69 |
| - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
70 |
| - }; |
| 58 | + constexpr int8_t MAILBOX[120] = { |
| 59 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 60 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 61 | + -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, |
| 62 | + -1, 8, 9, 10, 11, 12, 13, 14, 15, -1, |
| 63 | + -1, 16, 17, 18, 19, 20, 21, 22, 23, -1, |
| 64 | + -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, |
| 65 | + -1, 32, 33, 34, 35, 36, 37, 38, 39, -1, |
| 66 | + -1, 40, 41, 42, 43, 44, 45, 46, 47, -1, |
| 67 | + -1, 48, 49, 50, 51, 52, 53, 54, 55, -1, |
| 68 | + -1, 56, 57, 58, 59, 60, 61, 62, 63, -1, |
| 69 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 70 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
| 71 | + }; |
71 | 72 |
|
72 |
| - constexpr int8_t MAILBOX64[64] = { |
73 |
| - 21, 22, 23, 24, 25, 26, 27, 28, |
74 |
| - 31, 32, 33, 34, 35, 36, 37, 38, |
75 |
| - 41, 42, 43, 44, 45, 46, 47, 48, |
76 |
| - 51, 52, 53, 54, 55, 56, 57, 58, |
77 |
| - 61, 62, 63, 64, 65, 66, 67, 68, |
78 |
| - 71, 72, 73, 74, 75, 76, 77, 78, |
79 |
| - 81, 82, 83, 84, 85, 86, 87, 88, |
80 |
| - 91, 92, 93, 94, 95, 96, 97, 98 |
81 |
| - }; |
| 73 | + constexpr int8_t MAILBOX64[64] = { |
| 74 | + 21, 22, 23, 24, 25, 26, 27, 28, |
| 75 | + 31, 32, 33, 34, 35, 36, 37, 38, |
| 76 | + 41, 42, 43, 44, 45, 46, 47, 48, |
| 77 | + 51, 52, 53, 54, 55, 56, 57, 58, |
| 78 | + 61, 62, 63, 64, 65, 66, 67, 68, |
| 79 | + 71, 72, 73, 74, 75, 76, 77, 78, |
| 80 | + 81, 82, 83, 84, 85, 86, 87, 88, |
| 81 | + 91, 92, 93, 94, 95, 96, 97, 98 |
| 82 | + }; |
82 | 83 |
|
83 |
| - constexpr bool SLIDE[7] = {false, false, false, true, true, true, false}; |
84 |
| - constexpr int8_t OFFSETS[7] = {0, 4, 8, 4, 4, 8, 8}; |
85 |
| - constexpr int8_t OFFSET[7][8] = { |
86 |
| - {0, 0, 0, 0, 0, 0, 0, 0}, |
87 |
| - {8, 9, 11, 16, 0, 0, 0, 0}, |
88 |
| - {-21, -19, -12, -8, 8, 12, 19, 21}, |
89 |
| - {-11, -9, 9, 11, 0, 0, 0, 0}, |
90 |
| - {-10, -1, 1, 10, 0, 0, 0, 0}, |
91 |
| - {-11, -10, -9, -1, 11, 10, 9, 1}, |
92 |
| - {-11, -10, -9, -1, 11, 10, 9, 1} |
93 |
| - }; |
| 84 | + constexpr bool SLIDE[7] = {false, false, false, true, true, true, false}; |
| 85 | + constexpr int8_t OFFSETS[7] = {0, 4, 8, 4, 4, 8, 8}; |
| 86 | + constexpr int8_t OFFSET[7][8] = { |
| 87 | + {0, 0, 0, 0, 0, 0, 0, 0}, |
| 88 | + {8, 9, 11, 16, 0, 0, 0, 0}, |
| 89 | + {-21, -19, -12, -8, 8, 12, 19, 21}, |
| 90 | + {-11, -9, 9, 11, 0, 0, 0, 0}, |
| 91 | + {-10, -1, 1, 10, 0, 0, 0, 0}, |
| 92 | + {-11, -10, -9, -1, 11, 10, 9, 1}, |
| 93 | + {-11, -10, -9, -1, 11, 10, 9, 1} |
| 94 | + }; |
94 | 95 | }
|
95 | 96 |
|
96 | 97 | #endif //CHESSENGINE_MOVE_H
|
0 commit comments