Пример #1
0
        private void BoardView_SquareTapped(object sender, Square S)
        {
            //Game is finished
            if (GamePosition.Status != Position.GameResult.InProcess)
            {
                return;
            }


            if (PlayerToMove is EnginePlayer && PlayerWaiting is EnginePlayer)
            {
                MessageBox.Show("Don't bother the comps! Let them play!"); return;
            }
            int Piece = GamePosition[S.X + 8 * S.Y];

            if (Piece == 0)
            {
                return;
            }
            if (PlayerToMove is EnginePlayer && ((Piece & Color.Mask) == ((PlayerToMove == PlayerWhite) ? Color.White : Color.Black)))
            {
                return;
            }
            //if (PlayerToMove.IsThinking) return;


            List <int> Moves = GamePosition.LegalMoves();

            List <Square> EmptyAvailibleSquares = new List <Square>();
            List <Square> EnemyAvailibleSquares = new List <Square>();

            foreach (int Move in Moves.Where(m => PerfectChess.Move.FromSquare(m) == S.X + 8 * S.Y))
            {
                if (PerfectChess.Move.ToPiece(Move) == 0)
                {
                    EmptyAvailibleSquares.Add(Square.Get(PerfectChess.Move.ToSquare(Move) % 8 + 1, PerfectChess.Move.ToSquare(Move) / 8 + 1));
                }
                else
                {
                    EnemyAvailibleSquares.Add(Square.Get(PerfectChess.Move.ToSquare(Move) % 8 + 1, PerfectChess.Move.ToSquare(Move) / 8 + 1));
                }
            }
            BoardView.StartMove(S, EmptyAvailibleSquares, EnemyAvailibleSquares);
        }
Пример #2
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());
        }