mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
LibChess: Compact the Defenitions of various chess related types
before: sizeof(Board)=344, sizeof(Move)=36, sizeof(Piece)=4, sizeof(Square)=8 after: sizeof(Board)=108, sizeof(Move)=9, sizeof(Piece)=1, sizeof(Square)=2
This commit is contained in:
parent
57bb4d1aec
commit
34433f5dc4
1 changed files with 17 additions and 16 deletions
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
namespace Chess {
|
namespace Chess {
|
||||||
|
|
||||||
enum class Type {
|
enum class Type : u8 {
|
||||||
Pawn,
|
Pawn,
|
||||||
Knight,
|
Knight,
|
||||||
Bishop,
|
Bishop,
|
||||||
|
@ -28,7 +28,7 @@ enum class Type {
|
||||||
String char_for_piece(Type type);
|
String char_for_piece(Type type);
|
||||||
Chess::Type piece_for_char_promotion(const StringView& str);
|
Chess::Type piece_for_char_promotion(const StringView& str);
|
||||||
|
|
||||||
enum class Color {
|
enum class Color : u8 {
|
||||||
White,
|
White,
|
||||||
Black,
|
Black,
|
||||||
None,
|
None,
|
||||||
|
@ -55,8 +55,8 @@ struct Piece {
|
||||||
constexpr Piece EmptyPiece = { Color::None, Type::None };
|
constexpr Piece EmptyPiece = { Color::None, Type::None };
|
||||||
|
|
||||||
struct Square {
|
struct Square {
|
||||||
int rank; // zero indexed;
|
i8 rank; // zero indexed;
|
||||||
int file;
|
i8 file;
|
||||||
Square(const StringView& name);
|
Square(const StringView& name);
|
||||||
Square(const int& rank, const int& file)
|
Square(const int& rank, const int& file)
|
||||||
: rank(rank)
|
: rank(rank)
|
||||||
|
@ -88,10 +88,10 @@ struct Move {
|
||||||
Square to;
|
Square to;
|
||||||
Type promote_to;
|
Type promote_to;
|
||||||
Piece piece;
|
Piece piece;
|
||||||
bool is_check = false;
|
bool is_check : 1 = false;
|
||||||
bool is_mate = false;
|
bool is_mate : 1 = false;
|
||||||
bool is_capture = false;
|
bool is_capture : 1 = false;
|
||||||
bool is_ambiguous = false;
|
bool is_ambiguous : 1 = false;
|
||||||
Square ambiguous { 50, 50 };
|
Square ambiguous { 50, 50 };
|
||||||
Move(const StringView& long_algebraic);
|
Move(const StringView& long_algebraic);
|
||||||
Move(const Square& from, const Square& to, const Type& promote_to = Type::None)
|
Move(const Square& from, const Square& to, const Type& promote_to = Type::None)
|
||||||
|
@ -161,16 +161,17 @@ private:
|
||||||
bool apply_illegal_move(const Move&, Color color);
|
bool apply_illegal_move(const Move&, Color color);
|
||||||
|
|
||||||
Piece m_board[8][8];
|
Piece m_board[8][8];
|
||||||
Color m_turn { Color::White };
|
|
||||||
Color m_resigned { Color::None };
|
|
||||||
Optional<Move> m_last_move;
|
Optional<Move> m_last_move;
|
||||||
int m_moves_since_capture { 0 };
|
short m_moves_since_capture { 0 };
|
||||||
int m_moves_since_pawn_advance { 0 };
|
short m_moves_since_pawn_advance { 0 };
|
||||||
|
|
||||||
bool m_white_can_castle_kingside { true };
|
Color m_turn : 2 { Color::White };
|
||||||
bool m_white_can_castle_queenside { true };
|
Color m_resigned : 2 { Color::None };
|
||||||
bool m_black_can_castle_kingside { true };
|
|
||||||
bool m_black_can_castle_queenside { true };
|
bool m_white_can_castle_kingside : 1 { true };
|
||||||
|
bool m_white_can_castle_queenside : 1 { true };
|
||||||
|
bool m_black_can_castle_kingside : 1 { true };
|
||||||
|
bool m_black_can_castle_queenside : 1 { true };
|
||||||
|
|
||||||
// We trust that hash collisions will not happen to save lots of memory and time.
|
// We trust that hash collisions will not happen to save lots of memory and time.
|
||||||
HashMap<unsigned, int> m_previous_states;
|
HashMap<unsigned, int> m_previous_states;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue