In this note
  1. 01State Model
  2. 02Move Validation
  3. 03Check and Endgame Detection
  4. 04Knowledge Points
  5. 05Takeaway

Magic Chess is an ongoing browser chess prototype built with Vue 3 and TypeScript. It is not a shipped game yet, but it is a useful place to work out rule-engine structure, board state, and custom chess-like mechanics.

Chess already has plenty of edge cases, and the custom variants add another layer.

State Model

The core types model pieces, colors, positions, boards, moves, game status, and game modes. Keeping them explicit makes later logic easier to reason about, since every move function works from the same vocabulary.

The game composable owns the shared state: board, selected square, valid moves, current player, captured pieces, move history, timers, promotion state, and AI move timing.

Move Validation

The validator handles standard piece movement, special cases such as en passant and castling, and custom modes: ghost pawns, heavy knights, bishop sniper behavior, and rook charge behavior.

One pattern shows up throughout: simulation. Candidate moves are checked against a cloned board, so a move that exposes the king gets filtered out before the UI accepts it.

Check and Endgame Detection

Check detection is separate from general move generation. To avoid recursive validation loops, the project asks whether a king is threatened using attacking moves.

The detector also checks for checkmate, stalemate, and insufficient material. The project still needs finishing work before it would pass as a polished game.

Knowledge Points

  • A Vue composable is a clean place to keep game state and expose actions to components.
  • TypeScript union types and interfaces make board-game logic safer and easier to inspect.
  • Chess validation often needs simulation because a move can be locally valid and globally illegal.
  • Check detection should avoid calling full legal-move generation recursively.
  • Custom modes are easier to add when the base rules are modular.
  • UI highlights should be derived from state, not synced to the DOM by hand.
  • Timers, history, captured pieces, and the promotion UI are part of the game, not optional extras.

Takeaway

The repo is a work-in-progress game logic prototype. Its strongest lesson is how to separate state, rule validation, endgame detection, and rendering before polishing the gameplay.