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