Add 2010 to copyright years.
[bpt/emacs.git] / lisp / play / gomoku.el
index e9f7a07..e18d4bd 100644 (file)
@@ -1,7 +1,7 @@
 ;;; gomoku.el --- Gomoku game between you and Emacs
 
 ;; Copyright (C) 1988, 1994, 1996, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Philippe Schnoebelen <phs@lsv.ens-cachan.fr>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; RULES:
 ;;
-;; Gomoku is a game played between two players on a rectangular board. Each
+;; Gomoku is a game played between two players on a rectangular board.  Each
 ;; player, in turn, marks a free square of its choice. The winner is the first
 ;; one to mark five contiguous squares in any direction (horizontally,
 ;; vertically or diagonally).
@@ -153,8 +151,8 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces."
 
   (define-key gomoku-mode-map [remap previous-line] 'gomoku-move-up)
   (define-key gomoku-mode-map [remap next-line] 'gomoku-move-down)
-  (define-key gomoku-mode-map [remap beginning-of-line] 'gomoku-beginning-of-line)
-  (define-key gomoku-mode-map [remap end-of-line] 'gomoku-end-of-line)
+  (define-key gomoku-mode-map [remap move-beginning-of-line] 'gomoku-beginning-of-line)
+  (define-key gomoku-mode-map [remap move-end-of-line] 'gomoku-end-of-line)
   (define-key gomoku-mode-map [remap undo] 'gomoku-human-takes-back)
   (define-key gomoku-mode-map [remap advertised-undo] 'gomoku-human-takes-back))
 
@@ -212,9 +210,9 @@ is non-nil."
 ;;;
 
 ;; The board is a rectangular grid. We code empty squares with 0, X's with 1
-;; and O's with 6. The rectangle is recorded in a one dimensional vector
-;; containing padding squares (coded with -1). These squares allow us to
-;; detect when we are trying to move out of the board. We denote a square by
+;; and O's with 6.  The rectangle is recorded in a one dimensional vector
+;; containing padding squares (coded with -1).  These squares allow us to
+;; detect when we are trying to move out of the board.  We denote a square by
 ;; its (X,Y) coords, or by the INDEX corresponding to them in the vector.  The
 ;; leftmost topmost square has coords (1,1) and index gomoku-board-width + 2.
 ;; Similarly, vectors between squares may be given by two DX, DY coords or by
@@ -230,7 +228,7 @@ is non-nil."
   "Vector recording the actual state of the Gomoku board.")
 
 (defvar gomoku-vector-length nil
-  "Length of gomoku-board vector.")
+  "Length of `gomoku-board' vector.")
 
 (defvar gomoku-draw-limit nil
   ;; This is usually set to 70% of the number of squares.
@@ -250,7 +248,7 @@ is non-nil."
   (/ index (1+ gomoku-board-width)))
 
 (defun gomoku-init-board ()
-  "Create the gomoku-board vector and fill it with initial values."
+  "Create the `gomoku-board' vector and fill it with initial values."
   (setq gomoku-board (make-vector gomoku-vector-length 0))
   ;; Every square is 0 (i.e. empty) except padding squares:
   (let ((i 0) (ii (1- gomoku-vector-length)))
@@ -671,11 +669,11 @@ that DVAL has been added on SQUARE."
      (cond ((< gomoku-number-of-moves 20)
            "This was a REALLY QUICK win.")
           (gomoku-human-refused-draw
-           "I won... Too bad you refused my offer of a draw !")
+           "I won...  Too bad you refused my offer of a draw!")
           (gomoku-human-took-back
-           "I won... Taking moves back will not help you !")
+           "I won...  Taking moves back will not help you!")
           ((not gomoku-emacs-played-first)
-           "I won... Playing first did not help you much !")
+           "I won...  Playing first did not help you much!")
           ((and (zerop gomoku-number-of-human-wins)
                 (zerop gomoku-number-of-draws)
                 (> gomoku-number-of-emacs-wins 1))
@@ -688,7 +686,7 @@ that DVAL has been added on SQUARE."
              (gomoku-human-took-back
               "  I, for one, never take my moves back...")
              (gomoku-emacs-played-first
-              ".. so what ?")
+              ".. so what?")
              ("  Now, let me play first just once."))))
     ((eq result 'human-resigned)
      (setq gomoku-number-of-emacs-wins (1+ gomoku-number-of-emacs-wins))
@@ -732,12 +730,12 @@ that DVAL has been added on SQUARE."
 (defun gomoku (&optional n m)
   "Start a Gomoku game between you and Emacs.
 
-If a game is in progress, this command allow you to resume it.
+If a game is in progress, this command allows you to resume it.
 If optional arguments N and M are given, an N by M board is used.
 If prefix arg is given for N, M is prompted for.
 
 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
+and Emacs marks it with O.  The winner is the first to get five contiguous
 marks horizontally, vertically or in diagonal.
 
 You play by moving the cursor over the square you choose and hitting
@@ -758,7 +756,7 @@ Use \\[describe-mode] for more info."
       (setq gomoku-emacs-is-computing nil)
       (gomoku-terminate-game 'crash-game)
       (sit-for 4)
-      (or (y-or-n-p "Another game ") (error "Chicken !")))
+      (or (y-or-n-p "Another game? ") (error "Chicken!")))
     (switch-to-buffer gomoku-buffer-name)
     (gomoku-mode))
   (cond
@@ -779,14 +777,14 @@ Use \\[describe-mode] for more info."
       (if (and (> m max-height)
               (not (eq m gomoku-saved-board-height))
               ;; Use EQ because SAVED-BOARD-HEIGHT may be nil
-              (not (y-or-n-p (format "Do you really want %d rows " m))))
+              (not (y-or-n-p (format "Do you really want %d rows? " m))))
          (setq m max-height)))
     (message "One moment, please...")
     (gomoku-start-game n m)
-    (if (y-or-n-p "Do you allow me to play first ")
+    (if (y-or-n-p "Do you allow me to play first? ")
        (gomoku-emacs-plays)
        (gomoku-prompt-for-move)))
-   ((y-or-n-p "Shall we continue our game ")
+   ((y-or-n-p "Shall we continue our game? ")
     (gomoku-prompt-for-move))
    (t
     (gomoku-human-resigns))))
@@ -875,9 +873,9 @@ If the game is finished, this command requests for another game."
     (let (square score)
       (setq square (gomoku-point-square))
       (cond ((null square)
-            (error "Your point is not on a square. Retry !"))
+            (error "Your point is not on a square.  Retry!"))
            ((not (zerop (aref gomoku-board square)))
-            (error "Your point is not on a free square. Retry !"))
+            (error "Your point is not on a free square.  Retry!"))
            (t
             (setq score (aref gomoku-score-table square))
             (gomoku-play-move square 1)
@@ -902,7 +900,7 @@ If the game is finished, this command requests for another game."
     (sit-for 4)
     (gomoku-prompt-for-other-game))
    ((zerop gomoku-number-of-human-moves)
-    (message "You have not played yet... Your move ?"))
+    (message "You have not played yet...  Your move?"))
    (t
     (message "One moment, please...")
     ;; It is possible for the user to let Emacs play several consecutive
@@ -923,9 +921,9 @@ If the game is finished, this command requests for another game."
     (gomoku-crash-game))
    ((not gomoku-game-in-progress)
     (message "There is no game in progress"))
-   ((y-or-n-p "You mean, you resign ")
+   ((y-or-n-p "You mean, you resign? ")
     (gomoku-terminate-game 'human-resigned))
-   ((y-or-n-p "You mean, we continue ")
+   ((y-or-n-p "You mean, we continue? ")
     (gomoku-prompt-for-move))
    (t
     (gomoku-terminate-game 'human-resigned)))) ; OK. Accept it
@@ -937,21 +935,22 @@ If the game is finished, this command requests for another game."
 (defun gomoku-prompt-for-move ()
   "Display a message asking for Human's move."
   (message (if (zerop gomoku-number-of-human-moves)
-              "Your move ? (move to a free square and hit X, RET ...)"
-              "Your move ?"))
+              "Your move?  (Move to a free square and hit X, RET ...)"
+              "Your move?"))
   ;; This may seem silly, but if one omits the following line (or a similar
   ;; one), the cursor may very well go to some place where POINT is not.
+  ;; FIXME: this can't be right!!  --Stef
   (save-excursion (set-buffer (other-buffer))))
 
 (defun gomoku-prompt-for-other-game ()
   "Ask for another game, and start it."
-  (if (y-or-n-p "Another game ")
+  (if (y-or-n-p "Another game? ")
       (gomoku gomoku-board-width gomoku-board-height)
-    (error "Chicken !")))
+    (error "Chicken!")))
 
 (defun gomoku-offer-a-draw ()
   "Offer a draw and return t if Human accepted it."
-  (or (y-or-n-p "I offer you a draw. Do you accept it ")
+  (or (y-or-n-p "I offer you a draw.  Do you accept it? ")
       (not (setq gomoku-human-refused-draw t))))
 \f
 ;;;
@@ -991,7 +990,8 @@ If the game is finished, this command requests for another game."
 (defun gomoku-goto-xy (x y)
   "Move point to square at X, Y coords."
   (let ((inhibit-point-motion-hooks t))
-    (goto-line (+ 1 gomoku-y-offset (* gomoku-square-height (1- y)))))
+    (goto-char (point-min))
+    (forward-line (+ gomoku-y-offset (* gomoku-square-height (1- y)))))
   (move-to-column (+ gomoku-x-offset (* gomoku-square-width (1- x)))))
 
 (defun gomoku-plot-square (square value)
@@ -1209,7 +1209,9 @@ 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)
 
-;;; arch-tag: b1b8205e-77fc-4597-b373-3ea2c04311eb
+;; arch-tag: b1b8205e-77fc-4597-b373-3ea2c04311eb
 ;;; gomoku.el ends here