]> code.delx.au - gnu-emacs/blobdiff - lisp/play/5x5.el
Merge from emacs-23
[gnu-emacs] / lisp / play / 5x5.el
index f76ad703fe71aeb529dc2bffa25dd0066e759e42..5263cf11bc75636538b7d8ad7c4402ef3d4cd12b 100644 (file)
@@ -1,6 +1,7 @@
 ;;; 5x5.el --- simple little puzzle game
 
-;; Copyright (C) 1999,2000,2005 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Dave Pearson <davep@davep.org>
 ;; Maintainer: Dave Pearson <davep@davep.org>
 
 ;; 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
@@ -20,9 +21,7 @@
 ;; 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:
 
@@ -34,7 +33,7 @@
 ;; o The code for updating the grid needs to be re-done. At the moment it
 ;;   simply re-draws the grid every time a move is made.
 ;;
-;; o Look into tarting up the display with colour. gamegrid.el looks
+;; o Look into tarting up the display with color. gamegrid.el looks
 ;;   interesting, perhaps that is the way to go?
 
 ;;; Thanks:
 (eval-when-compile
   (require 'cl))
 
-;; If customize isn't available just use defvar instead.
-(eval-and-compile
-  (unless (fboundp 'defgroup)
-    (defmacro defgroup  (&rest rest) nil)
-    (defmacro defcustom (symbol init docstring &rest rest)
-      `(defvar ,symbol ,init ,docstring))))
-
 ;; Customize options.
 
 (defgroup 5x5 nil
   :prefix "5x5-")
 
 (defcustom 5x5-grid-size 5
-  "*Size of the playing area."
+  "Size of the playing area."
   :type  'integer
   :group '5x5)
 
 (defcustom 5x5-x-scale 4
-  "*X scaling factor for drawing the grid."
+  "X scaling factor for drawing the grid."
   :type  'integer
   :group '5x5)
 
 (defcustom 5x5-y-scale 3
-  "*Y scaling factor for drawing the grid."
+  "Y scaling factor for drawing the grid."
   :type  'integer
   :group '5x5)
 
 (defcustom 5x5-animate-delay .01
-  "*Delay in seconds when animating a solution crack."
+  "Delay in seconds when animating a solution crack."
   :type  'number
   :group '5x5)
 
 (defcustom 5x5-hassle-me t
-  "*Should 5x5 ask you when you want to do a destructive operation?"
+  "Should 5x5 ask you when you want to do a destructive operation?"
   :type  'boolean
   :group '5x5)
 
 (defcustom 5x5-mode-hook nil
-  "*Hook run on starting 5x5."
+  "Hook run on starting 5x5."
   :type  'hook
   :group '5x5)
 
 (put '5x5-mode 'mode-class 'special)
 
 (defun 5x5-mode ()
-  "A mode for playing `5x5'
+  "A mode for playing `5x5'.
 
 The key bindings for 5x5-mode are:
 
@@ -219,7 +211,8 @@ Quit current game         \\[5x5-quit-game]"
 (defun 5x5-new-game ()
   "Start a new game of `5x5'."
   (interactive)
-  (when (if (interactive-p) (5x5-y-or-n-p "Start a new game? ") t)
+  (when (if (called-interactively-p 'interactive)
+           (5x5-y-or-n-p "Start a new game? ") t)
     (setq 5x5-x-pos (/ 5x5-grid-size 2)
           5x5-y-pos (/ 5x5-grid-size 2)
           5x5-moves 0
@@ -281,7 +274,7 @@ Quit current game         \\[5x5-quit-game]"
   (loop for y from 0 to (1- 5x5-grid-size) sum (5x5-row-value (aref grid y))))
 
 (defun 5x5-draw-grid-end ()
-  "Draw the top/bottom of the grid"
+  "Draw the top/bottom of the grid."
   (insert "+")
   (loop for x from 0 to (1- 5x5-grid-size) do
         (insert "-" (make-string 5x5-x-scale ?-)))
@@ -308,7 +301,8 @@ Quit current game         \\[5x5-quit-game]"
 
 (defun 5x5-position-cursor ()
   "Position the cursor on the grid."
-  (goto-line (+ (* 5x5-y-pos 5x5-y-scale) 2))
+  (goto-char (point-min))
+  (forward-line (1+ (* 5x5-y-pos 5x5-y-scale)))
   (goto-char (+ (point) (* 5x5-x-pos 5x5-x-scale) (+ 5x5-x-pos 1) 1)))
 
 (defun 5x5-made-move ()
@@ -346,7 +340,7 @@ Quit current game         \\[5x5-quit-game]"
 
 ;;;###autoload
 (defun 5x5-crack-xor-mutate ()
-  "Attempt to crack 5x5 by xor the current and best solution.
+  "Attempt to crack 5x5 by xoring the current and best solution.
 Mutate the result."
   (interactive)
   (5x5-crack #'5x5-make-xor-with-mutation))
@@ -357,7 +351,7 @@ Mutate the result."
 
 5x5-crack takes the argument BREEDER which should be a function that takes
 two parameters, the first will be a grid vector array that is the current
-solution and the second will be the best solution so far. The function
+solution and the second will be the best solution so far.  The function
 should return a grid vector array that is the new solution."
 
   (interactive "aBreeder function: ")
@@ -392,7 +386,7 @@ should return a grid vector array that is the new solution."
   (5x5-mutate-solution best))
 
 (defun 5x5-make-xor-with-mutation (current best)
-  "xor current and best solution then mutate the result."
+  "Xor current and best solution then mutate the result."
   (let ((xored (5x5-make-new-grid)))
     (loop for y from 0 to (1- 5x5-grid-size) do
           (loop for x from 0 to (1- 5x5-grid-size) do
@@ -411,8 +405,8 @@ should return a grid vector array that is the new solution."
   solution)
 
 (defun 5x5-play-solution (solution best)
-  "Play a solution on an empty grid. This destroys the current game in
-progress because it is an animated attempt."
+  "Play a solution on an empty grid.  This destroys the current game
+in progress because it is an animated attempt."
   (5x5-new-game)
   (let ((inhibit-quit t))
     (loop for y from 0 to (1- 5x5-grid-size) do
@@ -513,12 +507,14 @@ progress because it is an animated attempt."
   (and (or x y) (not (and x y))))
 
 (defun 5x5-y-or-n-p (prompt)
-  "5x5 wrapper for y-or-n-p which respects the 5x5-hassle-me setting."
+  "5x5 wrapper for `y-or-n-p' which respects the `5x5-hassle-me' setting."
   (if 5x5-hassle-me
       (y-or-n-p prompt)
     t))
 
+(random t)
+
 (provide '5x5)
 
-;;; arch-tag: ec4dabd5-572d-41ea-b48c-ec5ce0d68fa9
+;; arch-tag: ec4dabd5-572d-41ea-b48c-ec5ce0d68fa9
 ;;; 5x5.el ends here