Skip to content
filedom
Esc
↑↓navigate↵open⌘Jpreview
On this page

Chess

Drag-to-move chess on the Finder desktop, a denser example of positioning, drag input, and host round-trips.

Chess puts more load on the renderer than Pong. The renderer, host bridge, and native layer have to agree on position, drag interaction, and timing while a full board is on screen. The source is in the Finder Mode repository under games/chess.

Modes

  • Solo: play the built-in AI (js-chess-engine). The AI waits 1.2 seconds before replying so its move reads as a reply.
  • Multiplayer: two machines share a board through a game-server Durable Object. Both sides join a room code.

From the Finder Mode repository root:

pnpm chess                  # solo vs computer
pnpm chess:multi create     # host a room
pnpm chess:multi join <room>

Like Pong, chess calls startSession with the default options, so your existing Desktop items are hidden in place for the game and shown again when it quits.

How it maps onto Finder

  • The board is a Wallpaper image. Each piece is a pooled Sprite with a library-minted invisible name, placed on a square computed from the board’s origin and cell size.
  • You drag a piece and the game reads where you dropped it, rounds that to the nearest square, and asks the engine to make the move. An illegal move, a move out of turn, or (in multiplayer) a server rejection leaves the piece’s position unchanged, and the Stage moves the file back.
  • Captured pieces line up in a tray for each colour. The turn indicator, the check banner, and the tray headers are pre-baked sprites in their own Stage, shown by moving them out of the park.
  • The game-over text uses <Text onDemand />, so its files are created fresh and draw above any piece the player dragged. R restarts the game.

Because it relies on absolute positioning and host round-trips, read chess alongside the Architecture and Host Runtime pages rather than as a first introduction.

Was this page helpful?