diff options
| author | Vincent Belaïche | 2011-06-20 23:16:02 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2011-06-20 23:16:02 -0400 |
| commit | 7cf3f55609dbddcf420f789ece79b190a0ed35a8 (patch) | |
| tree | 36e0fe9fbe9ae92aefebe7c379a96a14ca0b4fab | |
| parent | 60a406cf162e7bfd7f32c44db12747164baaf923 (diff) | |
| download | emacs-7cf3f55609dbddcf420f789ece79b190a0ed35a8.tar.gz emacs-7cf3f55609dbddcf420f789ece79b190a0ed35a8.zip | |
* lisp/play/5x5.el (5x5-solve-rotate-left, 5x5-solve-rotate-right): New funs.
(5x5-mode-map, 5x5-mode-menu): Bind them.
(5x5-draw-grid): Tweak the solver's rendering.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/play/5x5.el | 97 |
2 files changed, 91 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 66fa971f721..90f67e4e12d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2011-06-21 Vincent Belaïche <vincent.b.1@hotmail.fr> | ||
| 2 | |||
| 3 | * play/5x5.el (5x5-solve-rotate-left, 5x5-solve-rotate-right): | ||
| 4 | New functions. | ||
| 5 | (5x5-mode-map, 5x5-mode-menu): Bind them. | ||
| 6 | (5x5-draw-grid): Tweak the solver's rendering. | ||
| 7 | |||
| 1 | 2011-06-21 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2011-06-21 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * progmodes/compile.el (compilation-error-regexp-alist-alist): Rename | 10 | * progmodes/compile.el (compilation-error-regexp-alist-alist): Rename |
diff --git a/lisp/play/5x5.el b/lisp/play/5x5.el index 5a8ff9d0f32..86e6b4abb6c 100644 --- a/lisp/play/5x5.el +++ b/lisp/play/5x5.el | |||
| @@ -144,6 +144,8 @@ | |||
| 144 | (define-key map [(control c) (control x)] #'5x5-crack-xor-mutate) | 144 | (define-key map [(control c) (control x)] #'5x5-crack-xor-mutate) |
| 145 | (define-key map "n" #'5x5-new-game) | 145 | (define-key map "n" #'5x5-new-game) |
| 146 | (define-key map "s" #'5x5-solve-suggest) | 146 | (define-key map "s" #'5x5-solve-suggest) |
| 147 | (define-key map "<" #'5x5-solve-rotate-left) | ||
| 148 | (define-key map ">" #'5x5-solve-rotate-right) | ||
| 147 | (define-key map "q" #'5x5-quit-game) | 149 | (define-key map "q" #'5x5-quit-game) |
| 148 | map) | 150 | map) |
| 149 | "Local keymap for the 5x5 game.") | 151 | "Local keymap for the 5x5 game.") |
| @@ -174,6 +176,9 @@ GRID is the grid of positions to click.") | |||
| 174 | ["Quit game" 5x5-quit-game t] | 176 | ["Quit game" 5x5-quit-game t] |
| 175 | "---" | 177 | "---" |
| 176 | ["Use Calc solver" 5x5-solve-suggest t] | 178 | ["Use Calc solver" 5x5-solve-suggest t] |
| 179 | ["Rotate left list of Calc solutions" 5x5-solve-rotate-left t] | ||
| 180 | ["Rotate right list of Calc solutions" 5x5-solve-rotate-right t] | ||
| 181 | "---" | ||
| 177 | ["Crack randomly" 5x5-crack-randomly t] | 182 | ["Crack randomly" 5x5-crack-randomly t] |
| 178 | ["Crack mutating current" 5x5-crack-mutating-current t] | 183 | ["Crack mutating current" 5x5-crack-mutating-current t] |
| 179 | ["Crack mutating best" 5x5-crack-mutating-best t] | 184 | ["Crack mutating best" 5x5-crack-mutating-best t] |
| @@ -207,18 +212,21 @@ squares you must fill the grid. | |||
| 207 | 212 | ||
| 208 | 5x5 keyboard bindings are: | 213 | 5x5 keyboard bindings are: |
| 209 | \\<5x5-mode-map> | 214 | \\<5x5-mode-map> |
| 210 | Flip \\[5x5-flip-current] | 215 | Flip \\[5x5-flip-current] |
| 211 | Move up \\[5x5-up] | 216 | Move up \\[5x5-up] |
| 212 | Move down \\[5x5-down] | 217 | Move down \\[5x5-down] |
| 213 | Move left \\[5x5-left] | 218 | Move left \\[5x5-left] |
| 214 | Move right \\[5x5-right] | 219 | Move right \\[5x5-right] |
| 215 | Start new game \\[5x5-new-game] | 220 | Start new game \\[5x5-new-game] |
| 216 | New game with random grid \\[5x5-randomize] | 221 | New game with random grid \\[5x5-randomize] |
| 217 | Random cracker \\[5x5-crack-randomly] | 222 | Random cracker \\[5x5-crack-randomly] |
| 218 | Mutate current cracker \\[5x5-crack-mutating-current] | 223 | Mutate current cracker \\[5x5-crack-mutating-current] |
| 219 | Mutate best cracker \\[5x5-crack-mutating-best] | 224 | Mutate best cracker \\[5x5-crack-mutating-best] |
| 220 | Mutate xor cracker \\[5x5-crack-xor-mutate] | 225 | Mutate xor cracker \\[5x5-crack-xor-mutate] |
| 221 | Quit current game \\[5x5-quit-game]" | 226 | Solve with Calc \\[5x5-solve-suggest] |
| 227 | Rotate left Calc Solutions \\[5x5-solve-rotate-left] | ||
| 228 | Rotate right Calc Solutions \\[5x5-solve-rotate-right] | ||
| 229 | Quit current game \\[5x5-quit-game]" | ||
| 222 | 230 | ||
| 223 | (interactive "P") | 231 | (interactive "P") |
| 224 | (setq 5x5-cracking nil) | 232 | (setq 5x5-cracking nil) |
| @@ -331,9 +339,14 @@ Quit current game \\[5x5-quit-game]" | |||
| 331 | (forward-char (+ 1 (/ (1+ 5x5-x-scale) 2))) | 339 | (forward-char (+ 1 (/ (1+ 5x5-x-scale) 2))) |
| 332 | (dotimes (x 5x5-grid-size) | 340 | (dotimes (x 5x5-grid-size) |
| 333 | (when (5x5-cell solution-grid y x) | 341 | (when (5x5-cell solution-grid y x) |
| 342 | (if (= 0 (mod 5x5-x-scale 2)) | ||
| 343 | (progn | ||
| 344 | (insert "()") | ||
| 345 | (delete-region (point) (+ (point) 2)) | ||
| 346 | (backward-char 2)) | ||
| 334 | (insert-char ?O 1) | 347 | (insert-char ?O 1) |
| 335 | (delete-char 1) | 348 | (delete-char 1) |
| 336 | (backward-char)) | 349 | (backward-char))) |
| 337 | (forward-char (1+ 5x5-x-scale)))) | 350 | (forward-char (1+ 5x5-x-scale)))) |
| 338 | (forward-line 5x5-y-scale)))) | 351 | (forward-line 5x5-y-scale)))) |
| 339 | (setq 5x5-solver-output nil))) | 352 | (setq 5x5-solver-output nil))) |
| @@ -790,6 +803,64 @@ Argument N is ignored." | |||
| 790 | (5x5-draw-grid (list 5x5-grid)) | 803 | (5x5-draw-grid (list 5x5-grid)) |
| 791 | (5x5-position-cursor)) | 804 | (5x5-position-cursor)) |
| 792 | 805 | ||
| 806 | (defun 5x5-solve-rotate-left (&optional n) | ||
| 807 | "Rotate left by N the list of solutions in 5x5-solver-output. | ||
| 808 | |||
| 809 | If N is not supplied rotate by 1, that is to say put the last | ||
| 810 | element first in the list. | ||
| 811 | |||
| 812 | The 5x5 game has in general several solutions. For grid size=5, | ||
| 813 | there are 4 possible solutions. When function | ||
| 814 | `5x5-solve-suggest' (press `\\[5x5-solve-suggest]') is called the | ||
| 815 | solution that is presented is the one that needs least number of | ||
| 816 | strokes --- other solutions can be viewed by rotating through the | ||
| 817 | list. The list of solution is ordered by number of strokes, so | ||
| 818 | rotating left just after calling `5x5-solve-suggest' will show | ||
| 819 | the the solution with second least number of strokes, while | ||
| 820 | rotating right will show the solution with greatest number of | ||
| 821 | strokes." | ||
| 822 | (interactive "P") | ||
| 823 | (let ((len (length 5x5-solver-output))) | ||
| 824 | (when (>= len 3) | ||
| 825 | (setq n (if (integerp n) n 1) | ||
| 826 | n (mod n (1- len))) | ||
| 827 | (unless (eq n 0) | ||
| 828 | (setq n (- len n 1)) | ||
| 829 | (let* ((p-tail (last 5x5-solver-output (1+ n))) | ||
| 830 | (tail (cdr p-tail)) | ||
| 831 | (l-tail (last tail))) | ||
| 832 | ;; | ||
| 833 | ;; For n = 2: | ||
| 834 | ;; | ||
| 835 | ;; +--+--+ +--+--+ +--+--+ +--+--+ +--+--+ | ||
| 836 | ;; |M | ---->|S1| ---->|S2| ---->|S3| ---->|S4| ----> nil | ||
| 837 | ;; +--+--+ +--+--+ +--+--+ +--+--+ +--+--+ | ||
| 838 | ;; ^ ^ ^ ^ | ||
| 839 | ;; | | | | | ||
| 840 | ;; + 5x5-solver-output | | + l-tail | ||
| 841 | ;; + p-tail | | ||
| 842 | ;; + tail | ||
| 843 | ;; | ||
| 844 | (setcdr l-tail (cdr 5x5-solver-output)) | ||
| 845 | (setcdr 5x5-solver-output tail) | ||
| 846 | (unless (eq p-tail 5x5-solver-output) | ||
| 847 | (setcdr p-tail nil))) | ||
| 848 | (5x5-draw-grid (list 5x5-grid)) | ||
| 849 | (5x5-position-cursor))))) | ||
| 850 | |||
| 851 | (defun 5x5-solve-rotate-right (&optional n) | ||
| 852 | "Rotate right by N the list of solutions in 5x5-solver-output. | ||
| 853 | If N is not supplied, rotate by 1. Similar to function | ||
| 854 | `5x5-solve-rotate-left' except that rotation is right instead of | ||
| 855 | lest." | ||
| 856 | (interactive "P") | ||
| 857 | (setq n | ||
| 858 | (if (integerp n) (- n) | ||
| 859 | -1)) | ||
| 860 | (5x5-solve-rotate-left n)) | ||
| 861 | |||
| 862 | |||
| 863 | |||
| 793 | ;; Keyboard response functions. | 864 | ;; Keyboard response functions. |
| 794 | 865 | ||
| 795 | (defun 5x5-flip-current () | 866 | (defun 5x5-flip-current () |