-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
90 lines (82 loc) · 2.4 KB
/
Board.java
File metadata and controls
90 lines (82 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.*;
public class Board
{
private int boardDimensions = 9;
//ArrayList<ArrayList<Tile>> tiles;
private Tile tiles[][] = new Tile[boardDimensions][boardDimensions];
private Map<Integer, List<Tile>> localGroupMap = new HashMap<Integer, List<Tile>>();
private Map<Integer, List<Tile>> colMap = new HashMap<Integer, List<Tile>>();
private Map<Integer, List<Tile>> rowMap = new HashMap<Integer, List<Tile>>();
public Board()
{
for(int i=0; i < boardDimensions;i++)
{
localGroupMap.put(new Integer(i), new ArrayList<Tile>());
rowMap.put(new Integer(i), new ArrayList<Tile>());
colMap.put(new Integer(i), new ArrayList<Tile>());
}
for(int i=0; i < boardDimensions; i++)
{
for(int j=0; j < boardDimensions; j++)
{
int localGroup = ((i/3)*3) + (j/3);
System.out.println(i+" "+j+" "+localGroup);
Tile curTile = new Tile(i,j,localGroup);
tiles[i][j] = curTile;
localGroupMap.get(localGroup).add(curTile);
rowMap.get(i).add(curTile);
colMap.get(j).add(curTile);
}
}
}
public void setValue(int i,int j,int value)
{
tiles[i][j].setValue(value);
}
public Tile getTile(int i,int j)
{
return tiles[i][j];
}
public List<Tile> getLocalGroupTiles(int localGroup)
{
return localGroupMap.get(localGroup);
}
public List<Tile> getRowTiles(int row)
{
return rowMap.get(row);
}
public List<Tile> getColTiles(int column)
{
return colMap.get(column);
}
public String toString()
{
String boardString = "";
for(int i=0; i < boardDimensions; i++)
{
if( i%3 == 0)
boardString += "===================\n";
boardString += "|";
for(int j=0; j < boardDimensions; j++)
{
Tile curTile = tiles[i][j];
int tileValue = curTile.getValue();
if(tileValue != -1)
{
boardString += tileValue;
}
else
{
boardString += " ";
}
if( (j+1)%3 == 0)
boardString += "|";
else
boardString += " ";
}
boardString += "\n";
}
boardString += "===================\n";
return boardString;
}
}