Convert to Eclipse / Maven project
BIN
src/main/resources/pieces/bishop_black.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/main/resources/pieces/bishop_white.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/main/resources/pieces/king_black.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/pieces/king_white.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/main/resources/pieces/knight_black.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/main/resources/pieces/knight_white.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/main/resources/pieces/pawn_black.png
Normal file
After Width: | Height: | Size: 797 B |
BIN
src/main/resources/pieces/pawn_white.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/main/resources/pieces/queen_black.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/main/resources/pieces/queen_white.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/pieces/rook_black.png
Normal file
After Width: | Height: | Size: 725 B |
BIN
src/main/resources/pieces/rook_white.png
Normal file
After Width: | Height: | Size: 933 B |
45
src/test/java/dev/kske/chess/board/BoardTest.java
Normal file
@ -0,0 +1,45 @@
|
||||
package dev.kske.chess.board;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import dev.kske.chess.board.Piece.Color;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>BoardTest.java</strong><br>
|
||||
* Created: <strong>08.07.2019</strong><br>
|
||||
* Author: <strong>Kai S. K. Engelbart</strong>
|
||||
*/
|
||||
class BoardTest {
|
||||
|
||||
private Board board;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
board = new Board();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Board#Board(Board, boolean)}.
|
||||
*/
|
||||
@Test
|
||||
void testClone() {
|
||||
Board clone = new Board(board, false);
|
||||
assertNotSame(clone, board);
|
||||
assertNotSame(clone.getBoardArr(), board.getBoardArr());
|
||||
|
||||
clone.getBoardArr()[0][0] = new Queen(Color.BLACK, clone);
|
||||
clone.move(new Move(1, 1, 1, 2));
|
||||
assertNotEquals(clone.getBoardArr()[0][0], board.getBoardArr()[0][0]);
|
||||
assertNotEquals(
|
||||
clone.getLog().getActiveColor(),
|
||||
board.getLog().getActiveColor()
|
||||
);
|
||||
}
|
||||
}
|
87
src/test/java/dev/kske/chess/board/FENStringTest.java
Normal file
@ -0,0 +1,87 @@
|
||||
package dev.kske.chess.board;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import dev.kske.chess.board.Piece.Color;
|
||||
import dev.kske.chess.exception.ChessException;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>FENStringTest.java</strong><br>
|
||||
* Created: <strong>24 Oct 2019</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
*/
|
||||
class FENStringTest {
|
||||
|
||||
private List<String> fenStrings = new ArrayList<>();
|
||||
private List<Board> boards = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Removes all pieces from a board
|
||||
*
|
||||
* @param board the board to clean
|
||||
*/
|
||||
void cleanBoard(Board board) {
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 8; j++)
|
||||
board.getBoardArr()[i][j] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
fenStrings.addAll(
|
||||
Arrays.asList(
|
||||
"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"
|
||||
)
|
||||
);
|
||||
Board board = new Board();
|
||||
board.set(Position.fromLAN("c7"), null);
|
||||
board.set(Position.fromLAN("c5"), new Pawn(Color.BLACK, board));
|
||||
board.set(Position.fromLAN("e4"), new Pawn(Color.WHITE, board));
|
||||
board.set(Position.fromLAN("f3"), new Knight(Color.WHITE, board));
|
||||
board.set(Position.fromLAN("e2"), null);
|
||||
board.set(Position.fromLAN("g1"), null);
|
||||
|
||||
board.getLog().setActiveColor(Color.BLACK);
|
||||
board.getLog().setHalfmoveClock(1);
|
||||
board.getLog().setFullmoveNumber(2);
|
||||
boards.add(board);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link FENString#toString()}.
|
||||
*/
|
||||
@Test
|
||||
void testToString() {
|
||||
for (int i = 0; i < fenStrings.size(); i++)
|
||||
assertEquals(
|
||||
fenStrings.get(i),
|
||||
new FENString(boards.get(i)).toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link FENString#getBoard()}.
|
||||
*
|
||||
* @throws ChessException
|
||||
*/
|
||||
@Test
|
||||
void testGetBoard() throws ChessException {
|
||||
for (int i = 0; i < boards.size(); i++)
|
||||
assertEquals(
|
||||
boards.get(i),
|
||||
new FENString(fenStrings.get(i)).getBoard()
|
||||
);
|
||||
}
|
||||
}
|
165
src/test/java/dev/kske/chess/board/LogTest.java
Normal file
@ -0,0 +1,165 @@
|
||||
package dev.kske.chess.board;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import dev.kske.chess.board.Piece.Color;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>LogTest.java</strong><br>
|
||||
* Created: <strong>13 Sep 2019</strong><br>
|
||||
* Author: <strong>Kai S. K. Engelbart</strong>
|
||||
*/
|
||||
class LogTest {
|
||||
|
||||
private Log log = new Log();
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#Log()}.
|
||||
*/
|
||||
@Test
|
||||
void testLog() {
|
||||
assertTrue(log.isEmpty());
|
||||
assertNull(log.getLast());
|
||||
assertNull(log.getRoot());
|
||||
assertEquals(log.getActiveColor(), Color.WHITE);
|
||||
assertNull(log.getEnPassant());
|
||||
assertEquals(log.getFullmoveNumber(), 1);
|
||||
assertEquals(log.getHalfmoveClock(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#Log(Log, boolean)}.
|
||||
*/
|
||||
@Test
|
||||
void testClone() {
|
||||
Log other = new Log(log, false);
|
||||
log.setActiveColor(Color.WHITE);
|
||||
other.setActiveColor(Color.BLACK);
|
||||
assertNotEquals(log.getActiveColor(), other.getActiveColor());
|
||||
log.add(Move.fromLAN("a2a4"), new Pawn(Color.WHITE, null), null);
|
||||
log.add(Move.fromLAN("a4a5"), new Pawn(Color.WHITE, null), null);
|
||||
other.add(Move.fromLAN("a2a4"), new Pawn(Color.WHITE, null), null);
|
||||
other.add(Move.fromLAN("a4a5"), new Pawn(Color.WHITE, null), null);
|
||||
assertNotEquals(log.getRoot(), other.getRoot());
|
||||
assertNotEquals(
|
||||
log.getRoot().getVariations(),
|
||||
other.getRoot().getVariations()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#add(Move, Piece, Piece)}.
|
||||
*/
|
||||
@Test
|
||||
void testAdd() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#removeLast()}.
|
||||
*/
|
||||
@Test
|
||||
void testRemoveLast() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#isEmpty()}.
|
||||
*/
|
||||
@Test
|
||||
void testIsEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#reset()}.
|
||||
*/
|
||||
@Test
|
||||
void testReset() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getRoot()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetRoot() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getLast()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetLast() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getEnPassant()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetEnPassant() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#setEnPassant(dev.kske.chess.board.Position)}.
|
||||
*/
|
||||
@Test
|
||||
void testSetEnPassant() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getActiveColor()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetActiveColor() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link Log#setActiveColor(dev.kske.chess.board.Piece.Color)}.
|
||||
*/
|
||||
@Test
|
||||
void testSetActiveColor() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getFullmoveNumber()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetFullmoveCounter() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#setFullmoveNumber(int)}.
|
||||
*/
|
||||
@Test
|
||||
void testSetFullmoveCounter() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#getHalfmoveClock()}.
|
||||
*/
|
||||
@Test
|
||||
void testGetHalfmoveClock() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Log#setHalfmoveClock(int)}.
|
||||
*/
|
||||
@Test
|
||||
void testSetHalfmoveClock() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
}
|
56
src/test/java/dev/kske/chess/board/PositionTest.java
Normal file
@ -0,0 +1,56 @@
|
||||
package dev.kske.chess.board;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>PositionTest.java</strong><br>
|
||||
* Created: <strong>24.07.2019</strong><br>
|
||||
* Author: <strong>Kai S. K. Engelbart</strong>
|
||||
*/
|
||||
class PositionTest {
|
||||
|
||||
private final int n = 4;
|
||||
private Position[] positions = new Position[] {
|
||||
new Position(0, 0),
|
||||
new Position(7, 7),
|
||||
new Position(0, 7),
|
||||
new Position(7, 0)
|
||||
};
|
||||
private String[] sans = new String[] {
|
||||
"a8", "h1", "a1", "h8"
|
||||
};
|
||||
private String[] strings = new String[] {
|
||||
"[0, 0]", "[7, 7]", "[0, 7]", "[7, 0]"
|
||||
};
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link Position#fromLAN(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
void testFromSAN() {
|
||||
for (int i = 0; i < n; i++)
|
||||
assertEquals(positions[i], Position.fromLAN(sans[i]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Position#toLAN()}.
|
||||
*/
|
||||
@Test
|
||||
void testToSAN() {
|
||||
for (int i = 0; i < n; i++)
|
||||
assertEquals(sans[i], positions[i].toLAN());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link Position#toString()}.
|
||||
*/
|
||||
@Test
|
||||
void testToString() {
|
||||
for (int i = 0; i < n; i++)
|
||||
assertEquals(strings[i], positions[i].toString());
|
||||
}
|
||||
}
|
33
src/test/java/dev/kske/chess/pgn/PGNDatabaseTest.java
Normal file
@ -0,0 +1,33 @@
|
||||
package dev.kske.chess.pgn;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import dev.kske.chess.exception.ChessException;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
* File: <strong>PGNDatabaseTest.java</strong><br>
|
||||
* Created: <strong>4 Oct 2019</strong><br>
|
||||
* Author: <strong>Kai S. K. Engelbart</strong>
|
||||
*/
|
||||
class PGNDatabaseTest {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link dev.kske.chess.pgn.PGNDatabase#load(java.io.File)}.
|
||||
*
|
||||
* @throws ChessException if an error occurs while parsing the file
|
||||
* @throws FileNotFoundException if the test file {@code test.pgn} is not
|
||||
* present
|
||||
*/
|
||||
@Test
|
||||
void testLoad() throws FileNotFoundException, ChessException {
|
||||
PGNDatabase db = new PGNDatabase();
|
||||
db.load(
|
||||
new File(getClass().getClassLoader().getResource("test.pgn").getFile())
|
||||
);
|
||||
}
|
||||
}
|
18
src/test/resources/test.pgn
Normal file
@ -0,0 +1,18 @@
|
||||
[Event "Test Game"]
|
||||
[Site "Test Environment"]
|
||||
[Date "2019.10.04"]
|
||||
[Round "1"]
|
||||
[Result "1-0"]
|
||||
[White "Kai Engelbart"]
|
||||
[Black "Kai Engelbart 2"]
|
||||
|
||||
1. e4 c5 2. Nf3 e6 3. d4 cxd4 4. Nxd4 a6 5. Bd3 Nf6 6. O-O d6
|
||||
7. c4 Bd7 8. Nc3 Nc6 9. Be3 Be7 10. h3 Ne5 11. Be2 Rc8 12. Qb3
|
||||
Qc7 13. Rac1 O-O 14. f4 Nc6 15. Nf3 Qb8 16. Qd1 Be8 17. Qd2
|
||||
Na5 18. b3 b6 19. Bd3 Nc6 20. Qf2 b5 21. Rfd1 Nb4 22. Bf1 bxc4
|
||||
23. bxc4 a5 24. Nd4 Qa8 25. Qf3 Na6 26. Ndb5 Nc5 27. e5 dxe5
|
||||
28. Qxa8 Rxa8 29. fxe5 Nfe4 30. Nd6 Bc6 31. Ncxe4 Nxe4 32. c5
|
||||
Ng3 33. Bc4 h5 34. Bf2 h4 35. Bxg3 hxg3 36. Bb5 Bxb5 37. Nxb5
|
||||
f6 38. Rd7 Bd8 39. Rc3 fxe5 40. Rxg3 Rf7 41. Rxf7 Kxf7 42. c6
|
||||
Bb6+ 43. Kf1 Kf8 44. c7 Rc8 45. a4 e4 46. Ke2 e5 47. Rg6 Bd4
|
||||
48. h4 Bb2 1-0
|