aboutsummaryrefslogtreecommitdiff
path: root/src/board/board.hpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-13 18:31:44 +0200
committerAdam <adammegarules1@gmail.com>2026-08-13 18:31:44 +0200
commitde8f43c35b435674777eca98790ed3d086682ce4 (patch)
treea40a2d976708699ea74d022a683ce7076554d1f9 /src/board/board.hpp
parentea0d0dcbf4b23f9ed84300b9771ca3b2deab1a18 (diff)
adding more memory efficnet helper functions
Diffstat (limited to 'src/board/board.hpp')
-rw-r--r--src/board/board.hpp39
1 files changed, 6 insertions, 33 deletions
diff --git a/src/board/board.hpp b/src/board/board.hpp
index 35e2196..8ef3e56 100644
--- a/src/board/board.hpp
+++ b/src/board/board.hpp
@@ -34,40 +34,13 @@ struct Position {
};
/*
- * 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
+ * things here is a diagram for it uint16_t: XXFFFFFFTTTTTT00, XX for promotion
+ * flag F for from position T for to position, and 00 for empty ones.
*/
+PieceType getPromotionTypeFromMove(uint16_t move);
+uint8_t getFromValueFromMove(uint16_t move);
+
struct Move {
Position From;
Position To;
@@ -140,6 +113,6 @@ int PositionToIndex(Position i);
UndoMove MakeMove(Move move, Game *g);
void UnMakeMove(UndoMove undo, Game *g);
-Position FindKing(Game *g, bool white);
+Position FindKing(Game *g, bool color);
void UpdateHelpers(Game *g);
#endif /* SRC_BOARD_H_ */