Earlier quoted context omitted.
Unlike en-passant and castling, pinning and discovered checks are consequences of lower-level rules. At the "Is this move legal?" level, they don't need unique rules of its own if the lower-level rules are specified correctly.
3.9.2: no piece can be moved if that exposes or leaves its own king in check.
Chess invariants
11–20 of 67 posts
Re: Chess invariants
#12Re: Chess invariants
#13Re: Chess invariants
#14Re: Chess invariants
#15I can't wait to show this to my manager next time he asks why it's taking three weeks to build a simple CRUD app. "Look, if this guys TLA+ logic struggles to model a 1,500-year-old game without crying over a French pawn-capture rule, you can't expect me to integrate Stripe billing without a few state invariant violations."
Re: Chess invariants
#16Re: Chess invariants
#17The post talks about "transition invariants" that should be somehow different from "state invariants" yet it describe them as:
> These are predicates over a > pair ...
i.e. it still is about state, but I find it much more useful to focus on behavior so instead of thinking about how state transition you focus on what the program is allowed to perform, regardless of the underlying data structure.
What I mean is that I'd like the code to tell me why a certain piece can't do such move instead of why it cannot transition it's position to another position and basically dumping its state in my head and there I have to execute the program myself.
Re: Chess invariants
#18https://neuroning.com/boardgames-exercise/notebooks/walkthro...
The implementation makes it really easy to add new piece types or rules. For example, here's the full logic for rooks (sans castling):
(defn expand-pmove-for-rook [pmove]
(->> pmove
(expand-pmove-dirs [↑ ↓ ← →])
(pmoves-discard #(or (pmove-on-same-player-piece? %)
(pmove-changed-direction? %)))
(map pmoves-finish-capturing-opponent-piece)
(pmoves-finish-and-continue))))Re: Chess invariants
#19Earlier quoted context omitted.
Well, if a piece is pinned it's illegal to move it. Rule 3.9.2: No piece can be moved that will either expose the king of the same colour to check or leave that king in check.
You can also pin a pawn to a queen, but the pawn can still legally move.
Re: Chess invariants
#20If you like this, you're probably gonna like this: https://en.wikipedia.org/wiki/Chessboard_complex