-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIteratorTests.java
More file actions
177 lines (151 loc) · 5.33 KB
/
Copy pathIteratorTests.java
File metadata and controls
177 lines (151 loc) · 5.33 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package amazons;
import org.junit.Test;
import static org.junit.Assert.*;
import ucb.junit.textui;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/** Junit tests for our Board iterators.
* @author
*/
public class IteratorTests {
/** Run the JUnit tests in this package. */
public static void main(String[] ignored) {
textui.runClasses(IteratorTests.class);
}
/** Tests reachableFromIterator to make sure it returns all reachable
* Squares. This method may need to be changed based on
* your implementation. */
@Test
public void testReachableFrom() {
Board b = new Board();
int numSquares = 0;
Set<Square> squares = new HashSet<>();
Iterator<Square> reachableFrom = b.reachableFrom(Square.sq(5, 4), null);
while (reachableFrom.hasNext()) {
Square s = reachableFrom.next();
assertTrue(SQUARES.contains(s));
numSquares += 1;
squares.add(s);
}
System.out.println(squares);
System.out.print(SQUARES);
System.out.print(numSquares);
assertEquals(SQUARES.size(), numSquares);
assertEquals(SQUARES.size(), squares.size());
}
/** Tests legalMovesIterator to make sure it returns all legal Moves.
* This method needs to be finished and may need to be changed
* based on your implementation. */
@Test
public void testLegalMoves() {
Board b = new Board();
int numMoves = 0;
Set<Move> moves = new HashSet<>();
Iterator<Move> legalMoves = b.legalMoves(Piece.BLACK);
while (legalMoves.hasNext()) {
Move m = legalMoves.next();
assertTrue(MOVE_HASH_SET.contains(m));
numMoves += 1;
moves.add(m);
}
assertEquals(MOVE_HASH_SET.size(), numMoves);
assertEquals(MOVE_HASH_SET.size(), moves.size());
}
@Test
public void testLegalMoves1() {
Board b = new Board();
int numMoves = 0;
Set<Move> moves = new HashSet<>();
Iterator<Move> legalMoves = b.legalMoves(Piece.WHITE);
while (legalMoves.hasNext()) {
Move m = legalMoves.next();
System.out.println(m);
assertTrue(b.isLegal(m));
numMoves += 1;
moves.add(m);
}
System.out.print(numMoves);
assertEquals(2176, numMoves);
assertEquals(2176, moves.size());
}
/** Tests legalMovesIterator to make sure it returns all legal Moves.
* This method needs to be finished and may need to be changed
* based on your implementation. */
@Test
public void testReachableFromSp() {
Board b = new Board();
int numSquares = 0;
Set<Square> squares = new HashSet<>();
Iterator<Square> reachableFrom =
b.reachableFrom(Square.sq("c9"), Square.sq("b9"));
while (reachableFrom.hasNext()) {
Square s = reachableFrom.next();
numSquares += 1;
squares.add(s);
}
System.out.println(squares);
System.out.print(numSquares);
}
public static void buildBoard(Board b, Piece[][] target) {
for (int col = 0; col < Board.SIZE; col++) {
for (int row = Board.SIZE - 1; row >= 0; row--) {
Piece piece = target[Board.SIZE - row - 1][col];
b.put(piece, Square.sq(col, row));
}
}
System.out.println(b);
}
/** Tests legalMovesIterator to make sure it returns all legal Moves.
* This method needs to be finished and may need to be changed
* based on your implementation. */
@Test
public void testWin() {
Board b = new Board();
int numSquares = 0;
Set<Square> squares = new HashSet<>();
Iterator<Square> reachableFrom =
b.reachableFrom(Square.sq("c9"), Square.sq("b9"));
while (reachableFrom.hasNext()) {
Square s = reachableFrom.next();
numSquares += 1;
squares.add(s);
}
System.out.println(squares);
System.out.print(numSquares);
}
@Test
public void testAI() {
Board b = new Board();
int numSquares = 0;
Set<Square> squares = new HashSet<>();
Iterator<Square> reachableFrom =
b.reachableFrom(Square.sq("c9"), Square.sq("b9"));
while (reachableFrom.hasNext()) {
Square s = reachableFrom.next();
numSquares += 1;
squares.add(s);
}
System.out.println(squares);
System.out.print(numSquares);
}
static final Piece E = Piece.EMPTY;
static final Piece W = Piece.WHITE;
static final Piece B = Piece.BLACK;
static final Piece S = Piece.SPEAR;
static final Set<Square> SQUARES =
new HashSet<>(Arrays.asList(
Square.sq(5, 5),
Square.sq(4, 5),
Square.sq(4, 4),
Square.sq(6, 4),
Square.sq(7, 4),
Square.sq(6, 5),
Square.sq(7, 6),
Square.sq(8, 7)));
static final Set<Move> MOVE_HASH_SET =
new HashSet<>(Arrays.asList(
Move.mv(Square.sq("c9"),
Square.sq("b9"), Square.sq("c9"))));
}