4 Chess Patches
(require chess/patch) | package: chess |
A chess patch is a set of changes to a chess board , such as piece movements and captures. Boards can be modified with patches using chess-patch-apply. Patching a chess board might fail, for example because pieces needing to be removed aren’t present or there are obstacles in the way of added pieces. Patch application is atomic: a patch might succeed or fail but it will never half succeed, as failures always leave the board unchanged.
procedure
(chess-patch? v) → boolean?
v : any/c
procedure
(chess-patch [ #:placements placements #:removals removals #:captures captures #:obstruction-checks obstruction-checks #:safety-checks safety-checks]) → chess-patch?
placements : (hash/c chess-square? colored-chess-piece? #:immutable #t #:flat? #t) = (hash)
removals : (hash/c chess-square? colored-chess-piece? #:immutable #t #:flat? #t) = (hash)
captures : (hash/c chess-square? chess-color? #:immutable #t #:flat? #t) = (hash) obstruction-checks : (set/c chess-square?) = (set)
safety-checks : (hash/c chess-square? chess-color? #:immutable #t #:flat? #t) = (hash)
For each square and piece in placements, adds a piece to the board at that square. The square must be empty, but note that piece removals and captures in a patch are applied before piece placements.
For each square and piece in removals, removes that piece from that square of the board. If the square does not contain a piece or it contains a different piece, the patch fails.
For each square and capturing player color in captures, removes an opponent’s piece from that square. If the square does not contain a piece, or if it contains a piece of the same color as the capturing player, then the patch fails.
For each square in obstruction-checks, checks that the square is unoccupied. If it isn’t, the patch fails. This is used to represent the movement of pieces like bishops and rooks, which move along lines of empty squares.
For each square and defending player color in safety-checks, checks that that square is safe from attack by any opponent’s piece. If it isn’t, the patch fails. This is used to represent the movement of kings, which cannot move into squares that would place the king in check.
procedure
(chess-patch-apply patch board) → result?
patch : chess-patch? board : chess-board?
value
procedure
(chess-patch-failure-reason? v) → boolean?
v : any/c