Nick Stolbov
3 years ago
2 changed files with 84 additions and 0 deletions
@ -0,0 +1,30 @@ |
|||
package Game.ChessObj; |
|||
|
|||
public class ChessBoard { |
|||
|
|||
private ChessFigure[][] board; |
|||
|
|||
public ChessBoard() { |
|||
board = new ChessFigure[8][8]; |
|||
initBoard(); |
|||
} |
|||
|
|||
protected void initBoard() { |
|||
ChessFigure.Type[] order = { |
|||
ChessFigure.Type.CASTLE, ChessFigure.Type.KNIGHT, ChessFigure.Type.BISHOP, ChessFigure.Type.QUEEN, ChessFigure.Type.KING, ChessFigure.Type.BISHOP, ChessFigure.Type.KNIGHT, ChessFigure.Type.CASTLE |
|||
}; |
|||
for (int i = 0; i < board.length; i++) { |
|||
//sets all pawns |
|||
board[i][1] = new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK); |
|||
board[i][6] = new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE); |
|||
|
|||
//sets all others |
|||
board[i][0] = new ChessFigure(order[i], ChessFigure.Team.BLACK); |
|||
board[i][7] = new ChessFigure(order[i], ChessFigure.Team.WHITE); |
|||
} |
|||
} |
|||
|
|||
public ChessFigure[][] getBoard() { |
|||
return this.board; |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
package Game.ChessObj; |
|||
|
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
class ChessBoardTest { |
|||
|
|||
ChessFigure.Type[] startOrder = { |
|||
ChessFigure.Type.CASTLE, ChessFigure.Type.KNIGHT, ChessFigure.Type.BISHOP, ChessFigure.Type.QUEEN, ChessFigure.Type.KING, ChessFigure.Type.BISHOP, ChessFigure.Type.KNIGHT, ChessFigure.Type.CASTLE |
|||
}; |
|||
|
|||
ChessBoard chessBoard; |
|||
|
|||
@BeforeEach |
|||
void setUp() { |
|||
chessBoard = new ChessBoard(); |
|||
} |
|||
|
|||
@AfterEach |
|||
void tearDown() { |
|||
} |
|||
|
|||
@Test |
|||
void initBoard() { |
|||
ChessFigure[][] board = chessBoard.getBoard(); |
|||
for (int x = 0; x < board.length; x++) { |
|||
for (int y = 0; y < board[0].length; y++) { |
|||
//test pawns |
|||
if (y == 1) { |
|||
assertEquals(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK), board[x][y]); |
|||
continue; |
|||
} |
|||
if(y == 6) { |
|||
assertEquals(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE), board[x][y]); |
|||
continue; |
|||
} |
|||
|
|||
if(y == 0){ |
|||
assertEquals(new ChessFigure(startOrder[x], ChessFigure.Team.BLACK), board[x][y]); |
|||
continue; |
|||
} |
|||
if(y == 7){ |
|||
assertEquals(new ChessFigure(startOrder[x], ChessFigure.Team.WHITE), board[x][y]); |
|||
continue; |
|||
} |
|||
//rest should be empty(null) |
|||
assertNull(board[x][y]); |
|||
} |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue