;;; gomoku.el --- Gomoku game between you and Emacs
-;; Copyright (C) 1988, 1994, 1996, 2001, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1994, 1996, 2001, 2002, 2003, 2004,
+;; 2005 Free Software Foundation, Inc.
;; Author: Philippe Schnoebelen <phs@lsv.ens-cachan.fr>
;; Maintainer: FSF
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; CONSTANTS FOR BOARD
;;;
+(defconst gomoku-buffer-name "*Gomoku*"
+ "Name of the Gomoku buffer.")
+
;; You may change these values if you have a small screen or if the squares
;; look rectangular, but spacings SHOULD be at least 2 (MUST BE at least 1).
(defvar gomoku-emacs-won ()
"For making font-lock use the winner's face for the line.")
-(defface gomoku-font-lock-O-face
+(defface gomoku-O
'((((class color)) (:foreground "red" :weight bold)))
"Face to use for Emacs' O."
:group 'gomoku)
-(defface gomoku-font-lock-X-face
+(defface gomoku-X
'((((class color)) (:foreground "green" :weight bold)))
"Face to use for your X."
:group 'gomoku)
(defvar gomoku-font-lock-keywords
- '(("O" . 'gomoku-font-lock-O-face)
- ("X" . 'gomoku-font-lock-X-face)
- ("[-|/\\]" 0 (if gomoku-emacs-won
- 'gomoku-font-lock-O-face
- 'gomoku-font-lock-X-face)))
+ '(("O" . 'gomoku-O)
+ ("X" . 'gomoku-X)
+ ("[-|/\\]" 0 (if gomoku-emacs-won 'gomoku-O 'gomoku-X)))
"*Font lock rules for Gomoku.")
(put 'gomoku-mode 'front-sticky
Other useful commands:
\\{gomoku-mode-map}
Entry to this mode calls the value of `gomoku-mode-hook' if that value
-is non-nil. One interesting value is `turn-on-font-lock'."
+is non-nil."
(interactive)
+ (kill-all-local-variables)
(setq major-mode 'gomoku-mode
mode-name "Gomoku")
(gomoku-display-statistics)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults '(gomoku-font-lock-keywords t))
(toggle-read-only t)
- (run-hooks 'gomoku-mode-hook))
+ (run-mode-hooks 'gomoku-mode-hook))
\f
;;;
;;; THE BOARD.
(interactive (if current-prefix-arg
(list (prefix-numeric-value current-prefix-arg)
(eval (read-minibuffer "Height: ")))))
- (gomoku-switch-to-window)
+ ;; gomoku-switch-to-window, but without the potential call to gomoku
+ ;; from gomoku-prompt-for-other-game.
+ (if (get-buffer gomoku-buffer-name)
+ (switch-to-buffer gomoku-buffer-name)
+ (when gomoku-game-in-progress
+ (setq gomoku-emacs-is-computing nil)
+ (gomoku-terminate-game 'crash-game)
+ (sit-for 4)
+ (or (y-or-n-p "Another game ") (error "Chicken !")))
+ (switch-to-buffer gomoku-buffer-name)
+ (gomoku-mode))
(cond
(gomoku-emacs-is-computing
(gomoku-crash-game))
"Ask for another game, and start it."
(if (y-or-n-p "Another game ")
(gomoku gomoku-board-width gomoku-board-height)
- (message "Chicken !")))
+ (error "Chicken !")))
(defun gomoku-offer-a-draw ()
"Offer a draw and return t if Human accepted it."
(defun gomoku-switch-to-window ()
"Find or create the Gomoku buffer, and display it."
(interactive)
- (let ((buff (get-buffer "*Gomoku*")))
- (if buff ; Buffer exists:
- (switch-to-buffer buff) ; no problem.
- (if gomoku-game-in-progress
- (gomoku-crash-game)) ; buffer has been killed or something
- (switch-to-buffer "*Gomoku*") ; Anyway, start anew.
- (gomoku-mode))))
+ (if (get-buffer gomoku-buffer-name) ; Buffer exists:
+ (switch-to-buffer gomoku-buffer-name) ; no problem.
+ (if gomoku-game-in-progress
+ (gomoku-crash-game)) ; buffer has been killed or something
+ (switch-to-buffer gomoku-buffer-name) ; Anyway, start anew.
+ (gomoku-mode)))
\f
;;;
;;; CROSSING WINNING QTUPLES.
(provide 'gomoku)
+;;; arch-tag: b1b8205e-77fc-4597-b373-3ea2c04311eb
;;; gomoku.el ends here