jtulach@9
|
1 |
/*
|
jaroslav@264
|
2 |
* Quoridor server and related libraries
|
jaroslav@264
|
3 |
* Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jtulach@9
|
4 |
*
|
jaroslav@264
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@264
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@264
|
7 |
* the Free Software Foundation, either version 3 of the License.
|
jtulach@9
|
8 |
*
|
jaroslav@264
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@264
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@264
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@264
|
12 |
* GNU General Public License for more details.
|
jtulach@9
|
13 |
*
|
jaroslav@264
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@264
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@264
|
16 |
* If not, see http://www.gnu.org/licenses/.
|
jtulach@9
|
17 |
*/
|
jtulach@9
|
18 |
package cz.xelfi.quoridor;
|
jtulach@9
|
19 |
|
jtulach@15
|
20 |
import cz.xelfi.quoridor.Player.Direction;
|
jtulach@9
|
21 |
import java.io.IOException;
|
jtulach@9
|
22 |
import java.io.StringWriter;
|
jtulach@9
|
23 |
|
jtulach@9
|
24 |
/** Basic tests in simple configuration.
|
jtulach@9
|
25 |
*
|
jtulach@9
|
26 |
* @author Jaroslav Tulach
|
jtulach@9
|
27 |
*/
|
jtulach@9
|
28 |
public class SerializeTest extends BoardCase {
|
jtulach@9
|
29 |
public SerializeTest (String testName) {
|
jtulach@9
|
30 |
super (testName);
|
jtulach@9
|
31 |
}
|
jtulach@9
|
32 |
|
jtulach@9
|
33 |
@Override
|
jtulach@9
|
34 |
protected Board move(Board b, int player, Direction... where) throws IllegalPositionException {
|
jtulach@9
|
35 |
try {
|
jtulach@9
|
36 |
Board read = reread(b);
|
jtulach@10
|
37 |
return read.move(read.getPlayers().get(player), where);
|
jtulach@9
|
38 |
} catch (IOException ex) {
|
jtulach@9
|
39 |
throw new IllegalStateException(ex);
|
jtulach@9
|
40 |
}
|
jtulach@9
|
41 |
}
|
jtulach@15
|
42 |
protected Board fence(Board b, int player, char x, int y, Fence.Orientation orie)
|
jtulach@9
|
43 |
throws IllegalPositionException {
|
jtulach@9
|
44 |
try {
|
jtulach@9
|
45 |
Board read = reread(b);
|
jtulach@10
|
46 |
return read.fence(read.getPlayers().get(player), x, y, orie);
|
jtulach@9
|
47 |
} catch (IOException ex) {
|
jtulach@9
|
48 |
throw new IllegalStateException(ex);
|
jtulach@9
|
49 |
}
|
jtulach@9
|
50 |
}
|
jtulach@9
|
51 |
|
jtulach@13
|
52 |
@Override
|
jtulach@13
|
53 |
protected Board apply(Board b, Move move) throws IllegalPositionException {
|
jtulach@13
|
54 |
try {
|
jtulach@13
|
55 |
Board read = reread(b);
|
jtulach@13
|
56 |
return read.apply(move);
|
jtulach@13
|
57 |
} catch (IOException ex) {
|
jtulach@13
|
58 |
throw new IllegalStateException(ex);
|
jtulach@13
|
59 |
}
|
jtulach@13
|
60 |
}
|
jtulach@13
|
61 |
|
jtulach@10
|
62 |
private Board reread(Board b) throws IOException, IllegalPositionException {
|
jtulach@9
|
63 |
StringWriter w = new StringWriter();
|
jtulach@9
|
64 |
b.write(w);
|
jtulach@9
|
65 |
w.close();
|
jaroslav@179
|
66 |
return picture2board(w.toString());
|
jaroslav@178
|
67 |
//return Board.valueOf(w.toString());
|
jtulach@9
|
68 |
}
|
jtulach@13
|
69 |
|
jtulach@9
|
70 |
}
|