Malcolm James Webb (Mjw)
New member Username: Mjw
Post Number: 8 Registered: 5-2008
| | Posted on Sunday, January 20, 2013 - 3:45 pm: | |
I can think of two ways for another piece to test for check. Both use the "attacked?" function. 1) Search for the King, and then find out if it is "attacked?". To search for the King, when defining the board create a link "next" linking all the squares on the board (see my recently posted game "Abagoren Chess" for an example, or any of numerous other games). Create the macro "test-check" for movement of pieces which needs to know if the King is in check: (define test-check (mark next (while not-marked? (if (and friend? (piece? King)) (set-flag in-check attacked?)) next))) After executng this function, the flag in-check can be tested as true or false. 2) Use a virtual King-move which only occurs when in check: Define an off board position in the board definition (could be a dummy position, as no piece actually moves there eg (dummy END)) Include in the definition of King moves the move (if attacked? (capture END) add) Note that this move cannot actually be executed if the goal is checkmate, as it is a capture which cannot possibly get your king out of check. If the goal is not defined as checkmate, you may need to use move-type & move-priorities to stop an actual move being generated. Then include in the move definition of the check-blocking move (verify (defended? END)) Both the defended? and the attacked? functions are time-consuming for Zillions. |