Esempio n. 1
0
        public void ThoroughCheaterPlayer()
        {
            var Referee       = new Referee();
            var PlayerFactory = new PlayerFactory();

            var RandomPlayer = PlayerFactory.CreatePlayer(
                name: "RandomPlayer",
                id: 1,
                playerType: Config.PlayersTypes.Random,
                referee: Referee);

            var ThoroughCheater = PlayerFactory.CreatePlayer(
                name: "ThoroughCheater",
                id: 2,
                playerType: Config.PlayersTypes.ThoroughCheater,
                referee: Referee);

            Dictionary <int, int> numbers = new Dictionary <int, int>();

            bool isSameNum = false;
            int  i         = 0;

            while (numbers.Count < Config.MaxWeight - Config.MinWeight)
            {
                try
                {
                    var number = RandomPlayer.Action();
                    try
                    {
                        numbers.Add(number, i);
                    }
                    catch (Exception) { }

                    // action contains a call cheating event
                    Referee.AddNumber(RandomPlayer.Id, number);

                    number = ThoroughCheater.Action();
                    Assert.True((number >= Config.MinWeight) && (number <= Config.MaxWeight), "Numbers out of range");
                    numbers.Add(number, i);
                }
                catch (Exception)
                {
                    isSameNum = true;
                    break;
                }
                i++;
            }

            Assert.True(isSameNum == false, "Numbers are not unique");
        }
Esempio n. 2
0
        /// <summary>
        /// Performs the game process.
        /// </summary>
        /// <param name="referee">The referee of the game.</param>
        /// <returns>The tuple consisting of the winner name,
        /// the number of attempts to guess the weight of the fruit basket,
        /// and the winner guess about the weight of the fruit basket.</returns>
        public (string playerName, int attempt, int weight) PerformGameProcess(Referee referee)
        {
            bool IsBasketWeightFound = false;

            for (int i = 0; i < Config.MaxGameRound; i++)
            {
                referee.Round = i;
                foreach (var player in referee.Players)
                {
                    if (player.SkipRoundCount == 0)
                    {
                        int number = player.Action();
                        referee.AddNumber(player.Id, number);
                        player.Attempt++;
                        if (referee.IsBasketWeightCorrect(number))
                        {
                            IsBasketWeightFound = true;
                            break;
                        }
                        else
                        {
                            player.SkipRoundCount = referee.GetSkipRoundCount(number);
                        }
                    }
                    else
                    {
                        player.SkipRoundCount--;
                    }
                }
                if (IsBasketWeightFound)
                {
                    break;
                }
            }

            return(referee.GetWinner());
        }