annotate lisp/play/5x5.el @ 94330:52fb31c78b25

(isearch-search-string): Avoid string-bytes and aset.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 24 Apr 2008 17:59:51 +0000
parents 1e3a407766b9
children 949bd6ad1ba4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34006
diff changeset
1 ;;; 5x5.el --- simple little puzzle game
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68634
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
79716
54006a859bcc Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78227
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
33906
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
6 ;; Author: Dave Pearson <davep@davep.org>
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
7 ;; Maintainer: Dave Pearson <davep@davep.org>
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; Created: 1998-10-03
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; Keywords: games puzzles
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
78227
527f752989fc Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76953
diff changeset
15 ;; the Free Software Foundation; either version 3, or (at your option)
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; any later version.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62770
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62770
diff changeset
26 ;; Boston, MA 02110-1301, USA.
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; The aim of 5x5 is to fill in all the squares. If you need any more of an
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; explanation you probably shouldn't play the game.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;;; TODO:
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; o The code for updating the grid needs to be re-done. At the moment it
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; simply re-draws the grid every time a move is made.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;;
25160
6f69847b92b7 Undo miscorrected non-typo.
Karl Heuer <kwzh@gnu.org>
parents: 25143
diff changeset
38 ;; o Look into tarting up the display with colour. gamegrid.el looks
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; interesting, perhaps that is the way to go?
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;;; Thanks:
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 ;; Ralf Fassel <ralf@akutech.de> for his help and introduction to writing an
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; emacs mode.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;;
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; Pascal Q. Porcupine <joshagam@cs.nmsu.edu> for inspiring the animated
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 ;; solver.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34006
diff changeset
49 ;;; Code:
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34006
diff changeset
50
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;; Things we need.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 (eval-when-compile
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 (require 'cl))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 ;; Customize options.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 (defgroup 5x5 nil
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 "5x5 - Silly little puzzle game."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 :group 'games
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 :prefix "5x5-")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 (defcustom 5x5-grid-size 5
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 "*Size of the playing area."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 :type 'integer
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 (defcustom 5x5-x-scale 4
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 "*X scaling factor for drawing the grid."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 :type 'integer
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 (defcustom 5x5-y-scale 3
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 "*Y scaling factor for drawing the grid."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75 :type 'integer
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 (defcustom 5x5-animate-delay .01
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79 "*Delay in seconds when animating a solution crack."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 :type 'number
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 (defcustom 5x5-hassle-me t
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 "*Should 5x5 ask you when you want to do a destructive operation?"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 :type 'boolean
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 (defcustom 5x5-mode-hook nil
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 "*Hook run on starting 5x5."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 :type 'hook
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 :group '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 ;; Non-customize variables.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 (defvar 5x5-grid nil
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 "5x5 grid contents.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 (defvar 5x5-x-pos 2
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 "X position of cursor.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (defvar 5x5-y-pos 2
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 "Y position of cursor.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 (defvar 5x5-moves 0
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 "Moves made.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (defvar 5x5-cracking nil
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 "Are we in cracking mode?")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 (defvar 5x5-buffer-name "*5x5*"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 "Name of the 5x5 play buffer.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (defvar 5x5-mode-map nil
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 "Local keymap for the 5x5 game.")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 ;; Keymap.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 (unless 5x5-mode-map
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 (let ((map (make-sparse-keymap)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 (suppress-keymap map t)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 (define-key map "?" #'describe-mode)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 (define-key map "\r" #'5x5-flip-current)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 (define-key map " " #'5x5-flip-current)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 (define-key map [up] #'5x5-up)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 (define-key map [down] #'5x5-down)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 (define-key map [left] #'5x5-left)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 (define-key map [tab] #'5x5-right)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 (define-key map [right] #'5x5-right)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 (define-key map [(control a)] #'5x5-bol)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (define-key map [(control e)] #'5x5-eol)
25164
8e7561d048f5 (5x5-mode-map): Bind C-p, C-n, C-b, C-f.
Karl Heuer <kwzh@gnu.org>
parents: 25160
diff changeset
131 (define-key map [(control p)] #'5x5-up)
8e7561d048f5 (5x5-mode-map): Bind C-p, C-n, C-b, C-f.
Karl Heuer <kwzh@gnu.org>
parents: 25160
diff changeset
132 (define-key map [(control n)] #'5x5-down)
8e7561d048f5 (5x5-mode-map): Bind C-p, C-n, C-b, C-f.
Karl Heuer <kwzh@gnu.org>
parents: 25160
diff changeset
133 (define-key map [(control b)] #'5x5-left)
8e7561d048f5 (5x5-mode-map): Bind C-p, C-n, C-b, C-f.
Karl Heuer <kwzh@gnu.org>
parents: 25160
diff changeset
134 (define-key map [(control f)] #'5x5-right)
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (define-key map [home] #'5x5-bol)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (define-key map [end] #'5x5-eol)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (define-key map [prior] #'5x5-first)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 (define-key map [next] #'5x5-last)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 (define-key map "r" #'5x5-randomize)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 (define-key map [(control c) (control r)] #'5x5-crack-randomly)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 (define-key map [(control c) (control c)] #'5x5-crack-mutating-current)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 (define-key map [(control c) (control b)] #'5x5-crack-mutating-best)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
143 (define-key map [(control c) (control x)] #'5x5-crack-xor-mutate)
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (define-key map "n" #'5x5-new-game)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (define-key map "q" #'5x5-quit-game)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (setq 5x5-mode-map map)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 ;; Menu definition.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (easy-menu-define 5x5-mode-menu 5x5-mode-map "5x5 menu."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 '("5x5"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 ["New game" 5x5-new-game t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 ["Random game" 5x5-randomize t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 ["Quit game" 5x5-quit-game t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 "---"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 ["Crack randomly" 5x5-crack-randomly t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 ["Crack mutating current" 5x5-crack-mutating-current t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 ["Crack mutating best" 5x5-crack-mutating-best t]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 ["Crack with xor mutate" 5x5-crack-xor-mutate t]))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 ;; Gameplay functions.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (put '5x5-mode 'mode-class 'special)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (defun 5x5-mode ()
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
166 "A mode for playing `5x5'.
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 The key bindings for 5x5-mode are:
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 \\{5x5-mode-map}"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (kill-all-local-variables)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 (use-local-map 5x5-mode-map)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (setq major-mode '5x5-mode
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 mode-name "5x5")
62770
93e71f3dcd14 * play/5x5.el (5x5-mode):
Lute Kamstra <lute@gnu.org>
parents: 62249
diff changeset
175 (run-mode-hooks '5x5-mode-hook)
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (setq buffer-read-only t
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 truncate-lines t)
62770
93e71f3dcd14 * play/5x5.el (5x5-mode):
Lute Kamstra <lute@gnu.org>
parents: 62249
diff changeset
178 (buffer-disable-undo))
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 (defun 5x5 (&optional size)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 "Play 5x5.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 The object of 5x5 is very simple, by moving around the grid and flipping
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 squares you must fill the grid.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 5x5 keyboard bindings are:
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 \\<5x5-mode-map>
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
189 Flip \\[5x5-flip-current]
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
190 Move up \\[5x5-up]
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
191 Move down \\[5x5-down]
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
192 Move left \\[5x5-left]
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
193 Move right \\[5x5-right]
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 Start new game \\[5x5-new-game]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 New game with random grid \\[5x5-randomize]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 Random cracker \\[5x5-crack-randomly]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 Mutate current cracker \\[5x5-crack-mutating-current]
25164
8e7561d048f5 (5x5-mode-map): Bind C-p, C-n, C-b, C-f.
Karl Heuer <kwzh@gnu.org>
parents: 25160
diff changeset
198 Mutate best cracker \\[5x5-crack-mutating-best]
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 Mutate xor cracker \\[5x5-crack-xor-mutate]
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 Quit current game \\[5x5-quit-game]"
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (interactive "P")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (setq 5x5-cracking nil)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 (when size
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 (setq 5x5-grid-size size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (switch-to-buffer 5x5-buffer-name)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (if (or (not 5x5-grid) (not (= 5x5-grid-size (length (aref 5x5-grid 0)))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 (5x5-new-game))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 (5x5-draw-grid (list 5x5-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 (5x5-position-cursor)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 (5x5-mode))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 (defun 5x5-new-game ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 "Start a new game of `5x5'."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 (when (if (interactive-p) (5x5-y-or-n-p "Start a new game? ") t)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 (setq 5x5-x-pos (/ 5x5-grid-size 2)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 5x5-y-pos (/ 5x5-grid-size 2)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 5x5-moves 0
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 5x5-grid (5x5-make-move (5x5-make-new-grid) 5x5-y-pos 5x5-x-pos))
57826
26b411f0feaf (5x5-new-game): Set up the buffer even if not interactive.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
221 (5x5-draw-grid (list 5x5-grid))
26b411f0feaf (5x5-new-game): Set up the buffer even if not interactive.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
222 (5x5-position-cursor)))
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 (defun 5x5-quit-game ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 "Quit the current game of `5x5'."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 (kill-buffer 5x5-buffer-name))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 (defun 5x5-make-new-grid ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 "Create and return a new `5x5' grid structure."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 (let ((grid (make-vector 5x5-grid-size nil)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 (aset grid y (make-vector 5x5-grid-size nil)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 (defun 5x5-cell (grid y x)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 "Return the value of the cell in GRID at location X,Y."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 (aref (aref grid y) x))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 (defun 5x5-set-cell (grid y x value)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 "Set the value of cell X,Y in GRID to VALUE."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 (aset (aref grid y) x value))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 (defun 5x5-flip-cell (grid y x)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 "Flip the value of cell X,Y in GRID."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 (5x5-set-cell grid y x (not (5x5-cell grid y x))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 (defun 5x5-copy-grid (grid)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 "Make a new copy of GRID."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250 (let ((copy (5x5-make-new-grid)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253 (5x5-set-cell copy y x (5x5-cell grid y x))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 copy))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 (defun 5x5-make-move (grid row col)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 "Make a move on GRID at row ROW and column COL."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (5x5-flip-cell grid row col)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 (if (> row 0)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 (5x5-flip-cell grid (1- row) col))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 (if (< row (- 5x5-grid-size 1))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262 (5x5-flip-cell grid (1+ row) col))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263 (if (> col 0)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 (5x5-flip-cell grid row (1- col)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265 (if (< col (- 5x5-grid-size 1))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266 (5x5-flip-cell grid row (1+ col)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
267 grid)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
268
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 (defun 5x5-row-value (row)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270 "Get the \"on-value\" for grid row ROW."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 (loop for y from 0 to (1- 5x5-grid-size) sum (if (aref row y) 1 0)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 (defun 5x5-grid-value (grid)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 "Get the \"on-value\" for grid GRID."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275 (loop for y from 0 to (1- 5x5-grid-size) sum (5x5-row-value (aref grid y))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 (defun 5x5-draw-grid-end ()
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
278 "Draw the top/bottom of the grid."
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 (insert "+")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281 (insert "-" (make-string 5x5-x-scale ?-)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 (insert "-+ "))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284 (defun 5x5-draw-grid (grids)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 "Draw the grids GRIDS into the current buffer."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 (let ((buffer-read-only nil))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 (erase-buffer)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288 (loop for grid in grids do (5x5-draw-grid-end))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289 (insert "\n")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
290 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 (loop for lines from 0 to (1- 5x5-y-scale) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 (loop for grid in grids do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 (insert (if (zerop x) "| " " ")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295 (make-string 5x5-x-scale
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296 (if (5x5-cell grid y x) ?# ?.))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297 (insert " | "))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298 (insert "\n")))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
299 (loop for grid in grids do (5x5-draw-grid-end))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300 (insert "\n")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
301 (insert (format "On: %d Moves: %d" (5x5-grid-value (car grids)) 5x5-moves))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
302
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303 (defun 5x5-position-cursor ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 "Position the cursor on the grid."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305 (goto-line (+ (* 5x5-y-pos 5x5-y-scale) 2))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 (goto-char (+ (point) (* 5x5-x-pos 5x5-x-scale) (+ 5x5-x-pos 1) 1)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308 (defun 5x5-made-move ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
309 "Keep track of how many moves have been made."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
310 (incf 5x5-moves))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
311
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
312 (defun 5x5-make-random-grid ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
313 "Make a random grid."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
314 (let ((grid (5x5-make-new-grid)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
315 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317 (if (zerop (random 2))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
318 (5x5-flip-cell grid y x))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319 grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321 ;; Cracker functions.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 (defun 5x5-crack-randomly ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325 "Attempt to crack 5x5 using random solutions."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 (5x5-crack #'5x5-make-random-solution))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330 (defun 5x5-crack-mutating-current ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331 "Attempt to crack 5x5 by mutating the current solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 (5x5-crack #'5x5-make-mutate-current))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 (defun 5x5-crack-mutating-best ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337 "Attempt to crack 5x5 by mutating the best solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 (5x5-crack #'5x5-make-mutate-best))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 (defun 5x5-crack-xor-mutate ()
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
343 "Attempt to crack 5x5 by xoring the current and best solution.
41950
ac3936e792ac (5x5-crack-xor-mutate): Doc fix.
Pavel Janík <Pavel@Janik.cz>
parents: 38425
diff changeset
344 Mutate the result."
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346 (5x5-crack #'5x5-make-xor-with-mutation))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 ;;;###autoload
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349 (defun 5x5-crack (breeder)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 "Attempt to find a solution for 5x5.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 5x5-crack takes the argument BREEDER which should be a function that takes
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 two parameters, the first will be a grid vector array that is the current
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
354 solution and the second will be the best solution so far. The function
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
355 should return a grid vector array that is the new solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357 (interactive "aBreeder function: ")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358 (5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 (setq 5x5-cracking t)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 (let* ((best-solution (5x5-make-random-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 (current-solution best-solution)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 (best-result (5x5-make-new-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 (current-result (5x5-make-new-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 (target (* 5x5-grid-size 5x5-grid-size)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 (while (and (< (5x5-grid-value best-result) target)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 (not (input-pending-p)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 (setq current-result (5x5-play-solution current-solution best-solution))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368 (if (> (5x5-grid-value current-result) (5x5-grid-value best-result))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 (setq best-solution current-solution
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370 best-result current-result))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
371 (setq current-solution (funcall breeder
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372 (5x5-copy-grid current-solution)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 (5x5-copy-grid best-solution)))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 (setq 5x5-cracking nil))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 (defun 5x5-make-random-solution (&rest ignore)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 "Make a random solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 (5x5-make-random-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380 (defun 5x5-make-mutate-current (current best)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 "Mutate the current solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 (5x5-mutate-solution current))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 (defun 5x5-make-mutate-best (current best)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 "Mutate the best solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 (5x5-mutate-solution best))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 (defun 5x5-make-xor-with-mutation (current best)
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
389 "Xor current and best solution then mutate the result."
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 (let ((xored (5x5-make-new-grid)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393 (5x5-set-cell xored y x
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 (5x5-xor (5x5-cell current y x)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 (5x5-cell best y x)))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 (5x5-mutate-solution xored)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398 (defun 5x5-mutate-solution (solution)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 "Randomly flip bits in the solution."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 (loop for y from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 (loop for x from 0 to (1- 5x5-grid-size) do
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 (if (= (random (/ (* 5x5-grid-size 5x5-grid-size) 2))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 (/ (/ (* 5x5-grid-size 5x5-grid-size) 2) 2))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404 (5x5-flip-cell solution y x))))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 solution)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 (defun 5x5-play-solution (solution best)
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
408 "Play a solution on an empty grid. This destroys the current game
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
409 in progress because it is an animated attempt."
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 (5x5-new-game)
33906
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
411 (let ((inhibit-quit t))
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
412 (loop for y from 0 to (1- 5x5-grid-size) do
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
413 (loop for x from 0 to (1- 5x5-grid-size) do
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
414 (setq 5x5-y-pos y
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
415 5x5-x-pos x)
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
416 (if (5x5-cell solution y x)
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
417 (5x5-flip-current))
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
418 (5x5-draw-grid (list 5x5-grid solution best))
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
419 (5x5-position-cursor)
844457f780a5 Update from author.
Gerd Moellmann <gerd@gnu.org>
parents: 25164
diff changeset
420 (sit-for 5x5-animate-delay))))
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421 5x5-grid)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
422
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 ;; Keyboard response functions.
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425 (defun 5x5-flip-current ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 "Make a move on the current cursor location."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 (setq 5x5-grid (5x5-make-move 5x5-grid 5x5-y-pos 5x5-x-pos))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429 (5x5-made-move)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 (unless 5x5-cracking
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431 (5x5-draw-grid (list 5x5-grid)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 (5x5-position-cursor)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433 (when (= (5x5-grid-value 5x5-grid) (* 5x5-grid-size 5x5-grid-size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 (beep)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 (message "You win!")))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 (defun 5x5-up ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 "Move up."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 (unless (zerop 5x5-y-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 (decf 5x5-y-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442 (5x5-position-cursor)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 (defun 5x5-down ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 "Move down."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447 (unless (= 5x5-y-pos (1- 5x5-grid-size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 (incf 5x5-y-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 (5x5-position-cursor)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 (defun 5x5-left ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 "Move left."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454 (unless (zerop 5x5-x-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 (decf 5x5-x-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456 (5x5-position-cursor)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 (defun 5x5-right ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459 "Move right."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461 (unless (= 5x5-x-pos (1- 5x5-grid-size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 (incf 5x5-x-pos)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463 (5x5-position-cursor)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465 (defun 5x5-bol ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466 "Move to beginning of line."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 (setq 5x5-x-pos 0)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 (5x5-position-cursor))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 (defun 5x5-eol ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 "Move to end of line."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (setq 5x5-x-pos (1- 5x5-grid-size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 (5x5-position-cursor))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (defun 5x5-first ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 "Move to the first cell."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 (setq 5x5-x-pos 0
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 5x5-y-pos 0)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482 (5x5-position-cursor))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 (defun 5x5-last ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 "Move to the last cell."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 (setq 5x5-x-pos (1- 5x5-grid-size)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488 5x5-y-pos (1- 5x5-grid-size))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489 (5x5-position-cursor))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491 (defun 5x5-randomize ()
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492 "Randomize the grid."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
493 (interactive)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 (when (5x5-y-or-n-p "Start a new game with a random grid? ")
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
495 (setq 5x5-x-pos (/ 5x5-grid-size 2)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
496 5x5-y-pos (/ 5x5-grid-size 2)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
497 5x5-moves 0
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498 5x5-grid (5x5-make-random-grid))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 (unless 5x5-cracking
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 (5x5-draw-grid (list 5x5-grid)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
501 (5x5-position-cursor)))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
502
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
503 ;; Support functions
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
504
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
505 (defun 5x5-xor (x y)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
506 "Boolean exclusive-or of X and Y."
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
507 (and (or x y) (not (and x y))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 41950
diff changeset
508
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 (defun 5x5-y-or-n-p (prompt)
75916
1cea4c7de5cf (5x5-crack-xor-mutate): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
510 "5x5 wrapper for `y-or-n-p' which respects the `5x5-hassle-me' setting."
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
511 (if 5x5-hassle-me
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512 (y-or-n-p prompt)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 t))
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514
76953
417f62c55294 Seed RNG on loading.
Glenn Morris <rgm@gnu.org>
parents: 75916
diff changeset
515 (random t)
417f62c55294 Seed RNG on loading.
Glenn Morris <rgm@gnu.org>
parents: 75916
diff changeset
516
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 (provide '5x5)
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
519 ;; arch-tag: ec4dabd5-572d-41ea-b48c-ec5ce0d68fa9
25143
5decc043e9bf Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 ;;; 5x5.el ends here