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

object Bitboard

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

Supertypes
class Object
trait Matchable
class Any
Self type
Bitboard.type
object Color

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

Supertypes
class Object
trait Matchable
class Any
Self type
Color.type
object FenParser

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

Both parse and serialize are inverses of each other for any valid FEN string.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
FenParser.type
case class GameState(whitePieces: Bitboard, blackPieces: Bitboard, pawns: Bitboard, knights: Bitboard, bishops: Bitboard, rooks: Bitboard, queens: Bitboard, kings: Bitboard, mailbox: Map[Square, Piece], activeColor: Color, castlingRights: String, enPassant: Option[Square], halfMoveClock: Int, fullMoveNumber: Int)

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.

Value parameters

activeColor

The color of the player whose turn it is.

bishops

Bitboard for all Bishops (both colors).

blackPieces

Bitboard for all Black pieces.

castlingRights

FEN-standard castling string (e.g., "KQkq").

enPassant

Potential en passant target square.

fullMoveNumber

The number of the current full move.

halfMoveClock

Clock for the 50-move rule.

kings

Bitboard for all Kings (both colors).

knights

Bitboard for all Knights (both colors).

mailbox

Map of occupied squares to their respective pieces.

pawns

Bitboard for all Pawns (both colors).

queens

Bitboard for all Queens (both colors).

rooks

Bitboard for all Rooks (both colors).

whitePieces

Bitboard for all White pieces.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object MicroMove

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 Square (0-63)
  • Bits 0-5: Origin Square (0-63)

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
MicroMove.type
object Move

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Move.type
object Piece

A packed chess piece combining Color and PieceType.

A packed chess piece combining Color and PieceType.

Memory Layout (4 bits total):

  • Bit 3: Color (0 for White, 1 for Black)
  • Bits 0-2: PieceType (1-6)

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Piece.type
object PieceType

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

Supertypes
class Object
trait Matchable
class Any
Self type
PieceType.type
object Square

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

Supertypes
class Object
trait Matchable
class Any
Self type
Square.type
case class Turn(diceRoll: Int, microMoves: List[MicroMove])

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

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Types

opaque type Bitboard
opaque type Color
opaque type MicroMove
opaque type Move

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

opaque type Piece
opaque type PieceType
opaque type Square

Extensions

Extensions

extension (state: GameState)

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 move application — higher-level logic such as switching turns after three micro-moves is the responsibility of the Turn manager.

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 GameState reflecting the position after the move