Exemplo n.º 1
0
 public ChessMove(ChessPosition _from, ChessPosition _to)
 {
     From         = _from;
     To           = _to;
     FromChessNum = board.chess[_from.y, _from.x];
     ToChessNum   = board.chess[_to.y, _to.x];
 }
Exemplo n.º 2
0
 //把传入进来的可走位置全部画出来
 void MoveCheck(List <ChessPosition> chessPositionList, int[,] position, int j, int i, int x, int y)
 {
     if (rules._instance.KingBye(position, j, i, x, y))
     {
         ChessPosition pos = new ChessPosition(x, y);
         chessPositionList.Add(pos);
     }
 }
Exemplo n.º 3
0
        //获取AI搜索的结果
        public ChessMove GetAiMove()
        {
            SearchEngine.Move move      = SearchEngine._instance.SearchAGoodMove(board.chess);
            ChessPosition     posFrom   = new ChessPosition(move.From.x, move.From.y);
            ChessPosition     posTo     = new ChessPosition(move.To.x, move.To.y);
            ChessMove         chessmove = new ChessMove(posFrom, posTo);

            return(chessmove);
        }
Exemplo n.º 4
0
        //根据选择的棋子返回可走的位置
        public List <ChessPosition> ChessCanMove(ChessPosition pos)
        {
            int fromx = pos.x;
            int fromy = pos.y;
            List <ChessPosition> chessPositionList = new List <ChessPosition>();
            int ChessID = board.chess[fromy, fromx];

            switch (ChessID)
            {
            case 1:
            case 8:
                Gen_KingMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 2:
            case 9:
                Gen_CarMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 3:
            case 10:
                Gen_HorseMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 4:
            case 11:
                Gen_CanonMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 5:    //黑士
                Gen_BBishopMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 6:    //黑象
            case 13:   //红相
                Gen_ElephantMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 7:    //黑兵
                Gen_BPawnMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 12:    //红shi
                Gen_RBishopMove(chessPositionList, board.chess, fromx, fromy);
                break;

            case 14:    //红兵
                Gen_RPawnMove(chessPositionList, board.chess, fromx, fromy);
                break;
            }
            return(chessPositionList);
        }
Exemplo n.º 5
0
        ChessPosition GetRedKingPosition()
        {
            int x = 0, y = 0;

            for (int j = 7; j < 10; j++)
            {
                for (int i = 3; i < 6; i++)
                {
                    if (board.chess[j, i] == 8)
                    {
                        x = i; y = j;
                    }
                }
            }
            ChessPosition pos = new ChessPosition(x, y);

            return(pos);
        }
Exemplo n.º 6
0
        //开始悔棋功能了并返回该走的棋子位置的变换
        public ChessMove BackStep()
        {
            int fromx, fromy, tox, toy;
            int length = ChessMoveList.Count;

            fromx = ChessMoveList[length - 1].From.x;
            fromy = ChessMoveList[length - 1].From.y;
            tox   = ChessMoveList[length - 1].To.x;
            toy   = ChessMoveList[length - 1].To.y;

            ChessPosition TempPosFrom = ChessMoveList[length - 1].To;
            ChessPosition TempPosTo   = ChessMoveList[length - 1].From;
            ChessMove     move        = new ChessMove(TempPosFrom, TempPosTo);

            board.chess[fromy, fromx] = ChessMoveList[length - 1].FromChessNum;
            board.chess[toy, tox]     = ChessMoveList[length - 1].ToChessNum;
            ChessMoveList.RemoveAt(length - 1);
            return(move);
        }
Exemplo n.º 7
0
        //移动或吃棋子
        public bool MoveOrEatChess(ChessPosition TempPosFrom, ChessPosition TempPosTo)
        {
            int  _fromX = TempPosFrom.x;
            int  _fromY = TempPosFrom.y;
            int  _toX   = TempPosTo.x;
            int  _toY   = TempPosTo.y;
            bool ba     = rules._instance.IsValidMove(board.chess, _fromX, _fromY, _toX, _toY);

            if (!ba)
            {
                return(false);
            }
            else
            {
                AddChessList(TempPosFrom, TempPosTo);
                board.chess[_toY, _toX]     = board.chess[_fromY, _fromX];
                board.chess[_fromY, _fromX] = 0;
                return(true);
            }
        }
Exemplo n.º 8
0
        void AddChessList(ChessPosition TempPosFrom, ChessPosition TempPosTo)
        {
            ChessMove TempBack = new ChessMove(TempPosFrom, TempPosTo);

            ChessMoveList.Add(TempBack);
        }
Exemplo n.º 9
0
        //检测是否被将军
        public int KingAttackCheck()
        {
            ChessPosition blackKing = GetBlackKingPosition();
            ChessPosition redKing   = GetRedKingPosition();
            int           _jiang_X  = blackKing.x;
            int           _jiang_Y  = blackKing.y;
            int           _shuai_X  = redKing.x;
            int           _shuai_Y  = redKing.y;

            if (board.chess[_jiang_Y, _jiang_X] != 1)
            {
                return(-1);
            }
            else if (board.chess[_shuai_Y, _shuai_X] != 8)
            {
                return(-1);
            }
            bool BOL;//bool 值

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    switch (board.chess[j, i])
                    {
                    case 2:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _shuai_X, _shuai_Y);
                        if (BOL)
                        {
                            return(2);
                        }

                        break;

                    case 3:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _shuai_X, _shuai_Y);
                        if (BOL)
                        {
                            return(3);
                        }
                        break;

                    case 4:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _shuai_X, _shuai_Y);
                        if (BOL)
                        {
                            return(4);
                        }
                        break;

                    case 7:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _shuai_X, _shuai_Y);
                        if (BOL)
                        {
                            return(7);
                        }
                        break;

                    case 9:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _jiang_X, _jiang_Y);
                        if (BOL)
                        {
                            return(9);
                        }
                        break;

                    case 10:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _jiang_X, _jiang_Y);
                        if (BOL)
                        {
                            return(10);
                        }
                        break;

                    case 11:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _jiang_X, _jiang_Y);
                        if (BOL)
                        {
                            return(11);
                        }
                        break;

                    case 14:
                        BOL = rules._instance.IsValidMove(board.chess, i, j, _jiang_X, _jiang_Y);
                        if (BOL)
                        {
                            return(14);
                        }
                        break;
                    }
                }
            }
            return(0);
        }