Plans for a chess/taikyoku shogi/what have you engine

Links RSS
Author ArgentumCation Posts Notes
License CC-BY-NC-SA 4.0+ Updated
1
2
3
4
5
6
7
  board: Array,
  currentPlayer: 'white' | 'black',
  moveHistory: Array,
  enPassantTarget: {x, y} | null,  // Updates each turn
  halfMoveClock: number,  // For 50-move rule
  capturedPieces: Array
}

3. Move Validation System

Separate move generation into layers:

Layer 1: Basic Move Patterns

getPseudoLegalMoves(piece, position)
  - Returns all squares the piece could move to
  - Ignores check/pin considerations
  - Each piece type has its own logic

Layer 2: Board-Aware Filtering

getLegalMoves(piece, position, gameState)
  - Filters pseudoLegal moves
  - Checks if king would be in check after move
  - Handles special moves (castling, en passant)

Handling Special Cases

En Passant

Castling

Pawn Promotion

Key Functions

isSquareAttacked(x, y, byColor, gameState)
  - Critical for check detection
  - Generate all opponent moves, see if any target this square

isKingInCheck(color, gameState)
  - Find king position
  - Use isSquareAttacked

makeMove(from, to, gameState)
  - Validate move is legal
  - Update board
  - Handle captures
  - Update en passant state
  - Toggle current player
  - Add to move history (for undo)

getGameStatus()
  - Returns: 'playing', 'check', 'checkmate', 'stalemate', 'draw'