예제 #1
0
        /// <summary>
        /// Player wants to play a move
        /// </summary>
        /// <param name="sender">Player</param>
        /// <param name="Move">Move to play</param>
        private void Player_MakesMove(object sender, int Move)
        {
            if (GamePosition.Status != Position.GameResult.InProcess)
            {
                MessageBox.Show("Error. Game is finished. No moves allowed");
            }

            //Engine tried to move but couldn't
            if (Move == Engine.NO_MOVES)
            {
                MessageBox.Show(PerfectChess.Move.Details(Move));
                return;
            }

            //Check for legality
            if (!GamePosition.LegalMoves().Contains(Move))
            {
                MessageBox.Show(PerfectChess.Move.Details(Move));
                return;
            }

            //Make the move
            GamePosition.Make(Move);
            if (PlayerWaiting is HumanPlayer)
            {
                BoardView.FinishMove(Move);
            }
            else
            {
                BoardView.PerformComputerMove(Move);
            }

            //Add visual move effects
            ApplyMoveEffects();
            if (GamePosition.Status != Position.GameResult.InProcess)
            {
                return;
            }
            //if (GamePosition.GameFinished) return;

            //Tell the other guy he can move
            PlayerToMove.YourMove(GamePosition.DeepCopy());
        }