示例#1
0
        /// <summary>
        /// Applies a move for the current player at the given position
        /// </summary>
        /// <param name="position"> The position the piece is moved to</param>
        public async Task ApplyMove(BoardPosition position)
        {
            var possMoves = mBoard.GetPossibleMoves() as IEnumerable <ChessMove>;

            //Make sure the move is valid
            foreach (var move in possMoves)
            {
                if ((move.StartPosition.Equals(StartBoardPosition)) && (move.EndPosition.Equals(position)))
                {
                    if (!PromotedPiece.Equals(ChessPieceType.Empty))
                    {
                        if (move.PromoteTo == PromotedPiece)
                        {
                            mBoard.ApplyMove(move);
                            break;
                        }
                    }
                    else
                    {
                        mBoard.ApplyMove(move);
                        break;
                    }
                }
            }

            RebindState();

            if (Players == NumberOfPlayers.One && !mBoard.IsFinished)
            {
                var bestMoveTask = Task.Run(() => mGameAi.FindBestMove(mBoard));

                var bestMove = await bestMoveTask;

                if (bestMove != null)
                {
                    mBoard.ApplyMove(bestMove as ChessMove);
                }
                RebindState();
            }
            //MessageBox.Show(mBoard.BoardWeight.ToString());

            if (mBoard.IsFinished)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }
        }
示例#2
0
        /// <summary>
        ///		Convierte los datos del movimiento en una cadena
        /// </summary>
        public override string ToString()
        {
            string converted = $"{Turn} {Content} - {OriginPiece.ToString()} {Color.ToString()} ({Type.ToString()})";

            // Añade las posiciones
            if (From != null)
            {
                converted += $" From {From}";
            }
            if (To != null)
            {
                converted += $" To {To}";
            }
            // Añade los datos
            if (PromotedPiece != null)
            {
                converted += $" Promoted to {PromotedPiece.ToString()}";
            }
            if (IsCheck)
            {
                converted += " Check";
            }
            if (IsDoubleCheck)
            {
                converted += " Double check";
            }
            if (IsCheckMate)
            {
                converted += " Check mate";
            }
            if (IsDrawOffered)
            {
                converted += " Draw offered";
            }
            // Devuelve la cadena final
            return(converted);
        }