jaroslav@181
|
1 |
/*
|
jaroslav@181
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jaroslav@181
|
3 |
*
|
jaroslav@181
|
4 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@181
|
5 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@181
|
6 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@181
|
7 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@181
|
8 |
* License. You can obtain a copy of the License at
|
jaroslav@181
|
9 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@181
|
10 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@181
|
11 |
* specific language governing permissions and limitations under the
|
jaroslav@181
|
12 |
* License. When distributing the software, include this License Header
|
jaroslav@181
|
13 |
* Notice in each file and include the License file at
|
jaroslav@181
|
14 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jaroslav@181
|
15 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@181
|
16 |
* by Sun in the GPL Version 2 section of the License file that
|
jaroslav@181
|
17 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@181
|
18 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@181
|
19 |
* your own identifying information:
|
jaroslav@181
|
20 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@181
|
21 |
*
|
jaroslav@181
|
22 |
* Contributor(s):
|
jaroslav@181
|
23 |
*
|
jaroslav@181
|
24 |
* Portions Copyrighted 2009 Jaroslav Tulach
|
jaroslav@181
|
25 |
*/
|
jaroslav@181
|
26 |
package cz.xelfi.quoridor;
|
jaroslav@181
|
27 |
|
jaroslav@181
|
28 |
import cz.xelfi.quoridor.Player.Direction;
|
jaroslav@181
|
29 |
import java.io.IOException;
|
jaroslav@181
|
30 |
|
jaroslav@181
|
31 |
/** Basic tests in simple configuration.
|
jaroslav@181
|
32 |
*
|
jaroslav@181
|
33 |
* @author Jaroslav Tulach
|
jaroslav@181
|
34 |
*/
|
jaroslav@181
|
35 |
public class SerializeCodeTest extends BoardCase {
|
jaroslav@181
|
36 |
public SerializeCodeTest (String testName) {
|
jaroslav@181
|
37 |
super (testName);
|
jaroslav@181
|
38 |
}
|
jaroslav@181
|
39 |
|
jaroslav@181
|
40 |
@Override
|
jaroslav@181
|
41 |
protected Board move(Board b, int player, Direction... where) throws IllegalPositionException {
|
jaroslav@181
|
42 |
try {
|
jaroslav@181
|
43 |
Board read = reread(b);
|
jaroslav@181
|
44 |
return read.move(read.getPlayers().get(player), where);
|
jaroslav@181
|
45 |
} catch (IOException ex) {
|
jaroslav@181
|
46 |
throw new IllegalStateException(ex);
|
jaroslav@181
|
47 |
}
|
jaroslav@181
|
48 |
}
|
jaroslav@181
|
49 |
protected Board fence(Board b, int player, char x, int y, Fence.Orientation orie)
|
jaroslav@181
|
50 |
throws IllegalPositionException {
|
jaroslav@181
|
51 |
try {
|
jaroslav@181
|
52 |
Board read = reread(b);
|
jaroslav@181
|
53 |
return read.fence(read.getPlayers().get(player), x, y, orie);
|
jaroslav@181
|
54 |
} catch (IOException ex) {
|
jaroslav@181
|
55 |
throw new IllegalStateException(ex);
|
jaroslav@181
|
56 |
}
|
jaroslav@181
|
57 |
}
|
jaroslav@181
|
58 |
|
jaroslav@181
|
59 |
@Override
|
jaroslav@181
|
60 |
protected Board apply(Board b, Move move) throws IllegalPositionException {
|
jaroslav@181
|
61 |
try {
|
jaroslav@181
|
62 |
Board read = reread(b);
|
jaroslav@181
|
63 |
return read.apply(move);
|
jaroslav@181
|
64 |
} catch (IOException ex) {
|
jaroslav@181
|
65 |
throw new IllegalStateException(ex);
|
jaroslav@181
|
66 |
}
|
jaroslav@181
|
67 |
}
|
jaroslav@181
|
68 |
|
jaroslav@181
|
69 |
private Board reread(Board b) throws IOException, IllegalPositionException {
|
jaroslav@181
|
70 |
return Board.valueOf(b.getCode());
|
jaroslav@181
|
71 |
}
|
jaroslav@181
|
72 |
|
jaroslav@181
|
73 |
}
|