GameFlags

dicechess.engine.domain.GameFlags$package.GameFlags
object GameFlags

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
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
GameFlags.type

Members list

Value members

Concrete methods

def apply(color: Color, castlingRights: Int, enPassantFiles: Int, dice1: Int, dice2: Int, dice3: Int, halfMoveClock: Int): GameFlags

Builds a GameFlags integer from individual components.

Builds a GameFlags integer from individual components.

Every component other than halfMoveClock is masked to its allocated bit-width before packing; values that exceed their field width are silently truncated. halfMoveClock is the exception: out-of-range values are clamped to MaxHalfMoveClock instead (see withHalfMoveClock).

Value parameters

castlingRights

4-bit mask: Bit 0 = K (White king-side), Bit 1 = Q, Bit 2 = k, Bit 3 = q

color

the active player color (0 = White, 1 = Black)

dice1

first dice slot value (0 = empty, 1-6 = die face)

dice2

second dice slot value

dice3

third dice slot value

enPassantFiles

8-bit mask: Bit N is set when file N has an active en-passant target square

halfMoveClock

half-move counter for the 50-move rule; clamped to 0–MaxHalfMoveClock, not masked

Attributes

Returns

the packed GameFlags integer

Source
GameFlags.scala
def fromList(color: Color, castlingRights: Int, enPassantFiles: Int, dicePool: List[Int], halfMoveClock: Int): GameFlags

Convenience constructor that builds GameFlags from a dice pool list instead of individual slots.

Convenience constructor that builds GameFlags from a dice pool list instead of individual slots.

Missing slots default to 0 (empty). At most the first three elements of dicePool are used.

Value parameters

castlingRights

4-bit castling-rights mask (same as apply)

color

the active player color

dicePool

up to three die values; excess elements are ignored

enPassantFiles

8-bit en-passant file mask (same as apply)

halfMoveClock

7-bit half-move counter

Attributes

Returns

the packed GameFlags integer

Source
GameFlags.scala

Concrete fields

val DiceSlots: Int

How many dice the layout can hold: three 3-bit slots at bits 13-21, matching the three dice a turn rolls.

How many dice the layout can hold: three 3-bit slots at bits 13-21, matching the three dice a turn rolls.

Published because the packing is lossy in one direction only — fromList keeps the first DiceSlots values and drops the rest — so anything parsing external input has to check the length itself to avoid reporting success for a pool it silently shortened. FenParser.parse does.

Attributes

Source
GameFlags.scala

Sentinel value indicating an invalid GameFlags representation.

Sentinel value indicating an invalid GameFlags representation.

Valid GameFlags instances occupy bits 0–28, so their packed 32-bit signed integer value is always non-negative. Negative values (specifically -1) serve as an allocation-free error sentinel on hot paths.

Attributes

Source
GameFlags.scala
val MaxHalfMoveClock: Int

The largest half-move clock the 7-bit field at bits 22-28 can hold.

The largest half-move clock the 7-bit field at bits 22-28 can hold.

Published for the same reason as DiceSlots: the packing clamps rather than rejecting, so 200 arrives as 127 — a plausible number that hides how far out of range the input actually was. Callers accepting a clock from outside must bound it themselves if they need to distinguish a legitimate ceiling value from bad input.

Attributes

Source
GameFlags.scala

A GameFlags with all fields zeroed: White to move, no castling rights, no en-passant, empty dice pool, zero half-move clock.

A GameFlags with all fields zeroed: White to move, no castling rights, no en-passant, empty dice pool, zero half-move clock.

Attributes

Source
GameFlags.scala

Givens

Givens

Extensions

Extensions

extension (flags: GameFlags)
inline def activeColor: Color

Returns the active player's color.

Returns the active player's color.

Attributes

Source
GameFlags.scala
def addDie(die: Int): Either[String, GameFlags]

Adds a single die to the pool. Returns Left if the pool is already full or the die is invalid.

Adds a single die to the pool. Returns Left if the pool is already full or the die is invalid.

Attributes

Source
GameFlags.scala
inline def castlingRights: Int

Returns the 4-bit castling rights integer.

Returns the 4-bit castling rights integer.

Attributes

Source
GameFlags.scala
inline def consumeDiceFor(move: Move, moverType: PieceType): GameFlags

Consumes the dice required to execute move by a piece of moverType.

Consumes the dice required to execute move by a piece of moverType.

Under Dice Chess rules:

  • Castling requires and consumes both a King (6) and a Rook (4) die.
  • Standard moves consume one die matching the mover's piece type.

Returns GameFlags.Invalid if the required dice are not available in this flags' dice pool. Enforces require(moverType.diceValue != 0) defense-in-depth against moves from empty squares.

Value parameters

move

the move being executed

moverType

the piece type of the moving piece

Attributes

Returns

the updated GameFlags with consumed dice removed, or GameFlags.Invalid if required dice are missing

Source
GameFlags.scala
inline def containsDie(die: Int): Boolean

True when the pool holds at least one die of value die.

True when the pool holds at least one die of value die.

Attributes

Source
GameFlags.scala
def dicePool: List[Int]

Extracts the available dice into a standard Scala List (useful for UI/FEN boundaries). Avoid using in hot-paths.

Extracts the available dice into a standard Scala List (useful for UI/FEN boundaries). Avoid using in hot-paths.

Attributes

Source
GameFlags.scala
inline def diceSlot1: Int

Returns the raw value of dice slot 1 (0 = empty, 1–6 = die face).

Returns the raw value of dice slot 1 (0 = empty, 1–6 = die face).

Attributes

Source
GameFlags.scala
inline def diceSlot2: Int

Returns the raw value of dice slot 2 (0 = empty, 1–6 = die face).

Returns the raw value of dice slot 2 (0 = empty, 1–6 = die face).

Attributes

Source
GameFlags.scala
inline def diceSlot3: Int

Returns the raw value of dice slot 3 (0 = empty, 1–6 = die face).

Returns the raw value of dice slot 3 (0 = empty, 1–6 = die face).

Attributes

Source
GameFlags.scala
inline def enPassantFiles: Int

Returns the 8-bit en-passant files mask.

Returns the 8-bit en-passant files mask.

Attributes

Source
GameFlags.scala
inline def halfMoveClock: Int

Returns the half-move clock counter.

Returns the half-move clock counter.

Attributes

Source
GameFlags.scala
inline def isDicePoolEmpty: Boolean

True when all three dice slots are empty.

True when all three dice slots are empty.

Attributes

Source
GameFlags.scala
inline def isValid: Boolean

Attributes

Source
GameFlags.scala
def removeDie(die: Int): GameFlags

Removes a single occurrence of the specified die from the pool. Does nothing if the die is not present.

Removes a single occurrence of the specified die from the pool. Does nothing if the die is not present.

Attributes

Source
GameFlags.scala

Returns the active player's color flipped.

Returns the active player's color flipped.

Attributes

Source
GameFlags.scala
inline def value: Int

Attributes

Source
GameFlags.scala
inline def withActiveColor(c: Color): GameFlags

Sets the active player's color, returning a new GameFlags.

Sets the active player's color, returning a new GameFlags.

Attributes

Source
GameFlags.scala
inline def withCastlingRights(rights: Int): GameFlags

Sets the castling rights, returning a new GameFlags.

Sets the castling rights, returning a new GameFlags.

Attributes

Source
GameFlags.scala
def withDicePool(dice: List[Int]): GameFlags

Replaces the entire dice pool.

Replaces the entire dice pool.

Attributes

Source
GameFlags.scala
inline def withDiceSlotsOf(src: GameFlags): GameFlags

Replaces this value's three dice slots with those of src, leaving every other flag bit untouched.

Replaces this value's three dice slots with those of src, leaving every other flag bit untouched.

Allocation-free alternative to withDicePool for hot paths: it copies the slot values verbatim, so an emptied slot stays a hole rather than compacting. The dicePool getter and move generation skip empty slots, so the observable multiset is identical to a compacted pool.

Attributes

Source
GameFlags.scala
inline def withEnPassantFiles(filesMask: Int): GameFlags

Sets the en-passant files mask, returning a new GameFlags.

Sets the en-passant files mask, returning a new GameFlags.

Attributes

Source
GameFlags.scala
inline def withHalfMoveClock(clock: Int): GameFlags

Sets the half-move clock, clamping to MaxHalfMoveClock rather than wrapping when clock exceeds the packed field's range — a value of 200 becomes 127, not 72.

Sets the half-move clock, clamping to MaxHalfMoveClock rather than wrapping when clock exceeds the packed field's range — a value of 200 becomes 127, not 72.

Attributes

Source
GameFlags.scala