diff --git a/src/ChessGame.java b/src/ChessGame.java index 19a8897f1785f64fc824f72250b095b4a48c08e3..55ed57aeffa7e4e72d17a747c7ad858bdd7cb32b 100644 --- a/src/ChessGame.java +++ b/src/ChessGame.java @@ -1,15 +1,11 @@ -import java.lang.instrument.Instrumentation; -import java.util.ArrayList; -import java.util.Random; - public class ChessGame { - Player white; - Player black; - Position currentPos; + private Player white; + private Player black; + private Position currentPos; // moves list? - public ChessGame(Player white, Player black, Position currentPos) { + ChessGame(Player white, Player black, Position currentPos) { this.white = white; this.black = black; this.currentPos = currentPos; @@ -39,33 +35,6 @@ public class ChessGame { chess.currentPos = chess.currentPos.result(move); } - - - -// -// ArrayList<Move> legalMoves = pos.getLegalMoves(Color.WHITE); -// -// for (int i = 0; i < le1galMoves.size(); i++) { -// Move m = legalMoves.get(i); -// pos.result(m); -// System.out.println(pos); -// pos = new Position(savedpos.getBoard()); -// } - -// legalMoves = pos.getLegalMoves(Color.BLACK); -// -// for (int i = 0; i < legalMoves.size(); i++) { -// Move m = legalMoves.get(i); -// pos.result(m); -// System.out.println(pos); -// pos = new Position(); -// } - - - - - - } } \ No newline at end of file diff --git a/src/ComputerPlayer.java b/src/ComputerPlayer.java index 91d1b30297b35a999f45d9787000bf35c55224e3..32dbf56b7e9646d4ce812b9e1d4e431fcb1bfa5a 100644 --- a/src/ComputerPlayer.java +++ b/src/ComputerPlayer.java @@ -3,7 +3,7 @@ import java.util.Random; public class ComputerPlayer extends Player { - public ComputerPlayer(String name) { + ComputerPlayer(String name) { super(name); } @@ -14,5 +14,4 @@ public class ComputerPlayer extends Player { return legalMoves.get(random.nextInt(legalMoves.size())); } - } diff --git a/src/HumanPlayer.java b/src/HumanPlayer.java index bb77b21e8a021fab05fcf0ebef6373efc9abb1c1..e4fe5966a0971b5c0284d5c178ad3e31bef4016d 100644 --- a/src/HumanPlayer.java +++ b/src/HumanPlayer.java @@ -3,7 +3,7 @@ import java.util.Scanner; public class HumanPlayer extends Player { - public HumanPlayer(String name) { + HumanPlayer(String name) { super(name); } @@ -14,7 +14,7 @@ public class HumanPlayer extends Player { System.out.println(pos); - Move move = null; + Move move; boolean repeat = true; diff --git a/src/Move.java b/src/Move.java index 4506061be0feafa597ca17b2f65e90fd9fb09a6d..29b4be526681e01223b45028f7692d50527192c9 100644 --- a/src/Move.java +++ b/src/Move.java @@ -4,14 +4,14 @@ public class Move { int newX; int newY; - public Move(int oldX, int oldY, int newX, int newY) { + Move(int oldX, int oldY, int newX, int newY) { this.oldX = oldX; this.oldY = oldY; this.newX = newX; this.newY = newY; } - public Move(String move) { + Move(String move) { String letters = "abcdefgh"; this.oldX = letters.indexOf(move.charAt(0)); @@ -22,7 +22,7 @@ public class Move { } - public Move(int oldX, int oldY, Direction dir) { + Move(int oldX, int oldY, Direction dir) { this.oldX = oldX; this.oldY = oldY; diff --git a/src/Piece.java b/src/Piece.java index 227e8d09d58d8c5f991339f30f35592535b19d43..5b2967f20179ee674e36e17128e49d82a345aca6 100644 --- a/src/Piece.java +++ b/src/Piece.java @@ -2,7 +2,7 @@ public class Piece { Color color; Type type; - public Piece(Color color, Type type) { + Piece(Color color, Type type) { this.color = color; this.type = type; } diff --git a/src/Player.java b/src/Player.java index d15397a1709e8fa36cfe9273eb05d88599bdd182..fe9ee01b595f0d29564c0d39bc53062390a10052 100644 --- a/src/Player.java +++ b/src/Player.java @@ -1,9 +1,7 @@ -import java.util.ArrayList; - public abstract class Player { String name; - public Player(String name) { + Player(String name) { this.name = name; } diff --git a/src/Position.java b/src/Position.java index 24210b1206f445513d55fba6626fb6b57258fbc1..d903190b485f2ecee1f78920f5c5b9082dda0cb3 100644 --- a/src/Position.java +++ b/src/Position.java @@ -1,19 +1,11 @@ -import javafx.geometry.Pos; - import java.util.ArrayList; -import java.util.Arrays; public class Position { private Square[][] board; - - public Color getMovesNext() { - return movesNext; - } - private Color movesNext; // initial position (state) - public Position() { + Position() { movesNext = Color.WHITE; board = new Square[8][8]; @@ -59,7 +51,7 @@ public class Position { } // copy position with this constructor - public Position(Position pos) { + Position(Position pos) { Square[][] boardCopy = new Square[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { @@ -70,7 +62,7 @@ public class Position { this.movesNext = pos.movesNext; } - public Position result(Move move) { + Position result(Move move) { Position posCopy = new Position(this); Piece p = posCopy.board[move.oldY][move.oldX].getPiece(); @@ -87,11 +79,15 @@ public class Position { return posCopy; } - public Piece getPieceAt(int x, int y) { + Color getMovesNext() { + return movesNext; + } + + Piece getPieceAt(int x, int y) { return board[y][x].getPiece(); } - public Location getPieceLocation(Piece piece) { + Location getPieceLocation(Piece piece) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (!board[i][j].isEmpty()) { @@ -106,7 +102,7 @@ public class Position { return null; } - public ArrayList<Piece> getPieces() { + ArrayList<Piece> getPieces() { ArrayList<Piece> pieces = new ArrayList<>(); for (int i = 0; i < 8; i++) { @@ -301,14 +297,17 @@ public class Position { sb.append(" a b c d e f g h \n"); return sb.toString(); } -} -class Location { - int x; - int y; + class Location { + int x; + int y; - public Location(int x, int y) { - this.x = x; - this.y = y; + public Location(int x, int y) { + this.x = x; + this.y = y; + } } + } + + diff --git a/src/Square.java b/src/Square.java index 33d017d9ae550692b04d20d3415391e8ee72ceca..f0de340d01f6420ad34f32d24fa9da90b8bd768d 100644 --- a/src/Square.java +++ b/src/Square.java @@ -1,18 +1,18 @@ public class Square { private Piece piece; - public Square() { + Square() { } - public Square(Piece piece) { + Square(Piece piece) { this.piece = piece; } - public Piece getPiece() { + Piece getPiece() { return piece; } - public void setPiece(Piece piece) { + void setPiece(Piece piece) { this.piece = piece; } @@ -25,7 +25,7 @@ public class Square { return piece == null; } - public Square deepCopy () { + Square deepCopy () { if(isEmpty()) { return new Square(); }