Exemple #1
0
        public void TestDDStatRollerAllValuesCheck()
        {
            IRollable d = new DiceSet();

            IRollable dd1 = DiceFactory.CreateDDStatRoller();

            ((DiceSet)d).Add(dd1);

            // populate "not yet found" list
            List <int> notFound = new List <int>();

            notFound.AddRange(new int[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 });

            // attempt to find each value
            for (int i = 1; i < 1000; i++)             // arbitrary limit of 10000 maximum tries
            {
                int result = d.Roll();                 // 3 to 18
                notFound.Remove(result);
                if (notFound.Count <= 0)
                {
                    break;                     // all found
                }
            }
            // test
            Assert.AreEqual <int>(0, notFound.Count, "Some values were not rolled on 3 d6.");
        }
Exemple #2
0
        public (string, RunResults) RunGames()
        {
            if (_settings.GameCount <= 0)
            {
                return(ErrorMessages.GamesCount, null);
            }

            var diceService = DiceFactory.CreateDiceService();
            var gameService = GameFactory.CreateGameService(diceService);

            var results = new List <int>();

            for (int i = 0; i < _settings.GameCount; i++)
            {
                gameService.Initialize(_settings);
                gameService.PlayGame();
                results.Add(gameService.GameData.TurnNumber);
            }

            try
            {
                return(null, new RunResults
                {
                    Minimum = results.Min(),
                    Maximum = results.Max(),
                    Average = results.Average()
                });
            }
            catch
            {
                return(gameService.Error, null);
            }
        }
Exemple #3
0
    private List<Tile> tempTileList; //  temporary tiles for the turn. Use this for borrowing opponent's tiles or temporarily having abilities granted by dice or whatever.

    #endregion Fields

    #region Methods

    //  =============================================================================
    //    add a new die to myself
    public PharoahDie AddDie(DiceFactory.DieType dieType)
    {
        PharoahDie die = GameState.GetCurrentGameState().diceFactory.NewDie(dieType);
        diceList.Add(die);
        die.ReadyToRoll();
        return die;
    }
        public void RoleDiceForeNumTest()
        {
            IDice dice = DiceFactory.CreateDice(4);
            int   num  = dice.RoleDiceForeNum();

            Assert.NotEqual(0, num);
        }
Exemple #5
0
        public void TestAllD100Values()
        {
            // create D100
            var d = DiceFactory.CreateD100();

            // populate "not yet found" list
            List <int> notFound = new List <int>();

            //notFound.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 });

            for (int i = 1; i <= 100; i++)
            {
                notFound.Add(i);
            }

            // attempt to find each value
            for (int i = 1; i < 10000; i++)            // arbitrary limit of 10000 maximum tries
            {
                int result = d.Roll();                 // 1 To 20
                notFound.Remove(result);
                if (notFound.Count <= 0)
                {
                    break;                     // all found
                }
            }
            // test
            Assert.AreEqual <int>(0, notFound.Count, "Some values were not rolled on a d100.");
        }
 public void Test_Aurora_Score_Factory()
 {
     for (int i = 1; i < 7; i++)
     {
         var dice = DiceFactory.CreateDice(i);
         Assert.IsNotNull(dice, "DiceFactory must create a valid Dice for values between 1 and 6");
         Assert.IsTrue(dice.Value == i, "The created Dice must contains same value as the CreateDice parameter value.");
     }
 }
        public void CreateDiceTest()
        {
            int   num  = 4;
            IDice dice = DiceFactory.CreateDice(num);

            Assert.True(dice.HasSides);
            Assert.Equal(num, dice.Sides.Count());
            Assert.Equal(num, dice.NumberOfSides);
        }
Exemple #8
0
        public void Game_can_be_started_with_normal_dice_or_crooked_dice(DiceType diceType)
        {
            var gameSetting = new GameSetting
            {
                BoardSetting = new BoardSetting {
                    Min = 1, Max = 100
                },
                MaxPlayersAllowed = 1,
                MinPlayersNeeded  = 1,
                TotalTurns        = 1
            };

            var dice = new DiceFactory().Create(diceType);

            var player = new Player {
                Id = "p123"
            };
            int playerOriginalPosition = player.CurrentPosition;

            var playerProgressListnerMock = new Mock <IPlayerProgressListener>();

            playerProgressListnerMock.Setup(x => x.OnPlayed(It.IsAny <PlayerMoveResult>()))
            .Callback((PlayerMoveResult playerResult) =>
            {
                playerResult.Should().NotBeNull();
                playerResult.NewPosition.Should().BeGreaterThan(playerOriginalPosition);
                playerResult.Status.Should().Be(MoveStatus.Moved);
            });

            var endGameListnerMock = new Mock <IEndGameListener>();

            endGameListnerMock.Setup(x => x.OnEndGame(It.IsAny <GameResult>()))
            .Callback((GameResult gameResult) =>
            {
                var playerResult = gameResult.PlayerResults.FirstOrDefault(x => x.Key.Equals(player));
                playerResult.Should().NotBeNull();
                playerResult.Value.NewPosition.Should().BeGreaterThan(playerOriginalPosition);
                playerResult.Value.Status.Should().Be(MoveStatus.Moved);
            });

            var game = new Game(dice, gameSetting, endGameListnerMock.Object);

            game.AddPlayer(player);
            game.RegisterPlayerProgressListener(playerProgressListnerMock.Object);

            game.Start();

            endGameListnerMock.Setup(x => x.OnEndGame(It.IsAny <GameResult>()))
            .Callback((GameResult gameResult) =>
            {
                var playerResult = gameResult.PlayerResults.FirstOrDefault(x => x.Key.Equals(player));
                playerResult.Value.Status.Should().Be(MoveStatus.Stopped);
            });
            game.Stop();
        }
Exemple #9
0
        public void RollTest()
        {
            List <int> rollResults = new List <int>();
            IRollable  d           = DiceFactory.CreateD10();

            for (int i = 0; i < 100000000; i++)
            {
                rollResults.Add(d.Roll());
            }
            Assert.AreEqual(rollResults.Count, 100000000, "Count is " + rollResults.Count.ToString());
        }
 public AuroraScoreUnitTest()
 {
     AuroraPlays = new List <Dice[]>();
     for (int i = 0; i < 6; i++)
     {
         AuroraPlays.Add(new Dice[5]);
         var dice = DiceFactory.CreateDice(i + 1);
         for (int j = 0; j < 5; j++)
         {
             AuroraPlays[i][j] = dice;
         }
     }
 }
Exemple #11
0
        public void BasicSettings_Game_GeneratesTurnsCount()
        {
            var settings = new GameSettings
            {
                ChipsPerPlayer = 1,
                PlayerCount    = 3
            };
            var diceService = DiceFactory.CreateDiceService();
            var basicGame   = GameFactory.CreateGameService(diceService);

            basicGame.Initialize(settings);
            basicGame.PlayGame();
            Assert.NotEqual(0, basicGame.GameData.TurnNumber);
        }
        public void RoleDiceForSuccessFiftyTest()
        {
            IDice dice       = DiceFactory.CreateDice(4);
            bool  wasFial    = false;
            bool  wasSuccess = false;

            for (int i = 0; i < 100; i++)
            {
                if (dice.RoleDiceForSuccess(OddType.Fifty))
                {
                    wasSuccess = true;
                }
                else
                {
                    wasFial = true;
                }
            }
            Assert.True(wasSuccess && wasFial);
        }
Exemple #13
0
        public void TestAllCoinValues()
        {
            // create Coin
            var d = DiceFactory.CreateCoin();

            // populate "not yet found" list
            List <int> notFound = new List <int>();

            notFound.AddRange(new int[] { 1, 2 });

            // attempt to find each value
            for (int i = 1; i < 10; i++)               // arbitrary limit of 10 maximum tries
            {
                int result = d.Roll();                 // 1 To 2
                notFound.Remove(result);
                if (notFound.Count <= 0)
                {
                    break;                     // all found
                }
            }
            // test
            Assert.AreEqual <int>(0, notFound.Count, "Some values were not rolled on a coin.");
        }
Exemple #14
0
 public void ShouldCreateD4()
 {
     Assert.IsInstanceOf <D4Die>(DiceFactory.Create(DiceType.D4));
 }
Exemple #15
0
 public void ShouldCreateD20()
 {
     Assert.IsInstanceOf <D20Die>(DiceFactory.Create(DiceType.D20));
 }
Exemple #16
0
 public void ShouldCreateD12()
 {
     Assert.IsInstanceOf <D12Die>(DiceFactory.Create(DiceType.D12));
 }
Exemple #17
0
 public void ShouldCreateD8()
 {
     Assert.IsInstanceOf <D8Die>(DiceFactory.Create(DiceType.D8));
 }
Exemple #18
0
 public void ShouldCreateD6()
 {
     Assert.IsInstanceOf <D6Die>(DiceFactory.Create(DiceType.D6));
 }
Exemple #19
0
 public void Run(string environment)
 {
     var  diceFactory = new DiceFactory(environment);
     Dice d6          = diceFactory.GetDice6();
     Dice d10         = diceFactory.GetDice10();
 }
Exemple #20
0
 public DiceService(DiceFactory diceFactory)
 {
     _diceFactory = diceFactory;
 }
Exemple #21
0
        private PartialRoll RollGen(string diceRoll)
        {
            var myDice = DiceFactory.Create();

            return(myDice.Roll(diceRoll));
        }
Exemple #22
0
 public static IEnumerable <Dice> NewRange(IEnumerable <int> values)
 {
     return(values.Select(v => DiceFactory.CreateDice(v)));
 }
Exemple #23
0
 public static Dice New(int diceNum)
 {
     return(DiceFactory.CreateDice(diceNum));
 }