From 5abc51688b90f9d8110f4f5f0bc705a712d91346 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 25 Jul 2019 21:38:49 +0200 Subject: [PATCH] Added log resetting, disabled resizing in MainFrame --- src/dev/kske/chess/board/Board.java | 7 ++++--- src/dev/kske/chess/board/Log.java | 5 +++++ src/dev/kske/chess/game/ai/MoveProcessor.java | 14 +++++++------- src/dev/kske/chess/ui/MainWindow.java | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/dev/kske/chess/board/Board.java b/src/dev/kske/chess/board/Board.java index 9b654e4..c57064b 100644 --- a/src/dev/kske/chess/board/Board.java +++ b/src/dev/kske/chess/board/Board.java @@ -168,8 +168,6 @@ public class Board implements Cloneable { // Move the rook Move rookMove = move.dest.x == 6 ? new Move(5, move.pos.y, 7, move.pos.y) // Kingside : new Move(3, move.pos.y, 0, move.pos.y); // Queenside - - // Move the rook setDest(rookMove, getPos(rookMove)); setPos(rookMove, null); @@ -278,7 +276,8 @@ public class Board implements Cloneable { public GameState getGameEventType(Color color) { return checkCheck(color) ? checkCheckmate(color) ? GameState.CHECKMATE : GameState.CHECK - : getMoves(color).isEmpty() ? GameState.STALEMATE : GameState.NORMAL; + : getMoves(color).isEmpty() || log.getLast().halfmoveClock >= 50 ? GameState.STALEMATE + : GameState.NORMAL; } /** @@ -369,6 +368,8 @@ public class Board implements Cloneable { blackCastling.put(Type.QUEEN, true); castlingRights.put(Color.WHITE, whiteCastling); castlingRights.put(Color.BLACK, blackCastling); + + log.reset(); } /** diff --git a/src/dev/kske/chess/board/Log.java b/src/dev/kske/chess/board/Log.java index 6211983..8a66a33 100644 --- a/src/dev/kske/chess/board/Log.java +++ b/src/dev/kske/chess/board/Log.java @@ -49,6 +49,11 @@ public class Log implements Cloneable { } } + public void reset() { + moves.clear(); + activeColor = Color.WHITE; + } + @Override public Object clone() { Log log = null; diff --git a/src/dev/kske/chess/game/ai/MoveProcessor.java b/src/dev/kske/chess/game/ai/MoveProcessor.java index c32ca08..5042b0d 100644 --- a/src/dev/kske/chess/game/ai/MoveProcessor.java +++ b/src/dev/kske/chess/game/ai/MoveProcessor.java @@ -24,10 +24,10 @@ public class MoveProcessor implements Callable { private Move bestMove; public MoveProcessor(Board board, List rootMoves, Color color, int maxDepth, int alphaBetaThreshold) { - this.board = board; - this.rootMoves = rootMoves; - this.color = color; - this.maxDepth = maxDepth; + this.board = board; + this.rootMoves = rootMoves; + this.color = color; + this.maxDepth = maxDepth; this.alphaBetaThreshold = alphaBetaThreshold; } @@ -41,9 +41,9 @@ public class MoveProcessor implements Callable { int bestValue = Integer.MIN_VALUE; for (Move move : moves) { board.move(move); - int teamValue = board.evaluate(color); - int enemyValue = board.evaluate(color.opposite()); - int valueChange = teamValue - enemyValue; + int teamValue = board.evaluate(color); + int enemyValue = board.evaluate(color.opposite()); + int valueChange = teamValue - enemyValue; if (depth < maxDepth && valueChange >= alphaBetaThreshold) valueChange -= miniMax(board, board.getMoves(color.opposite()), color.opposite(), depth + 1); diff --git a/src/dev/kske/chess/ui/MainWindow.java b/src/dev/kske/chess/ui/MainWindow.java index 1d64376..9ec7ef8 100644 --- a/src/dev/kske/chess/ui/MainWindow.java +++ b/src/dev/kske/chess/ui/MainWindow.java @@ -55,7 +55,7 @@ public class MainWindow { */ private void initialize() { mframe = new JFrame("Chess by Kai S. K. Engelbart"); - mframe.setResizable(true); + mframe.setResizable(false); mframe.setBounds(100, 100, 494, 565); mframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);