|
1 | 1 | import org.junit.Test; |
2 | 2 | import sh.hell.compactchess.exceptions.ChessException; |
3 | 3 | import sh.hell.compactchess.game.Game; |
| 4 | +import sh.hell.compactchess.game.Move; |
4 | 5 | import sh.hell.compactchess.game.Opening; |
5 | 6 |
|
| 7 | +import java.util.ArrayList; |
| 8 | + |
6 | 9 | import static junit.framework.TestCase.assertEquals; |
| 10 | +import static junit.framework.TestCase.assertFalse; |
| 11 | +import static junit.framework.TestCase.assertTrue; |
7 | 12 |
|
8 | 13 | public class Tests |
9 | 14 | { |
10 | 15 | @Test(timeout = 3000L) |
11 | 16 | public void openings() throws ChessException |
12 | 17 | { |
13 | 18 | System.out.println("Openings\n"); |
14 | | - final Game game = Game.fromPGN("1.e4 e5 2.Nf3 Nc6 3.Bb5 a6 4.Ba4 Nf6 5.O-O Be7 6.Re1 b5 7.Bb3 O-O 8.c3 d5 9.exd5 Nxd5 10.Nxe5 Nxe5 11.Rxe5 c6 12.d4 Bd6 13.Re1 Qh4 14.g3 Qh3 15.Be3 Bg4 16.Qd3 Rae8 17.Nd2 Re6 18.a4 Qh5 19. axb5").get(0); |
| 19 | + final Game game = Game.fromPGN("1.e4 e5 2.Nf3 Nc6 3.Bb5 a6 4.Ba4 Nf6 5.O-O Be7 6.Re1 b5 7.Bb3 O-O 8.c3 d5 9.exd5 Nxd5 10.Nxe5 Nxe5 11.Rxe5 c6 12.d4 Bd6 13.Re1 Qh4 14.g3 Qh3 15.Be3 Bg4 16.Qd3 Rae8 17.Nd2 Re6 18.a4").get(0); |
| 20 | + final ArrayList<Opening> continuations = Opening.getContinuations(game); |
| 21 | + assertEquals(1, continuations.size()); |
| 22 | + final Opening opening = continuations.get(0); |
| 23 | + assertFalse(opening.isUsedIn(game)); |
| 24 | + assertTrue(opening.canBeUsedIn(game)); |
| 25 | + final Move nextMove = opening.getNextMove(game); |
| 26 | + assertEquals("h3h5", nextMove.toUCI()); |
| 27 | + nextMove.commit(); |
| 28 | + assertTrue(opening.isUsedIn(game)); |
| 29 | + game.uciMove("a4b5").commit(); |
| 30 | + assertTrue(opening.isUsedIn(game)); |
15 | 31 | Opening.insertInto(game, false, true); |
16 | 32 | System.out.println(game.toPGN()); |
17 | | - assertEquals("Ruy Lopez: Marshall, Main Line, Spassky Variation", game.tags.get("Opening")); |
| 33 | + assertEquals("Ruy Lopez: Marshall, Main Line, Spassky Variation", game.tags.get("Opening")); // This is the longest opening with 36 plies. |
18 | 34 | assertEquals("C89", game.tags.get("ECO")); |
19 | 35 | int i = 0; |
20 | 36 | assertEquals("B00 King's Pawn", game.moves.get(i++).getAnnotation()); |
|
0 commit comments