File size: 1,484 Bytes
3c88a0f | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "chess-0084", "name": "Chess Move Generation"}
{"type": "message", "message": {"role": "system", "content": "You are an expert chess programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain chess move generation algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "Move generation produces all legal moves from a position. Must be 100% correct.\n\nPseudo-legal generation: generate all moves that follow piece movement rules, then filter illegal ones (leaving king in check).\n\nPiece moves:\n- Pawn: single push, double push from rank 2/7, captures diagonally, en passant, promotion.\n- Knight: 8 possible squares from lookup table.\n- Bishop: sliding along diagonals (ray attacks).\n- Rook: sliding along ranks/files.\n- Queen: bishop + rook.\n- King: 8 adjacent squares, castling.\n\nBitboard approach: precompute attack tables for each piece type on each square. Knight attacks[sq] = precomputed bitmask. Sliding attacks: use magic bitboards for occupancy-dependent lookups.\n\nMagic bitboards: for sliding pieces, hash occupancy pattern to get attacks in O(1). Precompute 2^N entries for each relevant occupancy subset.\n\nLegality filtering: after generating pseudo-legal moves, make the move, check if own king is attacked. If yes, illegal.\n\nMove ordering: generate captures first (MVV-LVA), then killers, then history heuristic. Critical for alpha-beta performance."}}
|