summaryrefslogtreecommitdiff
path: root/chess-gnuchess.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-07 08:44:00 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-07 08:44:00 +0000
commit2ef00c4beddb77e546cdc212cc502c5a9a4bba6c (patch)
treef20a250ce3e162fd5580696528d7b8251cdcfcf4 /chess-gnuchess.el
parentb148d84be1c3bd781c4fd11dd0a928fbeeda28fd (diff)
Simplified the event model, and removed session objects. Now
everything just revolves around a game. Gnuchess is now playable to the end, except don't make moves that leave your king in check! The engine still doesn't check for this yet.
Diffstat (limited to 'chess-gnuchess.el')
-rw-r--r--chess-gnuchess.el25
1 files changed, 18 insertions, 7 deletions
diff --git a/chess-gnuchess.el b/chess-gnuchess.el
index 09fe89e..1f0e68b 100644
--- a/chess-gnuchess.el
+++ b/chess-gnuchess.el
@@ -8,13 +8,19 @@
(require 'chess-fen)
(require 'chess-algebraic)
+(defvar chess-gnuchess-now-moving nil)
+
(defvar chess-gnuchess-regexp-alist
(list (cons (concat "My move is : \\(" chess-algebraic-regexp "\\)")
(function
(lambda ()
- (funcall chess-engine-response-handler 'move
- (chess-algebraic-to-ply (chess-engine-position nil)
- (match-string 1))))))
+ (let* ((move (match-string 1))
+ (ply (chess-algebraic-to-ply
+ (chess-engine-position nil) move)))
+ (unless ply
+ (error "Could not convert engine move: %s" move))
+ (let ((chess-gnuchess-now-moving t))
+ (funcall chess-engine-response-handler 'move ply))))))
(cons "Illegal move:"
(function
(lambda ()
@@ -29,18 +35,23 @@
(executable-find "gnuchess")))
(message "Starting chess program 'gnuchess'...done")
proc))
+
((eq event 'shutdown)
(chess-engine-send nil "quit\n"))
+
((eq event 'setup)
(chess-engine-send nil (format "setboard %s\n"
(chess-pos-to-fen (car args)))))
+
((eq event 'pass)
(chess-engine-send nil "go\n"))
+
((eq event 'move)
- (chess-engine-send
- nil (concat (chess-ply-to-algebraic
- (car args) nil
- (chess-engine-search-function nil)) "\n")))))
+ (unless chess-gnuchess-now-moving
+ (chess-engine-send nil (concat (chess-ply-to-algebraic
+ (car args) nil
+ (chess-engine-search-function nil))
+ "\n"))))))
(provide 'chess-gnuchess)