On this page:
chess-patch?
chess-patch
chess-patch-apply
empty-chess-patch
chess-patch-failure-reason?
8.12

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
A predicate for chess patches.

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)
Constructs a chess patch that makes the following changes when applied:

procedure

(chess-patch-apply patch board)  result?

  patch : chess-patch?
  board : chess-board?
Applies patch to board, returning a result containing either the successfully-updated chess board or a reason describing why the patch failed.

The empty chess patch, which does nothing to the board and always succeeds.

procedure

(chess-patch-failure-reason? v)  boolean?

  v : any/c