Loading src/controller/ChessClickController.java +2 −0 Changes for src/controller/ChessClickController.java: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ public enum ChessClickController { History.instance.push(step); firstId = -1; if (Game.instance.gameType == GameType.LOCAL_AI) { AI.instance.interrupt(); AI.instance = new AI(); AI.instance.start(); } } Loading src/model/AI.java +4 −8 Changes for src/model/AI.java: 4 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -12,21 +12,17 @@ import java.util.stream.Stream; //TODO: 悔棋时要由按钮来停止它? public class AI extends Thread { public static final int DEPTH = 4; public static final int DEPTH = 2; public static final double Q = 0.8; public static final double ALPHA = 2; public static final AI instance = new AI(); public static AI instance = new AI(); @Override public void run() { try { Thread.sleep(100); // Thread.sleep(100); Game.instance.resolveStep(eval()); } catch (InterruptedException e) { throw new RuntimeException(e); } } public static Step eval0() { Loading Loading @@ -135,7 +131,7 @@ public class AI extends Thread { private static List<Step> movableSteps(Chessboard chessboard, ChessColor player) { List<Step> steps = new ArrayList<>(); for (Chess chess : chessboard.chessList) { if (chess.chessColor == player && chess.isReversal()) { if (chess.chessColor == player && chess.isReversal() && chess.getLocation().plate == ChessColor.NONE) { steps = Stream.concat(CheckRule.searchDstList(chessboard, chess).stream().map(gridPoint -> { Square dstSquare = chessboard.getSquareAtPoint(new Site(ChessColor.NONE, gridPoint)); return dstSquare instanceof Chess ? Loading src/model/game/CheckRule.java +1 −0 Changes for src/model/game/CheckRule.java: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ public class CheckRule { public static List<GridPoint> searchDstList(Chessboard chessboard, Chess chess) { List<GridPoint> dsts = new ArrayList<>(); if (chess.getLocation().plate != ChessColor.NONE) return dsts; if (chess.chessType != ChessType.CANNON) { if (chess.site.y > 0 && canMoveTo(chess, chessboard.getSquareAtPoint(chess.site.add(new GridPoint(-1, 0))))) { Loading src/model/game/Game.java +7 −5 Changes for src/model/game/Game.java: 7 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -95,12 +95,12 @@ public class Game implements Cloneable { chessboard.getSquareById(eatStep.dstChessId)); } if (res != null) { if (this.gameType == GameType.LOCAL_AI) { AI ai = new AI(); ai.start(); } } // if (this.gameType == GameType.LOCAL_AI) { // AI ai = new AI(); // ai.start(); // } judgeWinner(); } return res; } Loading Loading @@ -141,6 +141,8 @@ public class Game implements Cloneable { * 如果失败,返回值为null */ public Step revertStep() { if (History.instance.size() == 0) return null; Step last = History.instance.get(History.instance.size() - 1); Step res = null; if (last instanceof FlipStep flipStep) { Loading Loading
src/controller/ChessClickController.java +2 −0 Changes for src/controller/ChessClickController.java: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ public enum ChessClickController { History.instance.push(step); firstId = -1; if (Game.instance.gameType == GameType.LOCAL_AI) { AI.instance.interrupt(); AI.instance = new AI(); AI.instance.start(); } } Loading
src/model/AI.java +4 −8 Changes for src/model/AI.java: 4 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -12,21 +12,17 @@ import java.util.stream.Stream; //TODO: 悔棋时要由按钮来停止它? public class AI extends Thread { public static final int DEPTH = 4; public static final int DEPTH = 2; public static final double Q = 0.8; public static final double ALPHA = 2; public static final AI instance = new AI(); public static AI instance = new AI(); @Override public void run() { try { Thread.sleep(100); // Thread.sleep(100); Game.instance.resolveStep(eval()); } catch (InterruptedException e) { throw new RuntimeException(e); } } public static Step eval0() { Loading Loading @@ -135,7 +131,7 @@ public class AI extends Thread { private static List<Step> movableSteps(Chessboard chessboard, ChessColor player) { List<Step> steps = new ArrayList<>(); for (Chess chess : chessboard.chessList) { if (chess.chessColor == player && chess.isReversal()) { if (chess.chessColor == player && chess.isReversal() && chess.getLocation().plate == ChessColor.NONE) { steps = Stream.concat(CheckRule.searchDstList(chessboard, chess).stream().map(gridPoint -> { Square dstSquare = chessboard.getSquareAtPoint(new Site(ChessColor.NONE, gridPoint)); return dstSquare instanceof Chess ? Loading
src/model/game/CheckRule.java +1 −0 Changes for src/model/game/CheckRule.java: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ public class CheckRule { public static List<GridPoint> searchDstList(Chessboard chessboard, Chess chess) { List<GridPoint> dsts = new ArrayList<>(); if (chess.getLocation().plate != ChessColor.NONE) return dsts; if (chess.chessType != ChessType.CANNON) { if (chess.site.y > 0 && canMoveTo(chess, chessboard.getSquareAtPoint(chess.site.add(new GridPoint(-1, 0))))) { Loading
src/model/game/Game.java +7 −5 Changes for src/model/game/Game.java: 7 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -95,12 +95,12 @@ public class Game implements Cloneable { chessboard.getSquareById(eatStep.dstChessId)); } if (res != null) { if (this.gameType == GameType.LOCAL_AI) { AI ai = new AI(); ai.start(); } } // if (this.gameType == GameType.LOCAL_AI) { // AI ai = new AI(); // ai.start(); // } judgeWinner(); } return res; } Loading Loading @@ -141,6 +141,8 @@ public class Game implements Cloneable { * 如果失败,返回值为null */ public Step revertStep() { if (History.instance.size() == 0) return null; Step last = History.instance.get(History.instance.size() - 1); Step res = null; if (last instanceof FlipStep flipStep) { Loading