Echecs.MoveGen (Echecs v0.1.5)

Copy Markdown View Source

Legal-only move generation using the check-mask + pin-mask technique.

Instead of generating pseudo-legal moves and filtering them, legal_moves_int/4 computes the checking pieces (check_mask) and the pinned rays (pin_rays) once per position, then emits only legal moves: king moves avoid the danger set, and all other moves are masked by check_mask and their pin ray. Double check exits early with king moves only.

Moves are emitted as packed integers (see Echecs.Move) and converted to structs only at the API boundary by legal_moves/1. The captures/1 and quiets/1 variants share the same pipeline for search use.

Summary

Functions

Generates only capturing moves (for Quiescence Search).

Returns true if there is at least one legal move. Short-circuits on first found.

Returns a list of all legal moves for the current player.

Returns all legal moves as packed integers (no struct allocation).

Returns a list of pseudo-legal moves (ignoring check).

Generates only non-capturing (quiet) moves.

Functions

captures(game)

Generates only capturing moves (for Quiescence Search).

generate_moves_targeting(game, target_sq, piece_type)

quiets(game)

Generates only non-capturing (quiet) moves.