diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-13 16:48:15 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-13 16:48:15 +0200 |
| commit | ea0d0dcbf4b23f9ed84300b9771ca3b2deab1a18 (patch) | |
| tree | 72c64ccf19f833a34ba77e0cdda56108712f35a7 | |
| parent | 58e30cce0c3cc0ed467def5b36d861fb68f146b1 (diff) | |
moving enum around
| -rw-r--r-- | src/board/board.hpp | 36 | ||||
| -rw-r--r-- | src/board/fen.cpp | 18 |
2 files changed, 45 insertions, 9 deletions
diff --git a/src/board/board.hpp b/src/board/board.hpp index 6f72e56..35e2196 100644 --- a/src/board/board.hpp +++ b/src/board/board.hpp @@ -32,6 +32,42 @@ struct Position { bool operator==(const Position &) const = default; }; + +/* + * Maybe we can try to be efficent with memory by using a byte (char) or + * something like that let me brainstorm a little + * + * first two bits can be promotion flag because there are 4 posible options: + * NONE BISHOP ROOK QUEEN + * but wait none it not requided because its only applied + * when on last rank + * but that doesnt help becuase we cant have three options + * ok so first 2 bits for promotion flag + * like this ZZYYYYYY with ZZ being the promotion flag + * 00 for none piece + * 01 for queen + * 10 for rook + * 11 for bishop + * these valuesa are abritrari + * so we have other 6 bytes which doesnt work that well because we need to store + * two 64 bit numbers one for "From" and second for "To" + * so wait how much is a 64 for bit + * 2 * 2 = 4 (2 bits) + * 4 * 2 = 8 (3 bits) + * 8 * 2 = 16 (4 bits) + * 16 * 2 = 32 (5 bits) + * 32 * 2 = 64 (6 bits) + * so six bits that means that we can only store one posiiton we need a 2 + 6 * + * 2 (14) bits of value to represent it but wait when promotion flag isnt 0 we + * know its last rank oh but we dont know if from white or black perpective so + * 14 bits is required let me search if there is a way to store that data + * alright search done result seams that best way is to use 16 bit interger + * which look like good solution and we have 2 bits left if we want to add more + * things here is a diagram for it uint16_t: XXFFFFFFTTTTTT XX for promotion + * flag F for from position T for to position so we can try first writing a + * helper function for working with it then replace existing move struct + */ + struct Move { Position From; Position To; diff --git a/src/board/fen.cpp b/src/board/fen.cpp index dd503e0..e020e78 100644 --- a/src/board/fen.cpp +++ b/src/board/fen.cpp @@ -48,7 +48,14 @@ static void clearBoard(Game *g) { g->whiteCastleKing = false; g->whiteCastleQueen = false; } - +enum parserState : std::uint8_t { + BOARD, + PLAYER_TO_MOVE, + CASTLE, + ENPASSANT, + HALF_MOVE_CLOCK, + FULL_MOVE_CLOCK, +}; void setBoardFen(const std::string &fen, Game *g) { clearBoard(g); // example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 @@ -56,14 +63,7 @@ void setBoardFen(const std::string &fen, Game *g) { int rank = 7; Position enpassant = {}; - enum parserState : std::uint8_t { - BOARD, - PLAYER_TO_MOVE, - CASTLE, - ENPASSANT, - HALF_MOVE_CLOCK, - FULL_MOVE_CLOCK, - }; + parserState parser_state = BOARD; for (uint i = 0; i < fen.length(); i++) { |
