{"slug": "chess-invariants", "title": "Chess Invariants", "summary": "The article introduces the concept of invariants in chess, dividing them into state invariants (conditions true in a single state, like turn parity) and transition invariants (conditions over a step, like move count strictly increasing). It explains that basic chess rules satisfy invariants such as exactly two squares changing per move, but notes that adding castling, en passant, or pawn promotion violates some of these invariants. The piece is a technical exploration of modeling chess as a concurrent system to derive and test these logical constraints.", "body_md": "Chess invariants\nChess is a lot trickier than it looks. It has so many rules: castling, en passant, pawn promotion, pinning, the discovered check, and the deadlock case of stalemate.\nIt is a concurrent system, but with a very specific kind of concurrency: interleaved execution. More specifically, taking turns: white, then black, then white.\nYou know what we do with concurrent systems here? Here we model them, and we distill their invariants.\nHere is some setup definitions first.\nIn a CS or math paper, if you write \"Section 2: Model and Problem\" well enough, the rest of the paper writes itself. With this setup you can sort of see what the actions will be.\nIn fact, forget about the actions. Let's look at some invariants.\nInvariants\nWhen deriving invariants we ask: what must always be true? I find it useful to split the safety invariants into two camps: state invariants (which are predicates over a single state) and transition invariants (which are predicates over a step). The transition invariants are not as commonly used as state invariants, but they can be very helpful, especially when you are reasoning about transitions of a system. In the case of a system like chess, I think the transition invariants come in very handy as you may see below.\nState invariants\nTypeOK says every variable lives in the right space. It is boring, but it has caught more bugs than I would like to admit. OneKingPerColor and BothKingsOnBoard are also sanity checks.\nTurnParity is the first interesting one. It ties two state variables together: WHITE moves on even moves, BLACK on odd. The MakeMove action satisfies this TurnParity.\nPreviousPlayerNotInCheck restates the rule that \"you must end your turn not in check\" as \"look back: the player who just moved is not in check\". NotBothInCheck is a corollary.\nTransition invariants\nThese are predicates over a <<state, next-state>> pair, written with the bracketed form: [][P]_vars. They express how things change with constraints. The notation is simple: x is the value of the variable x in this state, and x' denotes the value in the next-state.\nMoveCountStrictlyIncreases and TurnAlternates say each step increments the move count with the colors flipping. If a transition ever messes this up, something has gone wrong.\nPieceCountNonIncreasing rules out pieces appearing out of thin air. SingleCapturePerMove tightens this: at most one piece disappears per step. ExactlyTwoSquaresChange is the strongest here. It says precisely two squares change per move, the source (now empty) and the destination (now holding the moving piece).\nHaha, yes, this is a model of the basic chess rules only. A useful exercise here is to consider which of these invariants survive when we add castling, pawns, en passant?\nExactlyTwoSquaresChange gets violated when we add castling: four squares change in one move. Similarly, en passant captures a piece not on the destination square, so three squares change.\nPieceCountNonIncreasing survives pawn promotion (when a pawn becomes a queen, the count is unchanged).", "url": "https://wpnews.pro/news/chess-invariants", "canonical_source": "http://muratbuffalo.blogspot.com/2026/05/chess-invariants.html", "published_at": "2026-05-22 11:06:52+00:00", "updated_at": "2026-05-22 12:13:19.598532+00:00", "lang": "en", "topics": [], "entities": [], "alternates": {"html": "https://wpnews.pro/news/chess-invariants", "markdown": "https://wpnews.pro/news/chess-invariants.md", "text": "https://wpnews.pro/news/chess-invariants.txt", "jsonld": "https://wpnews.pro/news/chess-invariants.jsonld"}}