Exemplo n.º 1
0
        /// <summary>
        /// create the chess pieces
        /// </summary>
        /// <param name="fen"></param>
        private void loadChessPieces(string fen)
        {
            string chessBoard;

            string[] chessArr = fen.Split(' ');
            m_IndexX = 0;
            m_IndexY = 0;
            if (chessArr.Length < 1)
            {
                return;
            }
            else
            {
                chessBoard = chessArr[0];
            }
            foreach (char curWord in chessBoard)
            {
                if (curWord >= 49 && curWord <= 57)
                {
                    m_IndexX += ChessUtils.charToNum(curWord);
                }
                else if ((curWord >= 65 && curWord <= 90) || (curWord >= 97 && curWord <= 122))
                {
                    //red
                    createPiece((byte)curWord);
                }
                else if (curWord == 47)
                {
                    m_IndexX = 0;
                    m_IndexY++;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// it's only move the chess piece, after select it
 /// </summary>
 /// <param name="newLocation"></param>
 private void chessMove(int gridX, int gridY)
 {
     if (_selectChess != null && _selectChess.Type == _currentActionType)
     {
         if (_selectChess.move(gridX, gridY))
         {
             //_selectChess.IsChecked = false;
             chessArray[_selectChess.GridY, _selectChess.GridX] = (byte)_selectChess.PieceType;
             chessArray[_selectChess.PreviousGridY, _selectChess.PreviousGridX] = (byte)0;
             string move = ChessUtils.getMoveString(_selectChess.GridX, _selectChess.GridY, _selectChess.PreviousGridX, _selectChess.PreviousGridY);
             _updateMovesStep(move);
             doSomeAfterMove();
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// it's common from select chess piece, or attack another chess piece
 /// </summary>
 /// <param name="theChessPiece"></param>
 private void chessItemSelected(BaseChess theChessPiece)
 {
     if (_selectChess == null)
     {
         //第一次选择棋子
         if (theChessPiece.Type == _currentActionType)
         {
             _selectChess = theChessPiece;
             //_previousChess = _selectChess;
         }
         else
         {
             //选择错了棋子
             theChessPiece.IsChecked = false;
         }
     }
     else
     {
         //已经选择了一个棋子,再次选择时是对方棋子
         if (theChessPiece.Type != _currentActionType)
         {
             BaseChess beAttackChess = theChessPiece;
             if (_selectChess.move(beAttackChess.Location))
             {
                 chessArray[_selectChess.GridY, _selectChess.GridX]   = (byte)_selectChess.PieceType;
                 chessArray[beAttackChess.GridY, beAttackChess.GridX] = 0;
                 _previousOppositeChess = beAttackChess.Clone();
                 beAttackChess.remove();
                 string move = ChessUtils.getMoveString(_selectChess.GridX, _selectChess.GridY, _selectChess.PreviousGridX, _selectChess.PreviousGridY);
                 _updateMovesStep(move, true);
                 _updateFenStr();
                 doSomeAfterMove();
             }
             else
             {
                 //不遵循着法
                 beAttackChess.IsChecked = false;
             }
         }
         else
         {
             //如果再次选择时还是己方棋子,更改check状态
             _selectChess.IsChecked = false;
             //更换当前引用
             _selectChess = theChessPiece;
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// send position command to engine
        /// and update the fen
        /// </summary>
        private void _sendPositionCommand()
        {
            StringBuilder cmd = new StringBuilder();

            string[] strArr = fen.Split(' ');
            if (strArr.Length < 1)
            {
                cmd.Append(fen);
            }
            else
            {
                cmd.Append(strArr[0]);
            }
            string theType = ChessUtils.getTypeForUcci((int)_currentActionType);

            cmd.Append(" " + theType + " - - 0 ");
            cmd.Append(m_nNoOfMoves.ToString() + " ");
            cmd.Append(moves);
            fen = cmd.ToString();
            _theEngineClient.SendPositionCommand(fen);
        }
Exemplo n.º 5
0
        /// <summary>
        /// get the best move from engine
        /// </summary>
        private void _executeBestMove()
        {
            int       currentGridX, currentGridY, nextGridX, nextGridY;
            BaseChess _attackedChess = null;

            if (ChessUtils.getGridXY(bestMove, out currentGridX, out currentGridY, out nextGridX, out nextGridY))
            {
                _selectChess   = BaseChess.getChessOnPoint(panel1, currentGridX, currentGridY);
                _attackedChess = BaseChess.getChessOnPoint(panel1, nextGridX, nextGridY);
                if (_selectChess != null)
                {
                    chessItemSelected(_selectChess);
                    if (_attackedChess != null)
                    {
                        chessItemSelected(_attackedChess);
                    }
                    else
                    {
                        chessMove(nextGridX, nextGridY);
                    }
                }
            }
        }