Exemplo n.º 1
0
        /// <summary>
        /// Plays the turn of the current player.
        /// </summary>
        /// <param name="column">The column to drop the current player's marker.</param>
        /// <returns>
        /// A TurnResult specifying if the play was invalid,
        /// if the result was victory for the current player,
        /// if the result is a tie, or if the play was valid
        /// resulting the the next turn.
        /// </returns>
        public TurnResult PlayTurn(int column)
        {
            var cell = Board.DropInColumn(CurrentPlayer, column);

            // placement was invalid
            if (cell == null)
            {
                return(TurnResult.Invalid);
            }

            // check victory
            var condition = Board.CheckVictory(cell);

            // if result was not next (victory or tie), return result
            if (condition != TurnResult.Next)
            {
                return(condition);
            }

            // increment turn, switch players and return that it was a valid move
            turn++;
            CurrentPlayer = (turn % 2 == 1) ? playerRed : playerYellow;
            return(TurnResult.Next);
        }