Compare commits
1 Commits
17ef882d44
...
failed
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ac7b4ad65 |
@@ -5,13 +5,14 @@ package chess;
|
||||
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Game;
|
||||
import chess.simulator.PromoteTest;
|
||||
import chess.view.consolerender.Console;
|
||||
|
||||
public class ConsoleMain {
|
||||
public static void main(String[] args) {
|
||||
Game game = new Game();
|
||||
Game game = new Game(new ChessBoard());
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
PromoteTest promoteTest = new PromoteTest(commandExecutor);
|
||||
|
||||
33
app/src/main/java/chess/OpenGLMain.java
Normal file
33
app/src/main/java/chess/OpenGLMain.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package chess;
|
||||
|
||||
import chess.ai.DumbAI;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
import chess.pgn.PgnExport;
|
||||
import chess.view.render.Window;
|
||||
|
||||
public class OpenGLMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Game game = new Game(new ChessBoard());
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
Window window = new Window(commandExecutor);
|
||||
commandExecutor.addListener(window);
|
||||
|
||||
// DumbAI ai = new DumbAI(commandExecutor, Color.Black);
|
||||
// commandExecutor.addListener(ai);
|
||||
|
||||
// DumbAI ai2 = new DumbAI(commandExecutor, Color.White);
|
||||
// commandExecutor.addListener(ai2);
|
||||
|
||||
commandExecutor.executeCommand(new NewGameCommand());
|
||||
|
||||
window.run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import chess.ai.DumbAI;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
import chess.pgn.PgnExport;
|
||||
@@ -11,7 +12,7 @@ import chess.view.simplerender.Window;
|
||||
|
||||
public class SwingMain {
|
||||
public static void main(String[] args) {
|
||||
Game game = new Game();
|
||||
Game game = new Game(new ChessBoard());
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
Window window = new Window(commandExecutor, false);
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package chess.ai;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.commands.GetPlayerMovesCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
|
||||
public abstract class AI extends GameAdaptator{
|
||||
|
||||
protected final CommandExecutor commandExecutor;
|
||||
protected final Color color;
|
||||
|
||||
public AI(CommandExecutor commandExecutor, Color color) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
protected abstract void play();
|
||||
protected abstract void promote(Coordinate pawnCoords);
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
if (this.color != color || undone)
|
||||
return;
|
||||
|
||||
play();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
Piece pawn = pieceAt(pieceCoords);
|
||||
if (pawn.getColor() != this.color)
|
||||
return;
|
||||
promote(pieceCoords);
|
||||
}
|
||||
|
||||
protected Piece pieceAt(Coordinate coordinate) {
|
||||
GetPieceAtCommand command = new GetPieceAtCommand(coordinate);
|
||||
sendCommand(command);
|
||||
return command.getPiece();
|
||||
}
|
||||
|
||||
protected List<Move> getAllowedMoves() {
|
||||
GetPlayerMovesCommand cmd = new GetPlayerMovesCommand();
|
||||
sendCommand(cmd);
|
||||
return cmd.getMoves();
|
||||
}
|
||||
|
||||
protected CastlingResult getAllowedCastlings() {
|
||||
GetAllowedCastlingsCommand cmd2 = new GetAllowedCastlingsCommand();
|
||||
sendCommand(cmd2);
|
||||
return cmd2.getCastlingResult();
|
||||
}
|
||||
|
||||
protected void sendCommand(Command command) {
|
||||
this.commandExecutor.executeCommand(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,28 +3,46 @@ package chess.ai;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.commands.GetPlayerMovesCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.GetAllowedCastlingsCommand.CastlingResult;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
|
||||
public class DumbAI extends AI {
|
||||
public class DumbAI extends GameAdaptator {
|
||||
|
||||
private final Color player;
|
||||
private final CommandExecutor commandExecutor;
|
||||
private final Random random = new Random();
|
||||
|
||||
public DumbAI(CommandExecutor commandExecutor, Color color) {
|
||||
super(commandExecutor, color);
|
||||
this.player = color;
|
||||
this.commandExecutor = commandExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void play() {
|
||||
CastlingResult castlings = getAllowedCastlings();
|
||||
List<Move> moves = getAllowedMoves();
|
||||
public void onPlayerTurn(Color color) {
|
||||
if (color != player)
|
||||
return;
|
||||
|
||||
GetPlayerMovesCommand cmd = new GetPlayerMovesCommand();
|
||||
sendCommand(cmd);
|
||||
|
||||
GetAllowedCastlingsCommand cmd2 = new GetAllowedCastlingsCommand();
|
||||
sendCommand(cmd2);
|
||||
|
||||
CastlingResult castlings = cmd2.getCastlingResult();
|
||||
List<Move> moves = cmd.getMoves();
|
||||
|
||||
switch (castlings) {
|
||||
case Both: {
|
||||
@@ -35,12 +53,20 @@ public class DumbAI extends AI {
|
||||
return;
|
||||
}
|
||||
|
||||
case Small:
|
||||
case Small: {
|
||||
int randomMove = this.random.nextInt(moves.size() + 1);
|
||||
if (randomMove != moves.size())
|
||||
break;
|
||||
this.commandExecutor.executeCommand(new CastlingCommand(false));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
case Big: {
|
||||
int randomMove = this.random.nextInt(moves.size() + 1);
|
||||
if (randomMove != moves.size())
|
||||
break;
|
||||
this.commandExecutor.executeCommand(new CastlingCommand(castlings == CastlingResult.Big));
|
||||
this.commandExecutor.executeCommand(new CastlingCommand(true));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,12 +76,27 @@ public class DumbAI extends AI {
|
||||
|
||||
int randomMove = this.random.nextInt(moves.size());
|
||||
this.commandExecutor.executeCommand(new MoveCommand(moves.get(randomMove)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void promote(Coordinate pawnCoords) {
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
Piece pawn = pieceAt(pieceCoords);
|
||||
if (pawn.getColor() != this.player)
|
||||
return;
|
||||
|
||||
int promote = this.random.nextInt(PromoteType.values().length);
|
||||
this.commandExecutor.executeCommand(new PromoteCommand(PromoteType.values()[promote]));
|
||||
}
|
||||
|
||||
private Piece pieceAt(Coordinate coordinate) {
|
||||
GetPieceAtCommand command = new GetPieceAtCommand(coordinate);
|
||||
sendCommand(command);
|
||||
return command.getPiece();
|
||||
}
|
||||
|
||||
private void sendCommand(Command command) {
|
||||
this.commandExecutor.executeCommand(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,14 +57,14 @@ public class CommandExecutor {
|
||||
this.dispatcher.onGameEnd();
|
||||
return;
|
||||
}
|
||||
switchPlayerTurn(command instanceof UndoCommand);
|
||||
switchPlayerTurn();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void switchPlayerTurn(boolean undone) {
|
||||
private void switchPlayerTurn() {
|
||||
this.game.switchPlayerTurn();
|
||||
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn(), undone);
|
||||
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ public class NewGameCommand extends Command {
|
||||
game.reset();
|
||||
|
||||
outputSystem.onGameStart();
|
||||
outputSystem.onPlayerTurn(game.getPlayerTurn(), false);
|
||||
outputSystem.onPlayerTurn(game.getPlayerTurn());
|
||||
|
||||
return CommandResult.NotMoved;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EmptyGameDispatcher extends GameDispatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
public void onPlayerTurn(Color color) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ import chess.model.Move;
|
||||
public abstract class GameAdaptator implements GameListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {}
|
||||
public void onPlayerTurn(Color color) {}
|
||||
|
||||
@Override
|
||||
public void onWin(Color color) {}
|
||||
|
||||
@@ -29,8 +29,8 @@ public class GameDispatcher implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
asyncForEachCall((l) -> l.onPlayerTurn(color, undone));
|
||||
public void onPlayerTurn(Color color) {
|
||||
asyncForEachCall((l) -> l.onPlayerTurn(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,9 +56,8 @@ public interface GameListener {
|
||||
/**
|
||||
* Invoked when it's the player turn
|
||||
* @param color the color of the player who should play
|
||||
* @param undone true if it's a result of an undo command
|
||||
*/
|
||||
void onPlayerTurn(Color color, boolean undone);
|
||||
void onPlayerTurn(Color color);
|
||||
|
||||
/**
|
||||
* Invoked when a pawn should be promoted
|
||||
|
||||
@@ -20,8 +20,8 @@ public class Game {
|
||||
Draw, Check, CheckMate, OnGoing, Pat;
|
||||
}
|
||||
|
||||
public Game() {
|
||||
this.board = new ChessBoard();
|
||||
public Game(ChessBoard board) {
|
||||
this.board = board;
|
||||
this.movesHistory = new Stack<>();
|
||||
this.traitsPos = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.event.EmptyGameDispatcher;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
@@ -21,7 +22,7 @@ import chess.model.pieces.Pawn;
|
||||
public class PgnExport {
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// final Game game = new Game();
|
||||
// final Game game = new Game(new ChessBoard());
|
||||
// final CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
// DumbAI ai1 = new DumbAI(commandExecutor, Color.White);
|
||||
@@ -189,7 +190,8 @@ public class PgnExport {
|
||||
|
||||
public static String exportGame(Game game) {
|
||||
|
||||
Game virtualGame = new Game();
|
||||
ChessBoard board = new ChessBoard();
|
||||
Game virtualGame = new Game(board);
|
||||
|
||||
CommandExecutor executor = new CommandExecutor(virtualGame, new EmptyGameDispatcher());
|
||||
executor.executeCommand(new NewGameCommand());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Console implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
public void onPlayerTurn(Color color) {
|
||||
if (!captureInput)
|
||||
return;
|
||||
System.out.println(Colors.RED + "Player turn: " + color + Colors.RESET);
|
||||
|
||||
@@ -3,6 +3,7 @@ package chess.view.render;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import chess.model.Coordinate;
|
||||
import chess.view.render.shader.BoardShader;
|
||||
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
@@ -59,16 +60,42 @@ public class Renderer {
|
||||
return positions;
|
||||
}
|
||||
|
||||
private Coordinate GetCellFromColor(Vector3f color) {
|
||||
int offset = 1;
|
||||
|
||||
if (color.x > 0.5) {
|
||||
color = new Vector3f(1.0f, 1.0f, 1.0f).sub(color);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
int r = (int) (color.x * 255.0f);
|
||||
int g = (int) (color.y * 255.0f);
|
||||
int b = (int) (color.z * 255.0f);
|
||||
|
||||
int index = (r + g + b) * 2 + offset;
|
||||
|
||||
return Coordinate.fromIndex(index);
|
||||
}
|
||||
|
||||
private Vector3f GetCellColor(int x, int y) {
|
||||
float index = (y * BOARD_WIDTH + x) / 2.0f;
|
||||
float r = (int) (index / 3) / 255.0f;
|
||||
float g = (int) ((index + 1) / 3) / 255.0f;
|
||||
float b = (int) ((index + 2) / 3) / 255.0f;
|
||||
if ((x + y) % 2 != 0) {
|
||||
System.out.println(GetCellFromColor(new Vector3f(1.0f - r - 1.0f / 255.0f, 1.0f - g - 1.0f / 255.0f, 1.0f - b - 1.0f / 255.0f)));
|
||||
return new Vector3f(1.0f - r - 1.0f / 255.0f, 1.0f - g - 1.0f / 255.0f, 1.0f - b - 1.0f / 255.0f);
|
||||
} else {
|
||||
System.out.println(GetCellFromColor(new Vector3f(r, g, b)));
|
||||
return new Vector3f(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
private float[] GetBoardColors() {
|
||||
float[] colors = new float[BOARD_SIZE * SQUARE_VERTEX_COUNT * 3];
|
||||
for (int i = 0; i < BOARD_WIDTH; i++) {
|
||||
for (int j = 0; j < BOARD_HEIGHT; j++) {
|
||||
Vector3f color;
|
||||
if ((i + j) % 2 != 0) {
|
||||
color = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
} else {
|
||||
color = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
for (int j = 0; j < BOARD_HEIGHT; j++) {
|
||||
for (int i = 0; i < BOARD_WIDTH; i++) {
|
||||
Vector3f color = GetCellColor(i, j);
|
||||
int squareIndex = i * BOARD_WIDTH + j;
|
||||
for (int k = 0; k < SQUARE_VERTEX_COUNT; k++) {
|
||||
colors[squareIndex * SQUARE_VERTEX_COUNT * 3 + k * 3] = color.x;
|
||||
@@ -109,6 +136,12 @@ public class Renderer {
|
||||
this.vao.Unbind();
|
||||
}
|
||||
|
||||
public Coordinate GetSelectedCell() {
|
||||
float pixels[] = new float[3];
|
||||
GL30.glReadPixels(500, 500, 1, 1, GL_RGB, GL_FLOAT, pixels);
|
||||
return GetCellFromColor(new Vector3f(pixels[0], pixels[1], pixels[2]));
|
||||
}
|
||||
|
||||
public void Render(Camera cam) {
|
||||
this.shader.Start();
|
||||
this.shader.SetCamMatrix(cam.getMatrix());
|
||||
|
||||
@@ -5,6 +5,12 @@ import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.lwjgl.system.*;
|
||||
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import static org.lwjgl.glfw.Callbacks.*;
|
||||
@@ -13,17 +19,20 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.system.MemoryStack.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
public class Window {
|
||||
public class Window implements GameListener{
|
||||
|
||||
// The window handle
|
||||
private long window;
|
||||
|
||||
private final CommandExecutor commandExecutor;
|
||||
|
||||
private Renderer renderer;
|
||||
private Camera cam;
|
||||
|
||||
public Window() {
|
||||
public Window(CommandExecutor commandExecutor) {
|
||||
this.renderer = new Renderer();
|
||||
this.cam = new Camera();
|
||||
this.commandExecutor = new CommandExecutor();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -114,6 +123,8 @@ public class Window {
|
||||
|
||||
render();
|
||||
|
||||
System.out.println(this.renderer.GetSelectedCell());
|
||||
|
||||
glfwSwapBuffers(window); // swap the color buffers
|
||||
|
||||
// Poll for window events. The key callback above will only be
|
||||
@@ -132,4 +143,82 @@ public class Window {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBoardUpdate() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onBoardUpdate'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onDraw'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameEnd() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onGameEnd'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameStart() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onGameStart'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKingInCheck() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onKingInCheck'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKingInMat() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onKingInMat'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onMove'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onMoveNotAllowed'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPatSituation() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onPatSituation'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(Color color) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onPlayerTurn'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onPromotePawn'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurrender(Color coward) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onSurrender'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWin(Color winner) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'onWin'");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class Window extends JFrame implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTurn(chess.model.Color color, boolean undone) {
|
||||
public void onPlayerTurn(chess.model.Color color) {
|
||||
this.displayText.setText("Current turn: " + color);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@@ -3,20 +3,24 @@
|
||||
*/
|
||||
package chess;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import chess.ai.DumbAI;
|
||||
import chess.controller.Command;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.commands.UndoCommand;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
import chess.model.*;
|
||||
import chess.model.pieces.*;
|
||||
import chess.simulator.Simulator;
|
||||
import chess.view.simplerender.Window;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
class AppTest {
|
||||
@Test void functionalRollback(){
|
||||
Game game = new Game();
|
||||
Game game = new Game(new ChessBoard());
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
DumbAI ai = new DumbAI(commandExecutor, Color.Black);
|
||||
@@ -34,9 +38,9 @@ class AppTest {
|
||||
result = commandExecutor.executeCommand(new UndoCommand());
|
||||
} while (result != Command.CommandResult.NotAllowed);
|
||||
|
||||
Game initialGame = new Game();
|
||||
Game initialGame = new Game(new ChessBoard());
|
||||
CommandExecutor initialCommandExecutor = new CommandExecutor(initialGame);
|
||||
initialCommandExecutor.executeCommand(new NewGameCommand());
|
||||
commandExecutor.executeCommand(new NewGameCommand());
|
||||
|
||||
assert(game.getBoard().equals(initialGame.getBoard()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user