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

fix(CheckRule): fixed Solder<-General; add clone() method for models

parent a2d65157
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -48,16 +48,20 @@ public class CheckRule {
     *                    此处利用 enum 的 compareTo 方法 判断吃棋是否合规
     */
    public static boolean checkRank(Chess handleChess, Chess dstChess) {
        //已翻转的情况
        ChessType srcType = handleChess.getChessType();
        ChessType dstType = dstChess.getChessType();
        if (dstChess.isReversal()) {
            return handleChess.getChessColor() != dstChess.getChessColor() && (
                    (handleChess.getChessType() == ChessType.SOLDIER &&
                            (dstChess.getChessType() == ChessType.CANNON ||
                                    dstChess.getChessType() == ChessType.GENERAL)
                    ) || dstChess.getChessType().compareTo(handleChess.getChessType()) >= 0
            return handleChess.getChessColor() != dstChess.getChessColor()  // 颜色不相等
                    && !(srcType == ChessType.GENERAL && dstType == ChessType.SOLDIER)      //将->兵,不可
                    && (
                            dstType.compareTo(srcType) >= 0     //高级
                            || (     //兵->炮/将
                                    srcType == ChessType.SOLDIER
                                    && (dstType == ChessType.CANNON || dstType == ChessType.GENERAL)
                            )
                    );
        } else {
            return (handleChess.getChessType() == ChessType.CANNON);
            return (srcType == ChessType.CANNON);
        }
    }

+0 −3
Original line number Diff line number Diff line
package model;


import com.sun.source.tree.SynchronizedTree;
import model.chess.Chess;
import model.chess.EmptySlot;
import model.chess.Square;
@@ -38,7 +36,6 @@ public class Chessboard implements Serializable, Cloneable {
     * 初始化整个棋盘,包括所有棋子和亡子堆
     */
    public Chessboard() {
        History.init(this);
        Random random = new Random();
        //此列表的元素是元组,每个元组存储的是对应棋子的部分参数(颜色和类别)
        ArrayList<Tuple2<ChessColor, ChessType>> paramsList = new ArrayList<>();