;; Version: 2.0
;; Keywords: games
;; Author: John Wiegley <johnw@gnu.org>
-;; Maintainer: John Wiegley <johnw@gnu.org>
+;; Maintainer: Mario Lang <mlang@delysid.org>
;; Description: Play chess in Emacs
-;; URL: http://www.gci-net.com/~johnw/Emacs/packages/chess.tar.gz
-;; Compatibility: Emacs20, Emacs21, XEmacs21
+;; URL: http://emacs-chess.sourceforge.net/
+;; Compatibility: Emacs21
;; This file is not part of GNU Emacs.
;;
;; To just get a chessboard up, put the following in your .emacs file:
;;
-;; (add-to-list 'load-list "<the path to Emacs Chess>")
+;; (add-to-list 'load-path "<the path to Emacs Chess>")
;;
;; (autoload 'chess "chess" "Play a game of chess" t)
;;
(require 'chess-game)
(require 'chess-display)
(require 'chess-engine)
-(require 'chess-random)
-(require 'chess-database)
-(require 'chess-file)
(defgroup chess nil
"An Emacs chess playing program."
:group 'games)
-(defconst chess-version "2.0a12"
+(defconst chess-version "2.0b6"
"The version of the Emacs chess program.")
(defcustom chess-default-display
(defcustom chess-default-modules
'((chess-sound chess-announce)
- chess-autosave)
+ chess-autosave
+ chess-clock
+ ;;chess-kibitz jww (2002-04-30): not fully supported yet
+ ;;chess-chat
+ )
"Modules to be used when starting a chess session.
A sublist indicates a series of alternatives, if the first is not
available.
:group 'chess)
(defcustom chess-default-engine
- '(chess-crafty chess-gnuchess chess-phalanx)
+ '(chess-crafty
+ chess-stockfish chess-glaurung chess-fruit
+ chess-gnuchess chess-phalanx
+ chess-ai)
"Default engine to be used when starting a chess session.
A list indicates a series of alternatives if the first engine is not
available."
:type 'string
:group 'chess)
+(and (fboundp 'font-lock-add-keywords)
+ (font-lock-add-keywords
+ 'emacs-lisp-mode
+ '(("(\\(chess-error\\)\\>" 1 font-lock-warning-face)
+ ("(\\(chess-with-current-buffer\\)\\>" 1 font-lock-keyword-face))))
+
(defun chess--create-display (module game my-color disable-popup)
- (when (require module nil t)
- (let ((display (chess-display-create game module my-color)))
- (when display
- (chess-game-set-data game 'my-color my-color)
- (if disable-popup
- (chess-display-disable-popup display))
- display))))
+ (let ((display (chess-display-create game module my-color)))
+ (when display
+ (chess-game-set-data game 'my-color my-color)
+ (if disable-popup
+ (chess-display-disable-popup display))
+ display)))
(defun chess--create-engine (module game response-handler ctor-args)
(let ((engine (apply 'chess-engine-create module game
engine)))
(defun chess-create-modules (module-list create-func &rest args)
+ "Create modules from MODULE-LIST with CREATE-FUNC and ARGS.
+If an element of MODULE-LIST is a sublist, treat it as alternatives."
(let (objects)
(dolist (module module-list)
(let (object)
;; this module is actually a list, which means keep trying
;; until we find one that works
(while module
- (if (setq object (apply create-func (car module) args))
+ (if (setq object (condition-case nil
+ (apply create-func (car module) args)
+ (error nil)))
(progn
(push object objects)
(setq module nil))
(nreverse objects)))
(chess-message-catalog 'english
- '((no-engines-found . "Could not find any chess engines to play against; install gnuchess!")))
+ '((no-engines-found
+ . "Could not find any chess engines to play against; install gnuchess!")))
;;;###autoload
(defun chess (&optional engine disable-popup engine-response-handler
&rest engine-ctor-args)
- "Start a game of chess, playing against ENGINE (a module name)."
+ "Start a game of chess, playing against ENGINE (a module name).
+With prefix argument, prompt for the engine to play against.
+Otherwise use `chess-default-engine' to determine the engine."
(interactive
(list
(if current-prefix-arg
(when (car objects)
(mapc 'chess-display-update objects)
(chess-module-set-leader (car objects))
- (chess-display-popup (car objects)))
+ (unless disable-popup
+ (chess-display-popup (car objects))))
(nconc objects (chess-create-modules chess-default-modules
'chess-module-create game))
- (push (car (chess-create-modules (list (or engine chess-default-engine))
- 'chess--create-engine game
- engine-response-handler
- engine-ctor-args))
+ (push (unless (eq engine 'none)
+ (car ;(condition-case nil
+ (chess-create-modules (list (or engine chess-default-engine))
+ 'chess--create-engine game
+ engine-response-handler
+ engine-ctor-args)
+ ; (error nil))
+ ))
objects)
(unless (car objects)
(defalias 'chess-session 'chess)
;;;###autoload
-(defun chess-create-display ()
- "Just make a display to use, letting chess.el decide the style."
- (cadr (chess-session 'chess-none)))
-
-;;;###autoload
-(defun chess-create-display-object (perspective)
- (car (chess-create-modules (list chess-default-display)
- 'chess--create-display
- (chess-game-create) perspective nil)))
-
-;;;###autoload
-(defun chess-read-pgn (&optional file)
- "Read and display a PGN game after point."
- (interactive "P")
- (if (or file (not (search-forward "[Event " nil t)))
- (setq file (read-file-name "Read a PGN game from file: ")))
- (if file
- (find-file file))
- (let ((game (chess-pgn-to-game))
- display)
- (when game
- (setq display (chess-create-display))
- (chess-display-set-game display game))))
-
-(defvar chess-puzzle-indices nil)
-(defvar chess-puzzle-position nil)
-(make-variable-buffer-local 'chess-puzzle-indices)
-(make-variable-buffer-local 'chess-puzzle-position)
-
-;;;###autoload
-(defun chess-puzzle (file &optional index)
- "Pick a random puzzle from FILE, and solve it against the default engine.
-The spacebar in the display buffer is bound to `chess-puzzle-next',
-making it easy to go on to the next puzzle once you've solved one."
- (interactive "fRead chess puzzles from: ")
- (let* ((database (chess-database-open 'chess-file file))
- (objects (and database (chess-session)))
- (display (cadr objects)))
- (when database
- (with-current-buffer display
- ;; make sure the database is closed when the display is shutdown
- (chess-game-add-hook (chess-display-game nil)
- 'chess-database-event-handler database)
- (chess-game-set-data (chess-display-game nil) 'database database)
- (define-key (current-local-map) [? ] 'chess-puzzle-next)
- (let ((count (chess-database-count database)))
- (setq chess-puzzle-indices (make-vector count nil))
- (dotimes (i count)
- (aset chess-puzzle-indices i i))
- (random t)
- (shuffle-vector chess-puzzle-indices)
- (setq chess-puzzle-position 0))
- (chess-puzzle-next)))))
-
-(chess-message-catalog 'english
- '((bad-game-read . "Error reading game at position %d")
- (end-of-puzzles . "There are no more puzzles in this collection")))
-
-(defun chess-puzzle-next ()
- "Play the next puzzle in the collection, selected randomly."
- (interactive)
- (let* ((game (chess-display-game nil))
- (database (chess-game-data game 'database))
- (index chess-puzzle-position)
- next-game)
- (if (= index (length chess-puzzle-indices))
- (chess-message 'end-of-puzzles)
- (setq chess-puzzle-position (1+ chess-puzzle-position))
- (if (null (setq next-game
- (chess-database-read database
- (aref chess-puzzle-indices index))))
- (chess-error 'bag-game-read
- (aref chess-puzzle-indices index))
- (chess-display-set-game nil next-game 0)
- (chess-game-set-data game 'my-color
- (chess-pos-side-to-move (chess-game-pos game)))
- (dolist (key '(database database-index database-count))
- (chess-game-set-data game key (chess-game-data next-game key)))))))
+(defun chess-create-display (perspective &optional modules-too)
+ "Create a display, letting the user's customization decide the style.
+If MODULES-TOO is non-nil, also create and associate the modules
+listed in `chess-default-modules'."
+ (if modules-too
+ (let ((display (cadr (chess-session 'none))))
+ (chess-display-set-perspective* display perspective))
+ (car (chess-create-modules (list chess-default-display)
+ 'chess--create-display
+ (chess-game-create) perspective nil))))
(provide 'chess)