Move generation produces all legal moves from a position. Must be 100% correct.
Pseudo-legal generation: generate all moves that follow piece movement rules, then filter illegal ones (leaving king in check).
Piece moves:
- Pawn: single push, double push from rank 2/7, captures diagonally, en passant, promotion.
- Knight: 8 possible squares from lookup table.
- Bishop: sliding along diagonals (ray attacks).
- Rook: sliding along ranks/files.
- Queen: bishop + rook.
- King: 8 adjacent squares, castling.
Bitboard 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.
Magic bitboards: for sliding pieces, hash occupancy pattern to get attacks in O(1). Precompute 2^N entries for each relevant occupancy subset.
Legality filtering: after generating pseudo-legal moves, make the move, check if own king is attacked. If yes, illegal.
Move ordering: generate captures first (MVV-LVA), then killers, then history heuristic. Critical for alpha-beta performance.