| 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 | * LARGE type puzzle. 16 by 16 cells, divided into thirds vertically and |
| 28 | * horizontally. Each row and each column must contain the digits 0 to 9 and |
| 29 | * A to F, as must each box. |
| 30 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
| 31 | */ |
| 32 | public class LargePuzzle extends Puzzle { |
| 33 | private static final int SIZE = 16; |
| 34 | private static final int BLOCK_SIZE = 4; |
| 35 | |
| 36 | public static Puzzle create() { |
| 37 | Puzzle puzzle = new LargePuzzle(); |
| 38 | |
| 39 | for (int row = 0; row < SIZE; row++) { |
| 40 | for (int column = 0 ; column < SIZE; column++) { |
| 41 | puzzle.grid.put(new Coordinate(row, column), 0); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return puzzle; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates a new instance of LargePuzzle. |
| 50 | */ |
| 51 | public LargePuzzle() { |
| 52 | this.grid = new Grid(SIZE); |
| 53 | } |
| 54 | |
| 55 | public PuzzleTypeEnum getType() { |
| 56 | return PuzzleTypeEnum.LARGE; |
| 57 | } |
| 58 | |
| 59 | public int getMaxInt() { |
| 60 | return SIZE; |
| 61 | } |
| 62 | |
| 63 | public Map<String, Region> getRegions() { |
| 64 | Map<String, Region> regions = new HashMap<String, Region>(); |
| 65 | |
| 66 | // rows |
| 67 | for (int row = 0; row < SIZE; row++) { |
| 68 | Region region = new Region("Row " + row); |
| 69 | for (int column = 0 ; column < SIZE; column++) { |
| 70 | region.add(new Coordinate(row, column)); |
| 71 | } |
| 72 | regions.put("row-" + row, region); |
| 73 | } |
| 74 | // columns |
| 75 | for (int column = 0 ; column < SIZE; column++) { |
| 76 | Region region = new Region("Column " + column); |
| 77 | for (int row = 0; row < SIZE; row++) { |
| 78 | region.add(new Coordinate(row, column)); |
| 79 | } |
| 80 | regions.put("column-" + column, region); |
| 81 | } |
| 82 | // blocks - 4 x 4 square blocks, each one 3 x 3 cells |
| 83 | for (int x = 0; x < BLOCK_SIZE; x++) { |
| 84 | for (int y = 0; y < BLOCK_SIZE; y++) { |
| 85 | Region region = new Region("Box " + ((x * BLOCK_SIZE) + y)); |
| 86 | for (int row = x * BLOCK_SIZE; row < (x + 1) * BLOCK_SIZE; row++) { |
| 87 | for (int column = y * BLOCK_SIZE ; column < (y + 1) * BLOCK_SIZE; column++) { |
| 88 | region.add(new Coordinate(row, column)); |
| 89 | } |
| 90 | } |
| 91 | regions.put("box-" + ((x * BLOCK_SIZE) + y), region); |
| 92 | } |
| 93 | } |
| 94 | // super-rows |
| 95 | for (int x = 0; x < BLOCK_SIZE; x++) { |
| 96 | Region region = new Region("superRow-" + x); |
| 97 | for (int row = x * BLOCK_SIZE; row < (x + 1) * BLOCK_SIZE; row++) { |
| 98 | region.addAll(regions.get("row-" + row)); |
| 99 | } |
| 100 | regions.put("superRow-" + x, region); |
| 101 | } |
| 102 | // super-columns |
| 103 | for (int x = 0; x < BLOCK_SIZE; x++) { |
| 104 | Region region = new Region("superColumn-" + x); |
| 105 | for (int column = x * BLOCK_SIZE; column < (x + 1) * BLOCK_SIZE; column++) { |
| 106 | region.addAll(regions.get("column-" + column)); |
| 107 | } |
| 108 | regions.put("superColumn-" + x, region); |
| 109 | } |
| 110 | |
| 111 | return regions; |
| 112 | } |
| 113 | |
| 114 | public String toString() { |
| 115 | return this.grid.toString(); |
| 116 | } |
| 117 | |
| 118 | public int getSize() { |
| 119 | return SIZE; |
| 120 | } |
| 121 | |
| 122 | } |