22 moves played · 2 takebacks · ply 16
Two players, one board, and a game you can wind back and forth like a tape.
What fold does here
Every move is stored as a small change to the board: this piece leaves this square (−1) and lands on that one (+1). A separate list says which moves are in force. The board you see is a fold view: the sum of every applied move's changes. Material, captured pieces and castling rights are views too.
One rule lives in fold rather than in code: a square holds at most one piece. A write that would break it is refused whole.
Why it shows off fold
Rewinding is the trick. Stepping back a move doesn't recompute the game from the start or restore a saved copy. It takes that move off the list, and fold subtracts exactly its changes from the board and from everything built on the board. Scrub forward and fold adds them back. Most databases treat an update as final; fold treats every row as something that can be taken back, so undo is free and exact.
Worth trying
- Play a few moves, then scrub back with the time controls. Captured pieces return, and material follows.
- Open Inspect and step back one move: a handful of rows are retracted, not a board rebuilt.
- Make a move while rewound: the old continuation is dropped, like a branch.
Still app code
The rules of chess: legal moves, castling, en passant, promotion, check and mate. Fold stores and rewinds the game; it doesn't know how a knight moves.
Press \ in the app to watch fold's commits as they happen.