1 | /* |
2 | * Copyright (c) 2005 The PseudoQ Project. |
3 | * |
4 | * This file is part of PseudoQ. |
5 | * |
6 | * PseudoQ is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as published by |
8 | * the Free Software Foundation; either version 2.1 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * PseudoQ is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License |
17 | * along with PseudoQ; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ |
20 | |
21 | package net.sourceforge.pseudoq.model; |
22 | |
23 | import java.util.HashMap; |
24 | import java.util.Map; |
25 | |
26 | /** |
27 | * STANDARD_SAMURAI type puzzle. Made up of 5 STANDARD 9 by 9 cell puzzles, |
28 | * arranged in an "X" pattern such that their corner boxes overlap. Within |
29 | * each 9 by 9 grid, all the rows, columns and boxes must contain the digits |
30 | * 1 to 9. Also known as a "Gattai-5 Sudoku". |
31 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
32 | */ |
33 | public class SamuraiPuzzle extends Puzzle { |
34 | private static final int SIZE = 21; |
35 | private static final int MAXINT = 9; |
36 | private static final int BLOCK_SIZE = 3; |
37 | |
38 | public static Puzzle create() { |
39 | Puzzle puzzle = new SamuraiPuzzle(); |
40 | |
41 | for (int row = 0; row < 9; row++) { |
42 | for (int column = 0; column < 9; column++) { |
43 | puzzle.grid.put(new Coordinate(row, column), 0); |
44 | } |
45 | } |
46 | for (int row = 12; row < 21; row++) { |
47 | for (int column = 0; column < 9; column++) { |
48 | puzzle.grid.put(new Coordinate(row, column), 0); |
49 | } |
50 | } |
51 | for (int row = 0; row < 9; row++) { |
52 | for (int column = 12; column < 21; column++) { |
53 | puzzle.grid.put(new Coordinate(row, column), 0); |
54 | } |
55 | } |
56 | for (int row = 12; row < 21; row++) { |
57 | for (int column = 12; column < 21; column++) { |
58 | puzzle.grid.put(new Coordinate(row, column), 0); |
59 | } |
60 | } |
61 | for (int row = 6; row < 15; row++) { |
62 | for (int column = 6; column < 15; column++) { |
63 | puzzle.grid.put(new Coordinate(row, column), 0); |
64 | } |
65 | } |
66 | |
67 | return puzzle; |
68 | } |
69 | |
70 | /** |
71 | * Creates a new instance of SamuraiPuzzle |
72 | */ |
73 | public SamuraiPuzzle() { |
74 | this.grid = new Grid(SIZE); |
75 | } |
76 | |
77 | public PuzzleTypeEnum getType() { |
78 | return PuzzleTypeEnum.STANDARD_SAMURAI; |
79 | } |
80 | |
81 | public int getMaxInt() { |
82 | return MAXINT; |
83 | } |
84 | |
85 | public Map<String, Region> getRegions() { |
86 | Map<String, Region> regions = new HashMap<String, Region>(); |
87 | |
88 | // rows |
89 | for (int row = 0; row < 9; row++) { |
90 | Region region = new Region("Row " + (10 + row)); |
91 | for (int column = 0 ; column < 9; column++) { |
92 | region.add(new Coordinate(row, column)); |
93 | } |
94 | regions.put("row-" + (10 + row), region); |
95 | } |
96 | for (int row = 0; row < 9; row++) { |
97 | Region region = new Region("Row " + (20 + row)); |
98 | for (int column = 12 ; column < 21; column++) { |
99 | region.add(new Coordinate(row, column)); |
100 | } |
101 | regions.put("row-" + (20 + row), region); |
102 | } |
103 | for (int row = 6; row < 15; row++) { |
104 | Region region = new Region("Row " + (24 + row)); |
105 | for (int column = 6 ; column < 15; column++) { |
106 | region.add(new Coordinate(row, column)); |
107 | } |
108 | regions.put("row-" + (24 + row), region); |
109 | } |
110 | for (int row = 12; row < 21; row++) { |
111 | Region region = new Region("Row " + (28 + row)); |
112 | for (int column = 0 ; column < 9; column++) { |
113 | region.add(new Coordinate(row, column)); |
114 | } |
115 | regions.put("row-" + (28 + row), region); |
116 | } |
117 | for (int row = 12; row < 21; row++) { |
118 | Region region = new Region("Row " + (38 + row)); |
119 | for (int column = 12 ; column < 21; column++) { |
120 | region.add(new Coordinate(row, column)); |
121 | } |
122 | regions.put("row-" + (38 + row), region); |
123 | } |
124 | // columns |
125 | for (int column = 0 ; column < 9; column++) { |
126 | Region region = new Region("Column " + (10 + column)); |
127 | for (int row = 0; row < 9; row++) { |
128 | region.add(new Coordinate(row, column)); |
129 | } |
130 | regions.put("column-" + (10 + column), region); |
131 | } |
132 | for (int column = 12 ; column < 21; column++) { |
133 | Region region = new Region("Column " + (8 + column)); |
134 | for (int row = 0; row < 9; row++) { |
135 | region.add(new Coordinate(row, column)); |
136 | } |
137 | regions.put("column-" + (8 + column), region); |
138 | } |
139 | for (int column = 6 ; column < 15; column++) { |
140 | Region region = new Region("Column " + (24 + column)); |
141 | for (int row = 6; row < 15; row++) { |
142 | region.add(new Coordinate(row, column)); |
143 | } |
144 | regions.put("column-" + (24 + column), region); |
145 | } |
146 | for (int column = 0 ; column < 9; column++) { |
147 | Region region = new Region("Column " + (40 + column)); |
148 | for (int row = 12; row < 21; row++) { |
149 | region.add(new Coordinate(row, column)); |
150 | } |
151 | regions.put("column-" + (40 + column), region); |
152 | } |
153 | for (int column = 12 ; column < 21; column++) { |
154 | Region region = new Region("Column " + (38 + column)); |
155 | for (int row = 12; row < 21; row++) { |
156 | region.add(new Coordinate(row, column)); |
157 | } |
158 | regions.put("column-" + (38 + column), region); |
159 | } |
160 | // blocks - 7 x 7 square blocks (minus a few gaps), each one 3 x 3 cells |
161 | for (int x = 0; x < 7; x++) { |
162 | for (int y = 0; y < 7; y++) { |
163 | if ((x != 3 && y != 3) || (2 <= x && x <= 4 && 2 <= y && y <= 4)) { |
164 | Region region = new Region("Box " + ((x* 7) + y)); |
165 | for (int row = x * BLOCK_SIZE; row < (x + 1) * BLOCK_SIZE; row++) { |
166 | for (int column = y * BLOCK_SIZE ; column < (y + 1) * BLOCK_SIZE; column++) { |
167 | region.add(new Coordinate(row, column)); |
168 | } |
169 | } |
170 | regions.put("box-" + ((x * 7) + y), region); |
171 | } |
172 | } |
173 | } |
174 | |
175 | return regions; |
176 | } |
177 | |
178 | public String toString() { |
179 | return this.grid.toString(); |
180 | } |
181 | |
182 | public int getSize() { |
183 | return SIZE; |
184 | } |
185 | |
186 | } |