Chess player/PicoLisp: Difference between revisions

Content added Content deleted
m (→‎{{header|PicoLisp}}: "header" template isn't necessary on this page)
No edit summary
 
Line 1: Line 1:
This implementation supports all chess rules (including castling, pawn promotion and en passant), switching sides, unlimited undo/redo, and the setup, saving and loading of board positions to/from files.
This implementation supports all chess rules (including castling, pawn promotion and en passant), switching sides, unlimited undo/redo, and the setup, saving and loading of board positions to/from files.
<lang PicoLisp># *Board a1 .. h8
<syntaxhighlight lang="PicoLisp"># *Board a1 .. h8
# *White *Black *WKPos *BKPos *Pinned
# *White *Black *WKPos *BKPos *Pinned
# *Depth *Moved *Undo *Redo *Me *You
# *Depth *Moved *Undo *Redo *Me *You
Line 566: Line 566:
(val This)
(val This)
(not (memq This *Moved)) ) )
(not (memq This *Moved)) ) )
(append *White *Black) ) ) ) ) ) )</lang>
(append *White *Black) ) ) ) ) ) )
</syntaxhighlight>
Start:
Start:
<pre>
<pre>$ pil chess.l -main +
$ pil chess.l -main +
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
8 |<R>|<N>|<B>|<Q>|<K>|<B>|<N>|<R>|
8 |<R>|<N>|<B>|<Q>|<K>|<B>|<N>|<R>|
Line 586: Line 588:
1 | R | N | B | Q | K | B | N | R |
1 | R | N | B | Q | K | B | N | R |
+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+---+
a b c d e f g h</pre>
a b c d e f g h
</pre>
Entering moves:
Entering moves:
<lang PicoLisp>: (go e2 e4)</lang>
<syntaxhighlight lang="PicoLisp">: (go e2 e4)</syntaxhighlight>

Undo moves:
Undo moves:
<lang PicoLisp>: (go -)</lang>
<syntaxhighlight lang="PicoLisp">: (go -)</syntaxhighlight>

Redo:
Redo:
<lang PicoLisp>: (go +)</lang>
<syntaxhighlight lang="PicoLisp">: (go +)</syntaxhighlight>

Switch sides:
Switch sides:
<lang PicoLisp>: (go)</lang>
<syntaxhighlight lang="PicoLisp">: (go)</syntaxhighlight>

Save position to a file:
Save position to a file:
<lang PicoLisp>: (ppos "file")</lang>
<syntaxhighlight lang="PicoLisp">: (ppos "file")</syntaxhighlight>

Load position from file:
Load position from file:
<lang PicoLisp>: (load "file")</lang>
<syntaxhighlight lang="PicoLisp">: (load "file")</syntaxhighlight>