:type 'hook
:group 'gomoku)
+;;;
+;;; CONSTANTS FOR BOARD
+;;;
+
+;; 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).
+
+(defconst gomoku-square-width 4
+ "*Horizontal spacing between squares on the Gomoku board.")
+
+(defconst gomoku-square-height 2
+ "*Vertical spacing between squares on the Gomoku board.")
+
+(defconst gomoku-x-offset 3
+ "*Number of columns between the Gomoku board and the side of the window.")
+
+(defconst gomoku-y-offset 1
+ "*Number of lines between the Gomoku board and the top of the window.")
+
+
(defvar gomoku-mode-map nil
"Local keymap to use in Gomoku mode.")
(defvar gomoku-emacs-won ()
"For making font-lock use the winner's face for the line.")
-(defcustom gomoku-font-lock-O-face
- (if (display-color-p)
- (list (facemenu-get-face 'fg:red) 'bold))
- "*Face to use for Emacs' O."
- :type '(repeat face)
+(defface gomoku-font-lock-O-face
+ '((((class color)) (:foreground "red" :weight bold)))
+ "Face to use for Emacs' O."
:group 'gomoku)
-(defcustom gomoku-font-lock-X-face
- (if (display-color-p)
- (list (facemenu-get-face 'fg:green) 'bold))
- "*Face to use for your X."
- :type '(repeat face)
+(defface gomoku-font-lock-X-face
+ '((((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)
+ '(("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)))
+ 'gomoku-font-lock-O-face
+ 'gomoku-font-lock-X-face)))
"*Font lock rules for Gomoku.")
(put 'gomoku-mode 'front-sticky
(put 'gomoku-mode 'rear-nonsticky '(intangible)))
(put 'gomoku-mode 'intangible 1)
+;; This one is for when they set view-read-only to t: Gomoku cannot
+;; allow View Mode to be activated in its buffer.
+(put 'gomoku-mode 'mode-class 'special)
-(define-derived-mode gomoku-mode nil "Gomoku"
+(defun gomoku-mode ()
"Major mode for playing Gomoku against Emacs.
You and Emacs play in turn by marking a free square. You mark it with X
and Emacs marks it with O. The winner is the first to get five contiguous
\\{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'."
+ (interactive)
+ (setq major-mode 'gomoku-mode
+ mode-name "Gomoku")
(gomoku-display-statistics)
- (set (make-local-variable 'font-lock-defaults)
- '(gomoku-font-lock-keywords t))
- (toggle-read-only t))
+ (use-local-map gomoku-mode-map)
+ (make-local-variable 'font-lock-defaults)
+ (setq font-lock-defaults '(gomoku-font-lock-keywords t))
+ (toggle-read-only t)
+ (run-hooks 'gomoku-mode-hook))
\f
;;;
;;; THE BOARD.
(message "Chicken !")))
(defun gomoku-offer-a-draw ()
- "Offer a draw and return T if Human accepted it."
+ "Offer a draw and return t if Human accepted it."
(or (y-or-n-p "I offer you a draw. Do you accept it ")
(not (setq gomoku-human-refused-draw t))))
\f
;;; DISPLAYING THE BOARD.
;;;
-;; 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).
-
-(defconst gomoku-square-width 4
- "*Horizontal spacing between squares on the Gomoku board.")
-
-(defconst gomoku-square-height 2
- "*Vertical spacing between squares on the Gomoku board.")
-
-(defconst gomoku-x-offset 3
- "*Number of columns between the Gomoku board and the side of the window.")
-
-(defconst gomoku-y-offset 1
- "*Number of lines between the Gomoku board and the top of the window.")
-
-
(defun gomoku-max-width ()
"Largest possible board width for the current window."
(1+ (/ (- (window-width (selected-window))
;; who won. The solution is to scan the board along all four directions.
(defun gomoku-find-filled-qtuple (square value)
- "Return T if SQUARE belongs to a qtuple filled with VALUEs."
+ "Return t if SQUARE belongs to a qtuple filled with VALUEs."
(or (gomoku-check-filled-qtuple square value 1 0)
(gomoku-check-filled-qtuple square value 0 1)
(gomoku-check-filled-qtuple square value 1 1)
(gomoku-check-filled-qtuple square value -1 1)))
(defun gomoku-check-filled-qtuple (square value dx dy)
- "Return T if SQUARE belongs to a qtuple filled with VALUEs along DX, DY."
+ "Return t if SQUARE belongs to a qtuple filled with VALUEs along DX, DY."
(let ((a 0) (b 0)
(left square) (right square)
(depl (gomoku-xy-to-index dx dy)))