]> code.delx.au - gnu-emacs-elpa/blob - chess.el
more fixes
[gnu-emacs-elpa] / chess.el
1 a0 243
2 ;;; chess.el --- Play chess in Emacs
3
4 ;; Copyright (C) 2001 John Wiegley <johnw@gnu.org>
5
6 ;; Emacs Lisp Archive Entry
7 ;; Filename: chess.el
8 ;; Version: 2.0
9 ;; Keywords: games
10 ;; Author: John Wiegley <johnw@gnu.org>
11 ;; Maintainer: John Wiegley <johnw@gnu.org>
12 ;; Description: Play chess in Emacs
13 ;; URL: http://www.gci-net.com/~johnw/Emacs/packages/chess.tar.gz
14 ;; Compatibility: Emacs20, Emacs21, XEmacs21
15
16 ;; This file is not part of GNU Emacs.
17
18 ;; This is free software; you can redistribute it and/or modify it under
19 ;; the terms of the GNU General Public License as published by the Free
20 ;; Software Foundation; either version 2, or (at your option) any later
21 ;; version.
22 ;;
23 ;; This is distributed in the hope that it will be useful, but WITHOUT
24 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 ;; for more details.
27 ;;
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
31 ;; MA 02111-1307, USA.
32
33 ;;; Commentary:
34
35 ;; Welcome to Emacs Chess, a chess playing module for GNU Emacs.
36 ;;
37 ;; This program will not play chess against you; it is not a chess
38 ;; computer. It can use a chess computer, however, to simulate your
39 ;; opponent's moves. This is decided when you choose your opponent.
40 ;; You must, of course, have that chess computer installed. See the
41 ;; top of chess-player.el for more information.
42 ;;
43 ;; To just get a chessboard up, put the following in your .emacs file:
44 ;;
45 ;; (add-to-list 'load-list "<the path to Emacs Chess>")
46 ;;
47 ;; (autoload 'chess "chess" "Play a game of chess" t)
48 ;;
49 ;; Now you can type `M-x chess', and play chess against anyone else in
50 ;; the room with you, without having to install anything more.
51 ;;
52 ;; Once this is working, the next thing to do is to customize
53 ;; `chess-use-modules'. This is a list of functionality modules used
54 ;; by chess.el to provide its functionality. You can enable or
55 ;; disable modules so that Emacs Chess better suites your tastes.
56 ;; Those modules in turn often have configuration variables, and
57 ;; appropriate documentation at the top of the related file.
58 ;;
59 ;; Emacs Chess is designed in a highly modular fashion, using loosely
60 ;; coupled modules that respond to events on the chess board. This
61 ;; makes it very easy for programmers to add their own types of
62 ;; displays, opponents, analysis programs, etc. See the documentation
63 ;; in chess-module.el to learn more.
64 ;;
65 ;; There is no documentation for this program other than what exists
66 ;; in the source files. This is because the source files aim at being
67 ;; self documenting, and as chess is such a simple game, most chess
68 ;; players aren't going to need to know much about this program in
69 ;; particular.
70 ;;
71 ;; However, most people will probably be interested in reading the top
72 ;; of chess-display.el and chess-pgn.el, which describe the user
73 ;; interface commands available in each of those buffer types.
74
75 ;;; Code:
76 (require 'chess-session)
77
78 (require 'chess-pgn)
79
80 (defgroup chess nil
81 "An Emacs chess playing program."
82 :group 'games)
83 (defconst chess-version "2.0a1"
84 (defconst chess-version "2.0a7"
85 "The version of the Emacs chess program.")
86
87 (defcustom chess-default-display (if (display-graphic-p)
88 'chess-images 'chess-ics1)
89 "Default module set to be used when starting a chess session."
90 :type 'sexp
91 :group 'chess)
92
93 (defcustom chess-default-engine 'chess-gnuchess
94 "Default engine to be used when starting a chess session."
95 :type 'sexp
96 :group 'chess)
97
98 (defun chess (&optional arg)
99 "Start a game of chess."
100 (interactive "P")
101 (let ((session (chess-session-create))
102 (perspective t)) ; start out as white always
103 ;; setup `chess-handler' to receive all events first
104 (chess-session-add-listener session 'chess-handler)
105 (chess-session-set-data session 'my-color perspective)
106 ;; unless prefix arg is given, use `chess-default-engine' to play
107 ;; against; otherwise, just create a board for play between two
108 ;; people
109 (unless arg
110 (chess-session-add-listener session chess-default-engine))
111 ;; initialize all of the modules, and setup a new game
112 (chess-session-event session 'initialize)
113 (chess-session-event session 'setup (chess-game-create))
114 ;; create a display object linked to the session, and add it to
115 ;; the event chain; it is via this object that session events will
116 ;; for the most part be generated
117 (chess-session-add-listener session 'chess-display nil
118 (chess-display-create chess-default-display
119 perspective session))))
120
121 (defun chess-handler (session window-config event &rest args)
122 "React to changes on the chess board in a global Emacs way."
123 (cond
124 ((eq event 'initialize)
125 (current-window-configuration))
126
127 ((eq event 'shutdown)
128 (ignore (set-window-configuration window-config)))
129
130 ((eq event 'setup)
131 (ignore (chess-session-set-data session 'current-game (car args))))
132
133 ((eq event 'pass)
134 (ignore
135 (let ((color (not (chess-session-data session 'my-color))))
136 (message "You are now playing %s" (if color "White" "Black"))
137 (chess-session-set-data session 'my-color (not color)))))))
138 (aset chess-puzzle-locations 3 puzzle-engine)))))))
139
140 (provide 'chess)
141
142 ;;; chess.el ends here