]> code.delx.au - gnu-emacs/blobdiff - lisp/play/gomoku.el
Merge from emacs-24; up to 2012-12-22T19:09:52Z!rgm@gnu.org
[gnu-emacs] / lisp / play / gomoku.el
index f9d5594cd0b170abcdc051edf45378a2907bb87e..f2abc00e3f5143f2c77303d23495687661309444 100644 (file)
@@ -1,6 +1,7 @@
 ;;; gomoku.el --- Gomoku game between you and Emacs
 
-;; Copyright (C) 1988, 1994, 1996, 2001-2011  Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1994, 1996, 2001-2013 Free Software Foundation,
+;; Inc.
 
 ;; Author: Philippe Schnoebelen <phs@lsv.ens-cachan.fr>
 ;; Maintainer: FSF
@@ -89,16 +90,16 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces."
 ;; 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.")
+  "Horizontal spacing between squares on the Gomoku board.")
 
 (defconst gomoku-square-height 2
-  "*Vertical spacing between squares on the Gomoku board.")
+  "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.")
+  "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.")
+  "Number of lines between the Gomoku board and the top of the window.")
 
 
 (defvar gomoku-mode-map
@@ -161,7 +162,7 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces."
 
 (defface gomoku-O
     '((((class color)) (:foreground "red" :weight bold)))
-  "Face to use for Emacs' O."
+  "Face to use for Emacs's O."
   :group 'gomoku)
 
 (defface gomoku-X
@@ -173,7 +174,7 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces."
   '(("O" . 'gomoku-O)
     ("X" . 'gomoku-X)
     ("[-|/\\]" 0 (if gomoku-emacs-won 'gomoku-O 'gomoku-X)))
-  "*Font lock rules for Gomoku.")
+  "Font lock rules for Gomoku.")
 
 (put 'gomoku-mode 'front-sticky
      (put 'gomoku-mode 'rear-nonsticky '(intangible)))
@@ -379,7 +380,7 @@ Other useful commands:\n
                  best-square square
                  score-max   score)
            (aset gomoku-score-table square -1))) ; no: kill it !
-       ;; If score is equally good, choose randomly. But first check freeness:
+       ;; If score is equally good, choose randomly. But first check freedom:
        ((not (zerop (aref gomoku-board square)))
        (aset gomoku-score-table square -1))
        ((zerop (random (setq count (1+ count))))
@@ -1043,27 +1044,29 @@ If the game is finished, this command requests for another game."
       (insert-char ?\n gomoku-square-height))
     (or (eq (char-after 1) ?.)
        (put-text-property 1 2 'point-entered
-                          (lambda (y) (if (bobp) (forward-char)))))
+                          (lambda (_x _y) (if (bobp) (forward-char)))))
     (or intangible
        (put-text-property point (point) 'intangible 2))
     (put-text-property point (point) 'point-entered
-                      (lambda (y) (if (eobp) (backward-char))))
+                      (lambda (_x _y) (if (eobp) (backward-char))))
     (put-text-property (point-min) (point) 'category 'gomoku-mode))
   (gomoku-goto-xy (/ (1+ n) 2) (/ (1+ m) 2)) ; center of the board
   (sit-for 0))                         ; Display NOW
 
 (defun gomoku-display-statistics ()
   "Obnoxiously display some statistics about previous games in mode line."
-  ;; We store this string in the mode-line-process local variable.
-  ;; This is certainly not the cleanest way out ...
-  (setq mode-line-process
-       (format ": Won %d, lost %d%s"
-               gomoku-number-of-human-wins
-               gomoku-number-of-emacs-wins
-               (if (zerop gomoku-number-of-draws)
-                   ""
-                 (format ", drew %d" gomoku-number-of-draws))))
-  (force-mode-line-update))
+  ;; Update mode line only if Gomoku buffer is current (Bug#12771).
+  (when (string-equal (buffer-name) gomoku-buffer-name)
+    ;; We store this string in the mode-line-process local variable.
+    ;; This is certainly not the cleanest way out ...
+    (setq mode-line-process
+         (format ": won %d, lost %d%s"
+                 gomoku-number-of-human-wins
+                 gomoku-number-of-emacs-wins
+                 (if (zerop gomoku-number-of-draws)
+                     ""
+                   (format ", drew %d" gomoku-number-of-draws))))
+    (force-mode-line-update)))
 
 (defun gomoku-switch-to-window ()
   "Find or create the Gomoku buffer, and display it."
@@ -1197,8 +1200,6 @@ If the game is finished, this command requests for another game."
   (move-to-column (+ gomoku-x-offset
                     (* gomoku-square-width (1- gomoku-board-width)))))
 
-(random t)
-
 (provide 'gomoku)
 
 ;;; gomoku.el ends here