]> code.delx.au - gnu-emacs-elpa/commitdiff
more fixes
authorJohn Wiegley <johnw@newartisans.com>
Thu, 28 Mar 2002 23:20:05 +0000 (23:20 +0000)
committerJohn Wiegley <johnw@newartisans.com>
Thu, 28 Mar 2002 23:20:05 +0000 (23:20 +0000)
chess-display.el
chess-game.el
chess-maint.el
chess-session.el
chess.el

index 0217d88b64cad376109c1e74ce973c40c55fe94a..422940bf61ae68a9555597c7afc52e3b048c7d3d 100644 (file)
@@ -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))))))
 
index 091263f0d4dc2a93c9127248c62bbefe09c3e474..e6b70fa5371bee3bd618d485a254164b1bdcc283 100644 (file)
@@ -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"      . "-")
index e229c50ff4940c0f220123ba7ddc3cd7c5b41682..dc7a8c8137296c9989b813039a3204d2eeaeef73 100644 (file)
@@ -1,4 +1,2 @@
 (require 'cl)
-(defvar chess-modules)
-(defvar chess-current-session)
 (add-to-list 'load-path ".")
index e28222389b94da075b4474b9837b7e4c4274646a..8ddf3c62b0b7c0ce887ce31fd3f2de82e1bc112c 100644 (file)
@@ -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))
index 934b01f14c10f8ddcce9f3b6e6e5d43c414395dc..c00fc6803fc7fde225fd49e3991d8dac324ca4a5 100644 (file)
--- 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)