Skip to content

Latest commit

 

History

History
90 lines (63 loc) · 2.42 KB

File metadata and controls

90 lines (63 loc) · 2.42 KB

Hyperion Architecture ⚡

Board representation

Hyperion addresses the board as a 14×14 grid:

bit = rank * 14 + file

The four 3×3 corner regions are invalid. The remaining 160 squares are stored inside an aligned 256-bit value made from four 64-bit limbs.

This mapping keeps directional offsets simple:

North      +14
South      -14
East        +1
West        -1
NorthEast  +15
NorthWest  +13
SouthEast  -13
SouthWest  -15

Compile-time source masks prevent shifts from wrapping across files or entering invalid corners.

Position data

Position maintains:

  • Six bitboards per color
  • One occupancy bitboard per color
  • Total occupancy
  • A 196-entry mailbox
  • Side to move
  • Rule mode
  • Eight castling-right bits
  • En-passant target and victim squares
  • Halfmove clock
  • Ply count
  • Incremental 64-bit Zobrist key

The mailbox makes captures and piece identification constant-time, while bitboards handle attacks and bulk occupancy operations.

Sliding attacks

Ray scanner

The default slider backend uses precomputed directional rays:

ray
→ intersect occupied
→ locate nearest blocker
→ remove squares beyond blocker

This requires no large lookup table and was the fastest backend in the included build-machine benchmark.

PEXT compressed tables

The optional backend compresses occupied squares on each directional ray using BMI2 PEXT, then performs a table lookup. It serves the same role as magic bitboards on an 8×8 board but fits the irregular 160-square geometry more naturally.

Use the benchmark before selecting it; BMI2 availability does not guarantee that this backend is faster on a particular CPU.

Legal move generation

Hyperion first generates pseudo-legal moves. It then uses a fast path:

  • If the king is not in check, ordinary moves from unpinned non-king pieces are accepted directly.
  • King moves, en-passant moves, and moves from pinned pieces are verified with make/undo.
  • If the king is already in check, every candidate is verified.

This preserves correctness while removing most make/undo traffic in normal positions.

State restoration

StateInfo saves only the irreversible or overwritten state needed for undo:

  • Zobrist key
  • En-passant target
  • En-passant victim
  • Captured piece and square
  • Side to move
  • Castling rights
  • Halfmove clock
  • Ply

Piece placement and occupancy are reversed incrementally. The original Zobrist key is restored exactly.