コード例 #1
0
ファイル: AIPlayer.cs プロジェクト: khanh1202/CustomProg
        /// <summary>
        /// Takes the turn.
        /// </summary>
        /// <param name="point">MousePosition</param>
        /// <param name="game">the game</param>
        public override void TakeTurn(Point2D point, ChessGame game)
        {
            Move bestMove = BestMove(3, game, this);

            game.Board.Move(bestMove);
            game.ChangeTurn();
        }
コード例 #2
0
        /// <summary>
        /// Reverses the move.
        /// </summary>
        /// <param name="game">the Game</param>
        /// <param name="isTurnChanged">If set to <c>true</c> the turn is swapped</param>
        public void ReverseMove(ChessGame game, bool isTurnChanged)
        {
            if (_moves.Count == 0)
            {
                return;
            }
            Move lastMove = _moves [_moves.Count - 1];

            MoveWithoutChecking(new Move(lastMove.PlayerMove, lastMove.PieceMove, null, lastMove.CellTo, lastMove.CellFrom), false);
            if (lastMove.PieceCaptured != null)
            {
                lastMove.PlayerMove.Opponent.AddPiece(lastMove.PieceCaptured, lastMove.CellTo);
            }
            _moves.Remove(_moves [_moves.Count - 1]);
            _moves.Remove(lastMove);
            if (isTurnChanged)
            {
                game.ChangeTurn();
            }
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: khanh1202/CustomProg
 /// <summary>
 /// Handle input and take a turn for Human Player
 /// </summary>
 /// <param name="point">usually the mouse position</param>
 /// <param name="game">the game in play</param>
 public virtual void TakeTurn(Point2D point, ChessGame game)
 {
     //if the player is selecting piece to move
     if (game.State == GameState.Selecting)
     {
         Cell chosen = game.FetchCell(point);
         //if the piece chosen is not null and belongs to the player
         if (chosen != null && chosen.Piece != null && _pieces.Contains(chosen.Piece))
         {
             game.ChangeState(GameState.Moving);
             chosen.Piece.Select();
             game.SetChosenPiece(chosen.Piece);
         }
     }
     //if the player is selecting a cell to move the piece
     else if (game.State == GameState.Moving)
     {
         Cell chosen = game.FetchCell(point);
         //if the chosen cell is the cell that contains the piece, deselect the piece
         if (chosen.Piece != null && chosen.Piece.isSelected)
         {
             game.ChangeState(GameState.Selecting);
             chosen.Piece.Deselect();
         }
         //if the chosen cell is in possible moves of the chosen piece
         else if (chosen.isPossibleMoveOf(game.ChosenPiece, _board))
         {
             game.ChangeState(GameState.Moved);
             _board.Move(new Move(this, game.ChosenPiece, chosen.Piece, game.ChosenPiece.Cell, chosen));
             //if the king is moved, check if whether it is a castle
             if (game.ChosenPiece.GetType() == typeof(King) && _board.timesKingMovedBefore(_color) == 1)
             {
                 MoveRookInCastle(_color, chosen);
             }
             game.ChosenPiece.Deselect();
             game.ChangeTurn();
             Opponent.TakeTurn(point, game);
         }
     }
 }