src/de/uapcore/sudoku/Field.java

Fri, 01 Feb 2013 10:18:47 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 01 Feb 2013 10:18:47 +0100
changeset 8
e70a0e3555fb
parent 7
2c0a2766461c
permissions
-rw-r--r--

removed completeness test - the solver automatically returns false when the field is incomplete

3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
1 /*
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
2 * Copyright 2013 Mike Becker. All rights reserved.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
3 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
4 * Redistribution and use in source and binary forms, with or without
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
5 * modification, are permitted provided that the following conditions are met:
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
6 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
7 * 1. Redistributions of source code must retain the above copyright
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
8 * notice, this list of conditions and the following disclaimer.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
9 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
12 * documentation and/or other materials provided with the distribution.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
13 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
24 * POSSIBILITY OF SUCH DAMAGE.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
25 */
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
26
1
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 package de.uapcore.sudoku;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 import java.awt.Color;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 import java.awt.Graphics;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 import java.awt.Graphics2D;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 import java.awt.GridBagConstraints;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 import java.awt.GridBagLayout;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import java.awt.Insets;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 import java.awt.image.BufferedImage;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 import javax.swing.JPanel;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 /**
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 *
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 * @author mike
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 */
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
42 public final class Field extends JPanel {
1
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 private SudokuTextField[][] cells;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 public Field() {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 setBackground(Color.WHITE);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 setLayout(new GridBagLayout());
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 GridBagConstraints c = new GridBagConstraints();
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 c.insets = new Insets(5, 5, 5, 5);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 cells = new SudokuTextField[9][9];
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 for (int x = 0 ; x < 9 ; x++) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 for (int y = 0 ; y < 9 ; y++) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 cells[x][y] = new SudokuTextField();
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 c.gridx = x;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 c.gridy = y;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 add(cells[x][y], c);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 @Override
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 public void paint(Graphics graphics) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 final int w = getWidth();
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 final int h = getHeight();
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 final int cw = w / 9;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 final int ch = h / 9;
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 Graphics2D g = img.createGraphics();
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 g.setBackground(Color.WHITE);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 g.clearRect(0, 0, w, h);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 g.setColor(Color.BLACK);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 g.drawRect(1, 1, w-2, h-2);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 g.drawRect(2, 2, w-4, h-4);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 for (int x = cw ; x < w ; x += cw) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 for (int y = ch ; y < h ; y += ch) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 g.drawLine(x, 2, x, h-2);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 g.drawLine(2, y, w-2, y);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 if ((x / cw) % 3 == 0) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 g.drawLine(x+1, 2, x+1, h-2);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 if ((y / ch) % 3 == 0) {
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 g.drawLine(2, y+1, w-2, y+1);
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 graphics.drawImage(img, 0, 0, this);
5
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
92 super.paintChildren(graphics);
1
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 }
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94
7
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
95 public boolean isCellEmpty(int x, int y) {
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
96 return getCellValue(x, y) == 0;
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
97 }
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
98
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
99 public int getCellValue(int x, int y) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
100 return cells[x][y].getValue();
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
101 }
1
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
103 public void setCellValue(int x, int y, int v) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
104 cells[x][y].setValue(v);
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
105 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
106
7
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
107 public void clearCellValue(int x, int y) {
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
108 setCellValue(x, y, 0);
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
109 }
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
110
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
111 public void setCellModified(int x, int y, boolean modified) {
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
112 cells[x][y].setModified(modified);
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
113 }
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
114
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
115 public void setAllCellsModified(boolean modified) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
116 for (int x = 0 ; x < 9 ; x++) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
117 for (int y = 0 ; y < 9 ; y++) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
118 cells[x][y].setModified(modified);
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
119 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
120 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
121 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
122
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
123 public boolean isAnyCellModified() {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
124 for (int x = 0 ; x < 9 ; x++) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
125 for (int y = 0 ; y < 9 ; y++) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
126 if (cells[x][y].isModified()) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
127 return true;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
128 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
129 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
130 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
131 return false;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
132 }
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
133
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
134 public void clear() {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
135 for (int x = 0 ; x < 9 ; x++) {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
136 for (int y = 0 ; y < 9 ; y++) {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
137 cells[x][y].setValue(0);
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
138 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
139 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
140 }
5
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
141
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
142 public int[][] getSquare(int x, int y) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
143 if (x < 0 || x > 2 || y < 0 || y > 2) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
144 throw new IllegalArgumentException("Invalid square coordinates");
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
145 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
146 int[][] square = new int[3][3];
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
147
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
148 for (int u = 0 ; u < 3 ; u++) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
149 for (int v = 0 ; v < 3 ; v++) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
150 square[u][v] = getCellValue(3*x+u, 3*y+v);
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
151 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
152 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
153
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
154 return square;
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
155 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
156
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
157 public int[] getRow(int y) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
158 if (y < 0 || y > 8) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
159 throw new IllegalArgumentException("Invalid row number");
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
160 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
161 int row[] = new int[9];
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
162
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
163 for (int x = 0 ; x < 9 ; x++) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
164 row[x] = getCellValue(x, y);
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
165 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
166
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
167 return row;
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
168 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
169
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
170 public int[] getColumn(int x) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
171 if (x < 0 || x > 8) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
172 throw new IllegalArgumentException("Invalid column number");
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
173 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
174 int column[] = new int[9];
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
175
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
176 for (int y = 0 ; y < 9 ; y++) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
177 column[y] = getCellValue(x, y);
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
178 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
179
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
180 return column;
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
181 }
1
f1d7de36b01e init project + editable sudoku field
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 }

mercurial