summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-11 00:12:56 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-11 00:12:56 +0000
commit54ec8abc770314b97bace34ec48a158828d07ab2 (patch)
tree8311536c86e8e1a3d082c64d438c6bfe721bfaa9
parente0688718b619954474cd65b4dfaa1cae0ebd8edb (diff)
*** no comment ***
-rw-r--r--chess-algebraic.el16
-rw-r--r--chess-phalanx.el67
2 files changed, 77 insertions, 6 deletions
diff --git a/chess-algebraic.el b/chess-algebraic.el
index 69cb073..f014a26 100644
--- a/chess-algebraic.el
+++ b/chess-algebraic.el
@@ -40,8 +40,9 @@
(defconst chess-algebraic-regexp
(format (concat "\\("
"O-O\\(-O\\)?\\|"
- "\\(%s?\\(\\([a-h]\\|[1-8]\\)?\\|[a-h][1-8]\\)\\)?"
- "\\([x-]\\)?"
+ "\\(%s?\\)"
+ "\\([a-h]?[1-8]?\\)"
+ "\\([x-]?\\)"
"\\([a-h][1-8]\\)"
"\\(=\\(%s\\)\\)?"
"\\)"
@@ -51,13 +52,16 @@
"A regular expression that matches all possible algebraic moves.
This regexp handles both long and short form.")
+(defconst chess-algebraic-regexp-entire
+ (concat chess-algebraic-regexp "$"))
+
(defun chess-algebraic-to-ply (position move)
"Convert the algebraic notation MOVE for POSITION to a ply."
- (unless (string-match chess-algebraic-regexp move)
+ (unless (string-match chess-algebraic-regexp-entire move)
(error "Cannot parse non-algebraic move notation: %s" move))
(let* ((color (chess-pos-side-to-move position))
- (mate (match-string 10 move))
- (promotion (match-string 9 move))
+ (mate (match-string 9 move))
+ (promotion (match-string 8 move))
(piece (aref move 0))
(changes
(if (eq piece ?O)
@@ -66,7 +70,7 @@ This regexp handles both long and short form.")
(list (chess-rf-to-index rank 4)
(chess-rf-to-index rank (if long 2 6))))
(let ((source (match-string 4 move))
- (target (chess-coord-to-index (match-string 7 move))))
+ (target (chess-coord-to-index (match-string 6 move))))
(if (and source (= (length source) 2))
(list (chess-coord-to-index source) target)
(if (= (length source) 0)
diff --git a/chess-phalanx.el b/chess-phalanx.el
new file mode 100644
index 0000000..417fa41
--- /dev/null
+++ b/chess-phalanx.el
@@ -0,0 +1,67 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; Play against phalanx!
+;;
+;; $Revision$
+
+(require 'chess-engine)
+(require 'chess-fen)
+(require 'chess-algebraic)
+
+(defgroup chess-phalanx nil
+ "The publically available chess engine 'phalanx'."
+ :group 'chess-engine)
+
+(defcustom chess-phalanx-path (executable-find "phalanx")
+ "The path to the phalanx executable."
+ :type 'file
+ :group 'chess-phalanx)
+
+(defvar chess-phalanx-regexp-alist
+ (list
+ (cons (concat "my move is \\(P?\\("
+ chess-algebraic-regexp "\\)\\)\\s-*$")
+ (function
+ (lambda ()
+ (funcall chess-engine-response-handler 'move
+ (chess-engine-convert-algebraic (match-string 2))))))
+ (cons "Illegal move:\\s-*\\(.*\\)"
+ (function
+ (lambda ()
+ (signal 'chess-illegal (match-string 1)))))))
+
+(defun chess-phalanx-handler (event &rest args)
+ (cond
+ ((eq event 'initialize)
+ (let (proc)
+ (message "Starting chess program 'phalanx'...")
+ (unless chess-phalanx-path
+ (error "Cannot find phalanx executable; check `chess-phalanx-path'"))
+ (setq proc (start-process "chess-process" (current-buffer)
+ chess-phalanx-path))
+ (message "Starting chess program 'phalanx'...done")
+ (process-send-string proc "nopost\n")
+ proc))
+
+ ((eq event 'shutdown)
+ (chess-engine-send nil "quit\n"))
+
+ ((eq event 'ready)
+ (and (chess-engine-game nil)
+ (chess-game-set-data (chess-engine-game nil) 'active t)))
+
+ ((eq event 'pass)
+ (chess-engine-send nil "go\n"))
+
+ ((memq event '(abort resign))
+ (chess-engine-send nil "new\n")
+ (and (chess-engine-game nil)
+ (chess-engine-set-start-position nil)))
+
+ ((eq event 'move)
+ (chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
+ "\n")))))
+
+(provide 'chess-phalanx)
+
+;;; chess-phalanx.el ends here