dicechess.engine.domain
Core domain models for the Dice Chess Engine.
This package contains the fundamental data structures used to represent the chess board, pieces, moves, and game state. It heavily relies on Scala 3 Opaque Types and bitwise memory packing to guarantee zero-allocation performance during hot-path evaluations like Expectimax search.
Attributes
Members list
Type members
Classlikes
A 64-bit integer representing a set of squares on the chess board.
A 64-bit integer representing a set of squares on the chess board.
Uses Little-Endian Rank-File (LERF) mapping, where bit 0 is a1 and bit 63 is h8.
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Bitboard.type
Represents the player colors: White (0) or Black (1).
Represents the player colors: White (0) or Black (1).
Uses bitwise XOR for fast toggling between opponents.
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Color.type
Parser and serialiser for Forsyth-Edwards Notation (FEN).
Parser and serialiser for Forsyth-Edwards Notation (FEN).
FEN encodes a complete chess position in a single ASCII string consisting of six space-separated fields:
<piece placement> <active color> <castling rights> <en-passant square> <half-move clock> <full-move number>
Example (starting position):
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Dice Chess Extension (7th field)
This parser also supports an optional 7th field that stores the current turn's dice pool:
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1 pnb
The 7th field is a string of piece letters (e.g. "PNB" for White or "pnb" for Black = dice pool [1, 2, 3]), never longer than GameFlags.DiceSlots because a turn rolls three dice. It is absent ("-") or omitted when no dice have been rolled yet. serialize appends it automatically when the pool is non-empty.
Both parse and serialize are inverses of each other for any valid FEN string.
Attributes
- Source
- FenParser.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FenParser.type
An ultra-compact 32-bit representation of the meta-state of a Dice Chess game.
An ultra-compact 32-bit representation of the meta-state of a Dice Chess game.
Memory Layout (29 bits total):
- Bit 0 (1 bit) : Active Color (0 = White, 1 = Black)
- Bits 1-4 (4 bits): Castling Rights (Bit 1=K, Bit 2=Q, Bit 3=k, Bit 4=q)
- Bits 5-12 (8 bits): En-Passant Files (Bit N = File N has an EP target)
- Bits 13-15 (3 bits): Dice Slot 1 (0 = empty, 1-6 = piece/die value)
- Bits 16-18 (3 bits): Dice Slot 2
- Bits 19-21 (3 bits): Dice Slot 3
- Bits 22-28 (7 bits): Half Move Clock (0-127, for the 50-move rule)
Attributes
- Source
- GameFlags.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
GameFlags.type
The complete snapshot of a Dice Chess game state.
The complete snapshot of a Dice Chess game state.
Uses a hybrid architecture combining fast Bitboards for move generation and a Map mailbox for constant-time piece lookups. Game meta-state (active color, castling rights, dice pool, half-move clock) is packed into the flags field via GameFlags to minimise heap allocations on the search hot-path.
Value parameters
- bishops
-
Bitboard for all Bishops (both colors).
- blackPieces
-
Bitboard with a set bit for every square occupied by a Black piece.
- enPassant
-
Bitboard of active en-passant target squares (one bit per valid EP capture destination). Stored separately from flags because the 8-bit file mask in GameFlags is lossy for positions with multiple EP targets.
- flags
-
Packed 29-bit integer encoding active color, castling rights, en-passant file mask, dice pool (up to 3 dice), and the half-move clock. See GameFlags for the exact bit layout.
- fullMoveNumber
-
Full-move counter; incremented after each Black move (starts at 1 per FEN convention).
- kings
-
Bitboard for all Kings (both colors).
- knights
-
Bitboard for all Knights (both colors).
- mailbox
-
Fast O(1) flat array from dicechess.engine.domain.Square to Piece.
- pawns
-
Bitboard for all Pawns (both colors).
- queens
-
Bitboard for all Queens (both colors).
- rooks
-
Bitboard for all Rooks (both colors).
- whitePieces
-
Bitboard with a set bit for every square occupied by a White piece.
Attributes
- Source
- Models.scala
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
A fast, flat array representation of the 64 squares on the board.
A fast, flat array representation of the 64 squares on the board.
Gives O(1) piece lookup and near-instant cloning via System.arraycopy without GC allocations.
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Mailbox.type
A high-performance 16-bit packed micro-move.
A high-performance 16-bit packed micro-move.
Memory Layout:
- Bits 12-15: Promotion PieceType (optional, 0 if none)
- Bits 6-11: Target dicechess.engine.domain.Square (0-63)
- Bits 0-5: Origin dicechess.engine.domain.Square (0-63)
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
MicroMove.type
Companion object for Move: smart constructors, flag constants, and extension methods.
Companion object for Move: smart constructors, flag constants, and extension methods.
Flag constants follow the Chess Programming Wiki standard 4-bit encoding, extended with higher bits for promotions. The encoding allows O(1) flag tests using bitwise arithmetic.
Attributes
- Source
- Move.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Move.type
A packed chess piece combining dicechess.engine.domain.Color and dicechess.engine.domain.PieceType.
A packed chess piece combining dicechess.engine.domain.Color and dicechess.engine.domain.PieceType.
Memory Layout (4 bits total):
- Bit 3: Color (0 for White, 1 for Black)
- Bits 0-2: PieceType (1-6)
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Piece.type
Represents chess piece types corresponding to dice values.
Represents chess piece types corresponding to dice values.
Values are 1: Pawn, 2: Knight, 3: Bishop, 4: Rook, 5: Queen, 6: King.
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PieceType.type
Represents a chess board square index.
Represents a chess board square index.
The index ranges from 0 (a1) to 63 (h8), mapped row by row (a1, b1... h8).
Attributes
- Source
- Models.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Square.type
Board-symmetry transforms and position canonicalization for Dice Chess.
Board-symmetry transforms and position canonicalization for Dice Chess.
Two positions related by a rules-preserving symmetry have identical win probability, so collapsing them to a single canonical representative lets downstream consumers pool statistics (analytics) and share results across equivalent positions (search transposition tables, Monte-Carlo caches).
This object provides two exact symmetries: color-flip (always legal) and horizontal mirror (a win-probability symmetry only when there are no castling rights — see below). Horizontal shift is intentionally excluded: translation is not an isometry of the bounded 8x8 board (it changes a piece's distance to the edge, and therefore its mobility), so it does not preserve win probability.
Color-flip
A vertical board mirror (rank r rank 9 - r) combined with swapping every piece's colour and the side to move. Because Black's downward pawns become White's upward pawns, the result is a strategically identical position with the side to move relabelled (white-to-move black-to-move). It is an involution: colorFlip(colorFlip(s)) == s.
Attributes
- Source
- Symmetry.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Symmetry.type
A chess turn consisting of a dice outcome and a sequence of micro-moves.
A chess turn consisting of a dice outcome and a sequence of micro-moves.
Value parameters
- diceRoll
-
The result of the dice (1-6).
- microMoves
-
The list of 1 to 3 moves executed within this turn.
Attributes
- Source
- Models.scala
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Deterministic Zobrist hashing for Dice Chess game states.
Deterministic Zobrist hashing for Dice Chess game states.
Includes piece placement, active color, castling rights, en passant target squares, and canonical remaining dice pool combinations.
Attributes
- Source
- Zobrist.scala
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Zobrist.type
Types
Attributes
- Source
- Models.scala
Attributes
- Source
- Models.scala
Attributes
- Source
- GameFlags.scala
Attributes
- Source
- Models.scala
Attributes
- Source
- Models.scala
A highly optimized 16-bit encoded chess move.
A highly optimized 16-bit encoded chess move.
Designed to completely avoid garbage collection (GC) during the hot path of the search tree.
Memory layout:
- Bits 0-5 (6 bits): Destination square index (to)
- Bits 6-11 (6 bits): Source square index (from)
- Bits 12-15 (4 bits): Move Flags (Quiet, Capture, Promotion, etc.)
Attributes
- Source
- Move.scala
Attributes
- Source
- Models.scala
Attributes
- Source
- Models.scala
Attributes
- Source
- Models.scala
Extensions
Extensions
Applies a MicroMove (turn-based) to the current game state.
Applies a MicroMove (turn-based) to the current game state.
Handles piece movement, captures, and basic bitboard updates. This is a raw micro-move application. According to Dice Chess micro-move semantics, this method does not flip the active color or increment the full-move number. Turn transitions must be explicitly managed via GameState.endTurn().
Dice pool: The die matching the moving piece type is automatically removed from state.dicePool. If the pool is empty (e.g. when replaying from perft or search without dice context), the pool is left unchanged.
The half-move clock is reset to 0 on pawn moves and captures; otherwise it is increased by 1.
Value parameters
- mv
-
the micro-move to apply
Attributes
- Returns
-
a new dicechess.engine.domain.GameState reflecting the position after the micro-move, with dice pool decremented
- Source
- Position.scala