Commit 98d06dd4 authored by 刘家荣's avatar 刘家荣 💬
Browse files

fix(AI): fix partly of AI

parent dbaaced0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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();
					}
				}
+5 −9
Original line number Diff line number Diff line
@@ -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() {
@@ -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 ?
+1 −0
Original line number Diff line number Diff line
@@ -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))))) {
+7 −5
Original line number Diff line number Diff line
@@ -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;
	}

@@ -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) {