commit 472fc7b96aef54d2cd1b1b27f72d8033fbd7ca46
parent b216e80cfeaff31459ef15d200316c0fc4ca6ae7
Author: Alexander Burger <abu@software-lab.de>
Date: Tue, 24 Apr 2012 10:09:09 +0200
Support user input of pawn promotions to other pieces
Diffstat:
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/games/README b/games/README
@@ -1,4 +1,4 @@
-15jul11abu
+24apr12abu
(c) Software Lab. Alexander Burger
@@ -75,7 +75,7 @@ Your positions are marked with 'T', the computer's with '0'.
-The 'chess' game is minimalistic (444 lines of code). Nevertheless, it plays
+The 'chess' game is minimalistic (447 lines of code). Nevertheless, it plays
some slow - though correct - chess. Start it as:
$ pil games/chess.l -main +
@@ -116,6 +116,10 @@ Castling may be entered by just specifying the king's move:
: (go e1 g1)
+To promote a pawn to some piece other than a queen, you can specify a class:
+
+: (go h7 h8 +Knight)
+
To undo one or several moves, enter
: (go -)
diff --git a/games/chess.l b/games/chess.l
@@ -1,4 +1,4 @@
-# 16jul11abu
+# 24apr12abu
# (c) Software Lab. Alexander Burger
# *Board a1 .. h8
@@ -502,13 +502,16 @@
(cdr (asoq (caar M) (cdr M)))
(pick cdr (cdar M)) ) ) )
-(de yourMove (From To)
+(de yourMove (From To Cls)
(when
(find
- '((Lst)
+ '((Mov)
(and
- (== (caar Lst) (get From 'piece))
- (== To (pick cdr (cdar Lst))) ) )
+ (== (caar Mov) (get From 'piece))
+ (== To (pick cdr (cdar Mov)))
+ (or
+ (not Cls)
+ (isa Cls (car (last (car Mov)))) ) ) )
(moves *You) )
(prog1 (car (push '*Undo @))
(off *Redo)
@@ -550,7 +553,7 @@
((not Args) (xchg '*Me '*You) (myMove))
((== '- (car Args)) (and *Undo (undo)))
((== '+ (car Args)) (and *Redo (redo)))
- ((yourMove (car Args) (cadr Args)) (display T) (myMove)) ) ) )
+ ((apply yourMove Args) (display T) (myMove)) ) ) )
# Print position to file
(de ppos (File)