Try fo fit move_t in 16 bits ? #12

Closed
opened 2024-04-28 16:51:19 +02:00 by bruno · 5 comments
Owner

ideas:

  • Remove useless grabbed piece (saved in move_do())
  • shrink flags: As they are mutually exclusive: castling, e.p., promotion.

We would be left with:

  • from/to: 12 bits (6 bits each)
  • Promoted piece: 2 bits: N=0, B=1, R=2, Q=3). Promoted piece would be KNIGHT + promoted_piece
  • Flags: 2 bits (quiet, e.p., castle, capture or promotion). This looks short.
ideas: - Remove useless grabbed piece (saved in `move_do()`) - shrink flags: As they are mutually exclusive: castling, e.p., promotion. We would be left with: - from/to: 12 bits (6 bits each) - Promoted piece: 2 bits: N=0, B=1, R=2, Q=3). Promoted piece would be `KNIGHT + promoted_piece` - Flags: 2 bits (quiet, e.p., castle, capture or promotion). This looks short.
bruno added the
enhancement
label 2024-04-28 16:51:19 +02:00
Author
Owner
  • e.p. flag can be removed: (piece == PAWN && to == ep) will do the trick
  • castling flag can be removed: we can test if to == from+2 or to == from - 2
- e.p. flag can be removed: `(piece == PAWN && to == ep)` will do the trick - castling flag can be removed: we can test if `to == from+2` or `to == from - 2`
bruno closed this issue 2024-06-25 11:07:46 +02:00
bruno reopened this issue 2024-06-25 11:09:32 +02:00
Author
Owner

flags capture, double push, and promotion removed in ec2d229.
Left to do:

  • Use 2 bits for promoted piece
  • remove e.p. flag
  • use one (or zero) flags value for castling
flags capture, double push, and promotion removed in ec2d229. Left to do: - Use 2 bits for promoted piece - remove e.p. flag - use one (or zero) flags value for castling
Author
Owner

Done in ffd5d05 :

  • move flags are now values (1, 2, 3...) instead of bitmask (1, 2, 4...)
  • unique value for castling flag

2 bits left to save to fit into 2 octets (16-bits).

Done in ffd5d05 : - move flags are now values (1, 2, 3...) instead of bitmask (1, 2, 4...) - unique value for castling flag 2 bits left to save to fit into 2 octets (16-bits).
Author
Owner

Since ffd5d05, flags are values (not bitmasks) meaning that we currently have one unused value in flags (the value 3, using 2 bits). We can use this value to flag promotion.

Other ideas "save bits" :

  • If promoted piece uses only 2 bits, we can :

    • test that piece is a pawn AND that destination square is on 1st or 8th rank
  • En-passant flag can be removed if we test that piece is pawn and dest square is en-passant square.

  • Castling flag can be removed with some changes in move_do, one of :

    • test if piece is king AND distance is 2
    • test is piece is king and move_fromto() is E1C1/E1G1 / E8C8/E8G8
  • If we know the moving piece type, we can use the same flag value for different pieces (e.g en-passant and castling)

Since ffd5d05, flags are values (not bitmasks) meaning that we currently have one unused value in flags (the value 3, using 2 bits). We can use this value to flag promotion. Other ideas "save bits" : - If promoted piece uses only 2 bits, we can : - test that piece is a pawn AND that destination square is on 1st or 8th rank - En-passant flag can be removed if we test that piece is pawn and dest square is en-passant square. - Castling flag can be removed with some changes in move_do, one of : - test if piece is king AND distance is 2 - test is piece is king and move_fromto() is E1C1/E1G1 / E8C8/E8G8 - If we know the moving piece type, we can use the same flag value for different pieces (e.g en-passant and castling)
Author
Owner

Finished with a2451d79db

Finished with a2451d79db
bruno closed this issue 2024-07-01 14:10:47 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bruno/brchess#12
No description provided.