-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTrain.java
More file actions
239 lines (206 loc) · 6.12 KB
/
Copy pathMainTrain.java
File metadata and controls
239 lines (206 loc) · 6.12 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package test;
import test.Tile.Bag;
public class MainTrain {
public static void testBag() {
Bag b=Tile.Bag.getBag();
Bag b1=Tile.Bag.getBag();
if(b1!=b)
System.out.println("your Bag in not a Singleton (-5)");
int[] q0 = b.getQuantities();
q0[0]+=1;
int[] q1 = b.getQuantities();
if(q0[0]!=q1[0] + 1)
System.out.println("getQuantities did not return a clone (-5)");
for(int k=0;k<9;k++) {
int[] qs = b.getQuantities();
Tile t = b.getRand();
int i=t.letter-'A';
int[] qs1 = b.getQuantities();
if(qs1[i]!=qs[i]-1)
System.out.println("problem with getRand (-1)");
b.put(t);
b.put(t);
b.put(t);
if(b.getQuantities()[i]!=qs[i])
System.out.println("problem with put (-1)");
}
if(b.getTile('a')!=null || b.getTile('$')!=null || b.getTile('A')==null)
System.out.println("your getTile is wrong (-2)");
}
private static Tile[] get(String s) {
Tile[] ts=new Tile[s.length()];
int i=0;
for(char c: s.toCharArray()) {
ts[i]=Bag.getBag().getTile(c);
i++;
}
return ts;
}
public static void testBoard() {
Board b = Board.getBoard();
if(b!=Board.getBoard())
System.out.println("board should be a Singleton (-5)");
Bag bag = Bag.getBag();
Tile[] ts=new Tile[10];
for(int i=0;i<ts.length;i++)
ts[i]=bag.getRand();
Word w0=new Word(ts,0,6,true);
Word w1=new Word(ts,7,6,false);
Word w2=new Word(ts,6,7,true);
Word w3=new Word(ts,-1,7,true);
Word w4=new Word(ts,7,-1,false);
Word w5=new Word(ts,0,7,true);
Word w6=new Word(ts,7,0,false);
if(b.boardLegal(w0) || b.boardLegal(w1) || b.boardLegal(w2) || b.boardLegal(w3) || b.boardLegal(w4) || !b.boardLegal(w5) || !b.boardLegal(w6))
System.out.println("your boardLegal function is wrong (-10)");
for(Tile t : ts)
bag.put(t);
Word horn=new Word(get("HORN"), 7, 5, false);
if(b.tryPlaceWord(horn)!=14)
System.out.println("problem in placeWord for 1st word (-10)");
Word farm=new Word(get("FA_M"), 5, 7, true);
if(b.tryPlaceWord(farm)!=9)
System.out.println("problem in placeWord for 2ed word (-10)");
Word paste=new Word(get("PASTE"), 9, 5, false);
if(b.tryPlaceWord(paste)!=25)
System.out.println("problem in placeWord for 3ed word (-10)");
Word mob=new Word(get("_OB"), 8, 7, false);
int mobpoint = b.tryPlaceWord(mob);
if(mobpoint!=18)
System.out.println("mob point sould be 18");
Word bit=new Word(get("BIT"), 10, 4, false);
int bitpoint = b.tryPlaceWord(bit);
if(bitpoint!=22)
System.out.println("bitpoint should be 22 (-15)");
Word bit2=new Word(get("S_TA"), 9, 4, true);
if(b.tryPlaceWord(bit2)!=28)
System.out.println("SBTA should be 28 (-15)");
Word bit3=new Word(get("A_ONE"), 11, 3, false);
if(b.tryPlaceWord(bit3)!=26)
System.out.println("ATONE should be 26 (-15)");
}
public static void main(String[] args) {
testBag(); // 30 points
testBoard(); // 70 points
System.out.println("done");
}
}
//package test;
//
//import test.Tile.Bag;
//
//public class MainTrain {
//
// public static void testBag() {
// Bag b=Tile.Bag.getBag();
// Bag b1=Tile.Bag.getBag();
// if(b1!=b)
// System.out.println("your Bag in not a Singleton (-5)");
//
// int[] q0 = b.getQuantities();
// q0[0]+=1;
// int[] q1 = b.getQuantities();
// if(q0[0]!=q1[0] + 1)
// System.out.println("getQuantities did not return a clone (-5)");
//
// for(int k=0;k<9;k++) {
// int[] qs = b.getQuantities();
// Tile t = b.getRand();
// int i=t.letter-'A';
// int[] qs1 = b.getQuantities();
// if(qs1[i]!=qs[i]-1)
// System.out.println("problem with getRand (-1)");
//
// b.put(t);
// b.put(t);
// b.put(t);
//
// if(b.getQuantities()[i]!=qs[i])
// System.out.println("problem with put (-1)");
// }
//
// if(b.getTile('a')!=null || b.getTile('$')!=null || b.getTile('A')==null)
// System.out.println("your getTile is wrong (-2)");
//
// }
//
//
//
// private static Tile[] get(String s) {
// Tile[] ts=new Tile[s.length()];
// int i=0;
// for(char c: s.toCharArray()) {
// ts[i]=Bag.getBag().getTile(c);
// i++;
// }
// return ts;
// }
//
//
// public static void testBoard() {
// Board b = Board.getBoard();
// if(b!=Board.getBoard())
// System.out.println("board should be a Singleton (-5)");
//
//
// Bag bag = Bag.getBag();
// Tile[] ts=new Tile[10];
// for(int i=0;i<ts.length;i++)
// ts[i]=bag.getRand();
//
// Word w0=new Word(ts,0,6,true);
// Word w1=new Word(ts,7,6,false);
// Word w2=new Word(ts,6,7,true);
// Word w3=new Word(ts,-1,7,true);
// Word w4=new Word(ts,7,-1,false);
// Word w5=new Word(ts,0,7,true);
// Word w6=new Word(ts,7,0,false);
//
// if(b.boardLegal(w0) || b.boardLegal(w1) || b.boardLegal(w2) || b.boardLegal(w3) || b.boardLegal(w4) || !b.boardLegal(w5) || !b.boardLegal(w6))
// System.out.println("your boardLegal function is wrong (-10)");
//
// for(Tile t : ts)
// bag.put(t);
//
//
// Word horn=new Word(get("HORN"), 7, 5, false);
// if(b.tryToPlaceWord(horn)!=14)
// System.out.println("problem in placeWord for 1st word (-10)");
//
//
// Word farm=new Word(get("FA_M"), 5, 7, true);
// if(b.tryToPlaceWord(farm)!=9)
// System.out.println("problem in placeWord for 2ed word (-10)");
//
// Word paste=new Word(get("PASTE"), 9, 5, false);
// if(b.tryToPlaceWord(paste)!=25)
// System.out.println("problem in placeWord for 3ed word (-10)");
//
// Word mob=new Word(get("_OB"), 8, 7, false);
// if(b.tryToPlaceWord(mob)!=18)
// System.out.println("problem in placeWord for 4th word (-10)");
//
// Word bit=new Word(get("BIT"), 10, 4, false);
// if(b.tryToPlaceWord(bit)!=22)
// System.out.println("problem in placeWord for 5th word (-15)");
//
//
// //// my test ///
// Word cmob=new Word(get("CMOB"), 8, 6, false);
// if(b.tryToPlaceWord(bit)!=10)
// System.out.println("problem in placeWord for 6th word (-15)");
//
//
//
//
//
//
// }
//
// public static void main(String[] args) {
// testBag(); // 30 points
// testBoard(); // 70 points
// System.out.println("done");
// }
//
//}