-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
141 lines (112 loc) · 2.86 KB
/
Copy pathBoard.java
File metadata and controls
141 lines (112 loc) · 2.86 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
public class Board {
private int size;
private int[] board;
private int num;
public static final int NOTHING = 0;
public static final int BLACK = 1;
public static final int WHITE = 2;
private Board() {
}
public Board(InfoPack info) throws ConflictException {
this.size = info.getSize();
this.num = (size * size);
board = new int[size * size];
for(int u = 0; u < board.length; u ++)
board[u] = NOTHING;
initialize(info);
}
private void initialize(InfoPack info) throws ConflictException {
for(MyQueue<Integer> q = info.getWhites(); q.getSize() > 0;) {
int i = q.dequeue();
addWhite(i - 1);
}
for(MyQueue<Integer> q = info.getBlacks(); q.getSize() > 0;) {
int i = q.dequeue();
addBlack(i - 1);
}
}
public int getNumbers() {
return num;
}
public int getColor(int position) {
return board[position];
}
public void setBlack(int position){
board[position] = BLACK;
}
public void setWhite(int position){
board[position] = WHITE;
}
public void addPebble(int position, int color) throws ConflictException {
if(inRange(position) && board[position] == NOTHING)
board[position] = color;
else throw new ConflictException("Invalid Position " + position);
}
public void addBlack(int position) throws ConflictException {
if(inRange(position) && board[position] == NOTHING)
board[position] = BLACK;
else throw new ConflictException("Invalid Position" + position);
}
public void addWhite(int position) throws ConflictException {
if(inRange(position) && board[position] == NOTHING)
board[position] = WHITE;
else throw new ConflictException("Invalid Position" + position);
}
public boolean inRange(int position) {
if (position < size || position >= 0)
return true;
else return false;
}
public int[] getBoard() {
return this.board;
}
public int getSize() {
return this.size;
}
public void printBoard() {
for(int i = 0; i < board.length;) {
for(int j = 0; j < size; i++,j++){
if(board[i] == BLACK)
System.out.print(" B ");
else if(board[i] == WHITE)
System.out.print(" W ");
else
System.out.print(" O ");
}
System.out.println();
}
System.out.println();
}
private void setBoard(int[] set) {
this.board = set;
}
private void setSize(int set) {
this.size = set;
}
public Board clone() {
Board clone = new Board();
clone.setBoard(this.getBoard());
clone.setSize(this.getSize());
clone.setNumbers(this.getNumbers());
return clone;
}
public boolean sameColor(int posA, int posB) {
if(getColor(posA) == getColor(posB))
return true;
else return false;
}
private void setNumbers(int set) {
this.num = set;
}
public static int InverseColor(int color) {
if(color == BLACK)
return WHITE;
else if(color == WHITE)
return BLACK;
else return NOTHING;
}
public boolean isEmpty() {
//TODO
return false;
}
}