summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chess-display.el8
-rw-r--r--chess-game.el3
-rw-r--r--chess-maint.el2
-rw-r--r--chess-session.el6
-rw-r--r--chess.el61
5 files changed, 48 insertions, 32 deletions
diff --git a/chess-display.el b/chess-display.el
index 0217d88..422940b 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -265,6 +265,8 @@ If only START is given, it must be in algebraic move notation."
start target))))
(cond
((chess-display-active-p)
+ ;; make the move and then announce it
+ (chess-game-move chess-display-game ply)
(chess-session-event chess-display-session 'move ply))
(chess-display-game
;; jww (2002-03-28): This should beget a variation, or alter
@@ -315,11 +317,15 @@ See `chess-display-type' for the different kinds of displays."
(chess-display-set-game display (car args)))
((eq event 'highlight)
- ;; calling `chess-display-highlight' would be recursive
+ ;; calling `chess-display-highlight' here would be recursive
(if chess-display-highlight-function
(funcall chess-display-highlight-function
(car args) (cadr args))))
+ ((eq event 'pass)
+ (chess-display-set-perspective
+ display (not (chess-display-perspective display))))
+
(t
(chess-display-update display))))))
diff --git a/chess-game.el b/chess-game.el
index 091263f..e6b70fa 100644
--- a/chess-game.el
+++ b/chess-game.el
@@ -12,6 +12,9 @@
(require 'chess-ply)
(require 'chess-algebraic)
+(defvar chess-illegal nil)
+(put 'chess-illegal 'error-conditions '(error))
+
(defconst chess-game-default-tags
`(("Event" . "Computer chess game")
("Round" . "-")
diff --git a/chess-maint.el b/chess-maint.el
index e229c50..dc7a8c8 100644
--- a/chess-maint.el
+++ b/chess-maint.el
@@ -1,4 +1,2 @@
(require 'cl)
-(defvar chess-modules)
-(defvar chess-current-session)
(add-to-list 'load-path ".")
diff --git a/chess-session.el b/chess-session.el
index e282223..8ddf3c6 100644
--- a/chess-session.el
+++ b/chess-session.el
@@ -9,11 +9,11 @@
(defun chess-session-create ()
(cons nil nil))
-(defun chess-session-add-listener (session listener &optional front)
+(defun chess-session-add-listener (session listener &optional front object)
(if (or front (not (cdr session)))
- (setcdr session (cons (cons listener nil)
+ (setcdr session (cons (cons listener object)
(cdr session)))
- (nconc session (list (cons listener nil)))))
+ (nconc session (list (cons listener object)))))
(defun chess-session-remove-listener (session listener)
(setcdr session (delq (assq listener (cdr session))
diff --git a/chess.el b/chess.el
index 934b01f..c00fc68 100644
--- a/chess.el
+++ b/chess.el
@@ -83,49 +83,58 @@ a0 243
(defconst chess-version "2.0a1"
(defconst chess-version "2.0a7"
"The version of the Emacs chess program.")
-(defcustom chess-modules
- (list 'chess-crafty
- (if (display-graphic-p)
- 'chess-images 'chess-ascii))
+
+ 'chess-images 'chess-ascii)
'chess-images 'chess-ics1)
- :type (list 'radio (apropos-internal "\\`chess-[^-]+\\'" 'functionp))
+ "Default module set to be used when starting a chess session."
:type 'sexp
:group 'chess)
-(defvar chess-current-session nil)
-
-(defvar chess-illegal nil)
-(put 'chess-illegal 'error-conditions '(error))
+(defcustom chess-default-engine 'chess-crafty
+(defcustom chess-default-engine 'chess-gnuchess
+ "Default engine to be used when starting a chess session."
+ :type 'sexp
:group 'chess)
-(defun chess ()
+(defun chess (&optional arg)
"Start a game of chess."
- (interactive)
- (setq chess-current-session (chess-session-create))
- (chess-session-add-listener chess-current-session 'chess-global-handler)
- (dolist (module chess-modules)
- (require module)
- (chess-session-add-listener chess-current-session module))
- (chess-session-event chess-current-session 'initialize)
- (chess-session-event chess-current-session 'setup (chess-game-create)))
-
-(defun chess-global-handler (session window-config event &rest args)
+ (interactive "P")
+ (let ((session (chess-session-create))
+ (perspective t)) ; start out as white always
+ ;; setup `chess-handler' to receive all events first
+ (chess-session-add-listener session 'chess-handler)
+ (chess-session-set-data session 'my-color perspective)
+ ;; unless prefix arg is given, use `chess-default-engine' to play
+ ;; against; otherwise, just create a board for play between two
+ ;; people
+ (unless arg
+ (chess-session-add-listener session chess-default-engine))
+ ;; initialize all of the modules, and setup a new game
+ (chess-session-event session 'initialize)
+ (chess-session-event session 'setup (chess-game-create))
+ ;; create a display object linked to the session, and add it to
+ ;; the event chain; it is via this object that session events will
+ ;; for the most part be generated
+ (chess-session-add-listener session 'chess-display nil
+ (chess-display-create chess-default-display
+ perspective session))))
+
+(defun chess-handler (session window-config event &rest args)
"React to changes on the chess board in a global Emacs way."
(cond
((eq event 'initialize)
- (chess-session-set-data session 'my-color t) ; start out white
(current-window-configuration))
+
((eq event 'shutdown)
(ignore (set-window-configuration window-config)))
+
((eq event 'setup)
(ignore (chess-session-set-data session 'current-game (car args))))
+
((eq event 'pass)
(ignore
(let ((color (not (chess-session-data session 'my-color))))
- (message "You are now playing %s"
- (if color "White" "Black"))
- (chess-session-set-data session 'my-color
- (not (chess-session-data session
- 'my-color))))))))
+ (message "You are now playing %s" (if color "White" "Black"))
+ (chess-session-set-data session 'my-color (not color)))))))
(aset chess-puzzle-locations 3 puzzle-engine)))))))
(provide 'chess)