No static :)
This commit is contained in:
parent
7dc1378bbc
commit
2db80d8b31
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
public class AutoPlayer {
|
public class AutoPlayer {
|
||||||
|
private PieceCreation pc = new PieceCreation();
|
||||||
private KingCheck kingCheck = new KingCheck();
|
private KingCheck kingCheck = new KingCheck();
|
||||||
public int MAX_DEPTH;
|
public int MAX_DEPTH;
|
||||||
public AutoPlayer() {}
|
public AutoPlayer() {}
|
||||||
|
|
@ -175,7 +176,7 @@ public class AutoPlayer {
|
||||||
ArrayList<Piece> newRow = new ArrayList<>();
|
ArrayList<Piece> newRow = new ArrayList<>();
|
||||||
for (Piece p : row) {
|
for (Piece p : row) {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
newRow.add(PieceCreation.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
||||||
} else {
|
} else {
|
||||||
newRow.add(null);
|
newRow.add(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import java.util.LinkedList;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
|
private PieceCreation pc = new PieceCreation();
|
||||||
private KingCheck kingCheck = new KingCheck();
|
private KingCheck kingCheck = new KingCheck();
|
||||||
private SoundEffect soundEffect = new SoundEffect();
|
private SoundEffect soundEffect = new SoundEffect();
|
||||||
private int width = 8;
|
private int width = 8;
|
||||||
|
|
@ -59,7 +60,7 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
|
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
|
||||||
Piece piece = PieceCreation.createPiece(x,y,type,isWhite);
|
Piece piece = pc.createPiece(x,y,type,isWhite);
|
||||||
board.get(y).set(x, piece);
|
board.get(y).set(x, piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ public class BoardHistory {
|
||||||
public int turnNumber;
|
public int turnNumber;
|
||||||
public boolean turnColor;
|
public boolean turnColor;
|
||||||
public Move lastMove;
|
public Move lastMove;
|
||||||
|
private PieceCreation pc = new PieceCreation();
|
||||||
public BoardHistory(ArrayList<ArrayList<Piece>> board, int turnNumber, boolean turnColor, Move lastMove) {
|
public BoardHistory(ArrayList<ArrayList<Piece>> board, int turnNumber, boolean turnColor, Move lastMove) {
|
||||||
this.board = deepCopyBoard(board);
|
this.board = deepCopyBoard(board);
|
||||||
this.turnNumber = turnNumber;
|
this.turnNumber = turnNumber;
|
||||||
|
|
@ -21,7 +22,7 @@ public class BoardHistory {
|
||||||
ArrayList<Piece> newRow = new ArrayList<>();
|
ArrayList<Piece> newRow = new ArrayList<>();
|
||||||
for (Piece p : row) {
|
for (Piece p : row) {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
newRow.add(PieceCreation.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
||||||
} else {
|
} else {
|
||||||
newRow.add(null);
|
newRow.add(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ public class FileBoard {
|
||||||
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
|
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
|
||||||
public int turnNumber;
|
public int turnNumber;
|
||||||
public boolean turnColor;
|
public boolean turnColor;
|
||||||
|
private PieceCreation pc = new PieceCreation();
|
||||||
public FileBoard(ArrayList<ArrayList<Piece>> board,int turnNumber, boolean turnColor) {
|
public FileBoard(ArrayList<ArrayList<Piece>> board,int turnNumber, boolean turnColor) {
|
||||||
this.board = board;
|
this.board = board;
|
||||||
this.turnColor = turnColor;
|
this.turnColor = turnColor;
|
||||||
|
|
@ -70,7 +71,7 @@ public class FileBoard {
|
||||||
color = pieceChar.charAt(0);
|
color = pieceChar.charAt(0);
|
||||||
type = pieceChar.charAt(1);
|
type = pieceChar.charAt(1);
|
||||||
col = color == 'W';
|
col = color == 'W';
|
||||||
Piece piece = PieceCreation.createPiece(x,y,PieceType.fromSummary(type),col);
|
Piece piece = pc.createPiece(x,y,PieceType.fromSummary(type),col);
|
||||||
boardF.get(y).set(x, piece);
|
boardF.get(y).set(x, piece);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ public class KingCheck {
|
||||||
private boolean opponentWasInCheck = false;
|
private boolean opponentWasInCheck = false;
|
||||||
private SoundEffect soundEffect = new SoundEffect();
|
private SoundEffect soundEffect = new SoundEffect();
|
||||||
private boolean soundShouldPlay = true;
|
private boolean soundShouldPlay = true;
|
||||||
|
private PieceCreation pc = new PieceCreation();
|
||||||
public ArrayList<ArrayList<Boolean>> getLegalMoves(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove) {
|
public ArrayList<ArrayList<Boolean>> getLegalMoves(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove) {
|
||||||
ArrayList<ArrayList<Boolean>> rawMoves = piece.getPossibleMoves(board,lastMove);
|
ArrayList<ArrayList<Boolean>> rawMoves = piece.getPossibleMoves(board,lastMove);
|
||||||
|
|
||||||
|
|
@ -88,7 +89,7 @@ public class KingCheck {
|
||||||
ArrayList<Piece> newRow = new ArrayList<>();
|
ArrayList<Piece> newRow = new ArrayList<>();
|
||||||
for (Piece p : row) {
|
for (Piece p : row) {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
newRow.add(PieceCreation.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
newRow.add(pc.createPiece(p.getX(), p.getY(), p.getType(), p.isWhite()));
|
||||||
} else {
|
} else {
|
||||||
newRow.add(null);
|
newRow.add(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class PieceCreation {
|
public class PieceCreation {
|
||||||
|
public Piece createPiece(int x, int y, PieceType type, boolean isWhite) {
|
||||||
public static Piece createPiece(int x, int y, PieceType type, boolean isWhite) {
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Pawn: return new Pawn(x, y, isWhite);
|
case Pawn: return new Pawn(x, y, isWhite);
|
||||||
case Rook: return new Rook(x, y, isWhite);
|
case Rook: return new Rook(x, y, isWhite);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue