This commit is contained in:
@@ -72,9 +72,7 @@ public abstract class AI extends GameAdaptator{
|
||||
|
||||
protected CommandResult sendCommand(Command command, CommandExecutor commandExecutor) {
|
||||
CommandResult result = commandExecutor.executeCommand(command);
|
||||
if(result == CommandResult.NotAllowed){
|
||||
System.out.println("eeeeee");
|
||||
}
|
||||
assert result != CommandResult.NotAllowed : "Command not allowed!";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,4 @@ public abstract class Piece {
|
||||
|
||||
public abstract <T> T accept(PieceVisitor<T> visitor);
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object other);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,4 @@ public class Bishop extends Piece {
|
||||
return visitor.visitPiece(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Bishop && ((Bishop) obj).getColor() == this.getColor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,13 +14,4 @@ public class King extends Piece {
|
||||
public <T> T accept(PieceVisitor<T> visitor) {
|
||||
return visitor.visitPiece(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof King && ((King) obj).getColor() == this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,4 @@ public class Knight extends Piece {
|
||||
return visitor.visitPiece(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Knight && ((Knight) obj).getColor() == this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,4 @@ public class Pawn extends Piece {
|
||||
return getColor() == Color.White ? 1 : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Pawn && ((Pawn) obj).getColor() == this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,5 @@ public class Queen extends Piece {
|
||||
return visitor.visitPiece(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof Queen && ((Queen) obj).getColor() == this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,4 @@ public class Rook extends Piece {
|
||||
return visitor.visitPiece(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof Rook && ((Rook) other).getColor() == this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package chess.model.visitor;
|
||||
|
||||
import chess.model.Color;
|
||||
import chess.model.Piece;
|
||||
import chess.model.PieceVisitor;
|
||||
import chess.model.pieces.*;
|
||||
|
||||
public class KingIdentifier implements PieceVisitor<Boolean> {
|
||||
|
||||
private final Color color;
|
||||
|
||||
public KingIdentifier(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public boolean isKing(Piece piece) {
|
||||
if (piece == null)
|
||||
return false;
|
||||
return visit(piece);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Bishop bishop) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(King king) {
|
||||
return king.getColor() == color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Knight knight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Pawn pawn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Queen queen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitPiece(Rook rook) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,12 @@
|
||||
package chess.pgn;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.view.AssetManager;
|
||||
import common.AssetManager;
|
||||
|
||||
public class PgnFileSimulator extends PgnSimulator{
|
||||
|
||||
private static String readResource(String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(AssetManager.getResource(path)));
|
||||
reader.lines().forEach((line) -> builder.append(line + "\n"));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public PgnFileSimulator(CommandExecutor commandExecutor, String fileName) {
|
||||
super(commandExecutor, readResource(fileName));
|
||||
super(commandExecutor, AssetManager.getResourceAsString(fileName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@ import java.util.List;
|
||||
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.controller.commands.NewGameCommand;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Game;
|
||||
import common.Signal0;
|
||||
|
||||
public class PgnSimulator extends GameAdaptator {
|
||||
|
||||
private final CommandExecutor commandExecutor;
|
||||
private final String pgn;
|
||||
|
||||
public final Signal0 onComplete = new Signal0();
|
||||
|
||||
public PgnSimulator(CommandExecutor commandExecutor, String pgn) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.pgn = pgn;
|
||||
@@ -23,6 +24,7 @@ public class PgnSimulator extends GameAdaptator {
|
||||
public void onGameStart() {
|
||||
List<PlayerCommand> cmds = PgnImport.importGame(this.pgn);
|
||||
this.commandExecutor.executeCommands(cmds);
|
||||
this.onComplete.emit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package chess.view;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssetManager {
|
||||
|
||||
private static final String gradleBase = "app/src/main/resources/";
|
||||
|
||||
public static InputStream getResource(String name) {
|
||||
// we first search it in files
|
||||
InputStream inputStream = getFileInputStream(name);
|
||||
if (inputStream != null)
|
||||
return inputStream;
|
||||
|
||||
inputStream = getFileInputStream(gradleBase + name);
|
||||
if (inputStream != null)
|
||||
return inputStream;
|
||||
// then in the jar
|
||||
return ClassLoader.getSystemResourceAsStream(name);
|
||||
}
|
||||
|
||||
private static InputStream getFileInputStream(String path) {
|
||||
File f = new File(path);
|
||||
if (f.exists()) {
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
return fis;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import chess.view.AssetManager;
|
||||
import common.AssetManager;
|
||||
|
||||
public class AudioFiles {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import chess.model.pieces.Knight;
|
||||
import chess.model.pieces.Pawn;
|
||||
import chess.model.pieces.Queen;
|
||||
import chess.model.pieces.Rook;
|
||||
import chess.view.AssetManager;
|
||||
import common.AssetManager;
|
||||
|
||||
public class PieceIcon implements PieceVisitor<String> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user