Beispiel #1
0
        public ViewController(Variant variant, DiceCollection diceCollection)
        {
            roundsView = new RoundsView(variant);
            renderer   = new Renderer(variant);

            Subscribe(diceCollection);
        }
        public void SumTestWithModifier()
        {
            var count  = 0;
            var allMin = false;
            var allMax = false;
            var dice   = new List <Die>()
            {
                new Die(6),
                new Die(6),
                new Die(6)
            };

            var diceCollection = new DiceCollection(dice, 3);

            while (count++ < 10000)
            {
                diceCollection.Roll();
                if (!allMax && diceCollection.Sum() == 21)
                {
                    allMax = true;
                }
                if (!allMin && diceCollection.Sum() == 6)
                {
                    allMin = true;
                }


                Assert.LessOrEqual(diceCollection.Sum(), 21);
                Assert.GreaterOrEqual(diceCollection.Sum(), 6);
            }
            Assert.True(allMin);
            Assert.True(allMax);
        }
Beispiel #3
0
        public void DiceCollection_ConstructorValid(int value, int count)
        {
            var diceCollection = new DiceCollection(value, count);

            Assert.AreEqual(value, diceCollection.Value);
            Assert.AreEqual(count, diceCollection.Count);
        }
        private void StartGame()
        {
            gameSetup      = new GameSetup();
            diceCollection = gameSetup.diceCollection;
            gameType       = gameSetup.gameType;

            variant        = gameSetup.variant;
            rules          = gameSetup.rules;
            database       = gameSetup.database;
            viewController = new ViewController(variant, diceCollection);

            while (viewController.ViewHighscore())
            {
                viewController.GetFiles(rules, database, true);
            }

            if (viewController.ResumeGame())
            {
                viewController.GetFiles(rules, database, false);
                Date        = viewController.Date;
                RoundNumber = viewController.RoundNumber;
                players     = viewController.GetListOfPlayersFromFile();
            }
            else
            {
                Date        = DateTime.Now;
                RoundNumber = 0;
                gameSetup.PlayerSetup();
                players = gameSetup.addedplayers;
            }

            RunGame(players);
        }
        public List<List<KingsburgDie>> Find( int targetSum, DiceCollection bag )
        {
            //DiceCollection clone = (DiceCollection)bag.Clone();
            DiceCollection clone = bag;
            List<KingsburgDie> elements = (List<KingsburgDie>)clone;
            mResults = new List<List<KingsburgDie>>();
            RecursiveFind( targetSum, 0, new List<KingsburgDie>(), elements, 0 );

            List<List<KingsburgDie>> copy = new List<List<KingsburgDie>>( mResults );
            foreach( List<KingsburgDie> list in copy )
            {
                if( list.Count == 1 )
                {
                    if( list[0].Type != KingsburgDie.DieTypes.Regular )
                    {
                        mResults.Remove( list );
                    }
                }

                IEnumerable<KingsburgDie> linq = from r in list
                                                 where r.Type == KingsburgDie.DieTypes.MarketNegative || r.Type == KingsburgDie.DieTypes.MarketPositive
                                                 select r;
                List<KingsburgDie> marketDice = new List<KingsburgDie>( linq );
                if( marketDice.Count > 1 )
                {
                    mResults.Remove( list );
                }
            }
            return mResults;
        }
Beispiel #6
0
        public void AddToCount_AddValid(int value, int count, int countToAdd, int expected)
        {
            var diceCollection = new DiceCollection(value, count);

            diceCollection.AddToCount(countToAdd);

            Assert.AreEqual(expected, diceCollection.Count);
        }
        public void CalculateScore_Calculate_ReturnsCorrect(int[] hand, int expected)
        {
            var scoreCalculator = new ScoreCalculator();
            var diceCollection  = new DiceCollection(hand[0], hand[1]);

            var result = scoreCalculator.CalculateScore(diceCollection);

            result.ShouldBe(expected);
        }
        public void DiceCollectionRollShouldBeWithinRange(int diceCount, int diceFaceCount)
        {
            // Setup
            var diceCollection = new DiceCollection(diceCount, diceFaceCount);

            // Test
            var roll = diceCollection.RollAll();

            // Assert
            Assert.InRange(roll, diceCount, diceCount * diceFaceCount);
        }
 public InterfaceRules GetRules(DiceCollection diceCollection)
 {
     if (gameType == GameType.Yahtzee)
     {
         return(new YahtzeeRules(diceCollection));
     }
     else if (gameType == GameType.Yatzy)
     {
         return(new YatzyRules(diceCollection));
     }
     return(null);
 }
Beispiel #10
0
 private void CreateDice()
 {
     Dice = new DiceCollection(
         new List <DiceGroup>()
     {
         new DiceGroup(2, NumberOfTwoSidedDice),
         new DiceGroup(4, NumberOfFourSidedDice),
         new DiceGroup(6, NumberOfSixSidedDice),
         new DiceGroup(8, NumberOfEightSidedDice),
         new DiceGroup(12, NumberOfTwelveSidedDice),
         new DiceGroup(20, NumberOfTwentySidedDice)
     });
 }
Beispiel #11
0
        public GameSetup()
        {
            this.gameType       = new MainMenu().RenderStartMenu();
            this.manufactory    = new GameManufactory(gameType);
            this.diceCollection = new DiceCollection();
            this.database       = new Database(variant, rules, gameType);

            this.variant      = manufactory.GetVariant();
            this.rules        = manufactory.GetRules(diceCollection);
            this.renderer     = new Renderer(variant);
            settingsView      = new SettingsView();
            this.addedplayers = new List <Player>();
        }
        public void IntMinusDieCollectionTest()
        {
            var diceSet = new List <Die>()
            {
                new Die(6, seed: 123456),
                new Die(6, seed: 3376)
            };

            var diceCollection = new DiceCollection(diceSet);

            diceCollection.Roll();

            Assert.AreEqual(4, 10 - diceCollection);
        }
        public void SumHighestSpecifiedValueTest()
        {
            var dice = new List <Die>()
            {
                new Die(6, seed: 12345),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceCollection = new DiceCollection(dice);

            diceCollection.Roll();

            Assert.AreEqual(9, diceCollection.SumHighest(2));
        }
        public void SubtractIntFromDieCollectionTest()
        {
            var diceSet75 = new List <Die>()
            {
                new Die(6, seed: 12345),  //3
                new Die(6, seed: 123456), //6
                new Die(6, seed: 1234)    //2
            };

            var diceCollection = new DiceCollection(diceSet75);

            diceCollection.Roll();

            Assert.AreEqual(8, diceCollection - 3);
        }
        public void AddDiceCollectiontoIntTest()
        {
            var diceSet1 = new List <Die>()
            {
                new Die(6, seed: 12345),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceCollection = new DiceCollection(diceSet1);

            diceCollection.Roll();

            Assert.AreEqual(15, 4 + diceCollection);
        }
        public void SumHighestDefaultValueTestWithDuplicates()
        {
            var dice = new List <Die>()
            {
                new Die(6, seed: 123456),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceCollection = new DiceCollection(dice);

            diceCollection.Roll();

            Assert.AreEqual(6, diceCollection.SumHighest());
        }
        public void Add2DiceCollectionsTestTwoModifier()
        {
            var count  = 0;
            var allMin = false;
            var allMax = false;
            var max    = 15 + 18 + 3 + 2;
            var min    = 6 + 3 + 2;
            var dice1  = new List <Die>()
            {
                new Die(5),
                new Die(5),
                new Die(5)
            };

            var dice2 = new List <Die>()
            {
                new Die(6),
                new Die(6),
                new Die(6),
            };

            var diceCollection1 = new DiceCollection(dice1, 3);
            var diceCollection2 = new DiceCollection(dice2, 2);

            while (count++ < 100000)
            {
                diceCollection1.Roll();
                diceCollection2.Roll();

                var result = diceCollection1 + diceCollection2;

                if (!allMax && result == max)
                {
                    allMax = true;
                }
                if (!allMin && result == min)
                {
                    allMin = true;
                }

                Assert.LessOrEqual(result, max);
                Assert.GreaterOrEqual(result, min);
            }

            Assert.IsTrue(allMin);
            Assert.IsTrue(allMax);
        }
        public void SubtractDiceCollectionFromDie()
        {
            var diceSet1 = new List <Die>()
            {
                new Die(6, seed: 12345),  //3
                new Die(6, seed: 123456), //3
                new Die(6, seed: 1234)    //4
            };

            var die = new Die(6, seed: 3376); //1

            var diceCollection = new DiceCollection(diceSet1);

            diceCollection.Roll();
            die.Roll();

            Assert.AreEqual(-9, die - diceCollection);
        }
        public void AddDiceCollectionToDieTest()
        {
            var diceSet1 = new List <Die>()
            {
                new Die(6, seed: 12345),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var die = new Die(6, seed: 6573);

            var diceCollection = new DiceCollection(diceSet1);

            diceCollection.Roll();
            die.Roll();

            Assert.AreEqual(13, die + diceCollection);
        }
        public void RollTest()
        {
            var dice = new List <Die>()
            {
                new Die(1),
                new Die(2),
                new Die(3),
                new Die(4)
            };

            var diceCollection = new DiceCollection(dice);

            diceCollection.Roll();

            var count = diceCollection.Dice.Where(d => d.currentValue == 0).Sum(d => d.currentValue);

            Assert.AreEqual(0, count);
        }
        public void CreateTest()
        {
            var dice = new List <Die>()
            {
                new Die(1),
                new Die(2),
                new Die(3),
                new Die(4)
            };

            var diceCollection = new DiceCollection(dice);

            Assert.AreEqual(4, diceCollection.Dice.Count);
            Assert.AreEqual(1, diceCollection.Dice.ElementAt(0).max);
            Assert.AreEqual(2, diceCollection.Dice.ElementAt(1).max);
            Assert.AreEqual(3, diceCollection.Dice.ElementAt(2).max);
            Assert.AreEqual(4, diceCollection.Dice.ElementAt(3).max);
        }
        public void GetHighestDefaultValueWithDuplicates()
        {
            var dice = new List <Die>()
            {
                new Die(6, seed: 123456),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceCollection = new DiceCollection(dice);

            diceCollection.Roll();

            var expectedList = new List <int>()
            {
                6
            };

            CollectionAssert.AreEqual(expectedList, diceCollection.GetHighest());
        }
        public void GetHighestSpSpecifiedValueTest()
        {
            var dice = new List <Die>()
            {
                new Die(6, seed: 12345),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceCollection = new DiceCollection(dice);

            diceCollection.Roll();

            var expectedList = new List <int>()
            {
                6,
                3
            };

            CollectionAssert.AreEqual(expectedList, diceCollection.GetHighest(2));
        }
Beispiel #24
0
        // This is a horrible way to do this but I am sick of trying to do the right algorithm to find all subset sums
        public static HashSet<int> Sums( DiceCollection diceVals )
        {
            HashSet<int> toReturn = new HashSet<int>();
            DiceCollection bag = new DiceCollection( 0, 6 );
            SumComboFinder comboFinder = new SumComboFinder();

            foreach( KingsburgDie i in diceVals )
            {
                KingsburgDie d;
                d = new KingsburgDie( i.Type );
                d.Value = i.Value;
                bag.Add( d );
            }

            foreach( int i in new Range( 1, 18 ) )
            {
                if( comboFinder.Find( i, bag ).Count > 0 )
                {
                    toReturn.Add( i );
                }
            }
            return toReturn;
        }
        public void SubtractTwoDiceCollections()
        {
            var diceSet1 = new List <Die>()
            {
                new Die(6, seed: 12345),
                new Die(6, seed: 123456),
                new Die(6, seed: 1234)
            };

            var diceSet2 = new List <Die>()
            {
                new Die(6, seed: 1326),
                new Die(6, seed: 6543),
                new Die(6, seed: 78654)
            };

            var diceCollection1 = new DiceCollection(diceSet1);
            var diceCollection2 = new DiceCollection(diceSet2);

            diceCollection1.Roll();
            diceCollection2.Roll();

            Assert.AreEqual(4, diceCollection1 - diceCollection2);
        }
 public override void DisplayDiceRoll( Player p, DiceCollection roll )
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
 private void Subscribe(DiceCollection diceCollection)
 {
     diceCollection.Subscribe(this);
 }
Beispiel #28
0
 public void DiceCollection_ConstructorInvalid_ThrowsException(int value, int count)
 {
     _ = new DiceCollection(value, count);
 }
Beispiel #29
0
 public MainWindowViewModel()
 {
     Dice = new DiceCollection();
 }
Beispiel #30
0
        public void AddToCount_AddInvalid_ThrowsException(int value, int count, int countToAdd, int expected)
        {
            var diceCollection = new DiceCollection(value, count);

            diceCollection.AddToCount(countToAdd);
        }
Beispiel #31
0
 public BasicRules(DiceCollection diceCollection)
 {
     this.diceCollection = diceCollection;
 }
Beispiel #32
0
 //public UIManager( string uiMode )
 //{
 //    if( uiMode.Equals( "CLI", StringComparison.OrdinalIgnoreCase ) )
 //    {
 //        Mode = graphicsMode.CLI;
 //    }
 //    else if( uiMode.Equals( "GUI", StringComparison.OrdinalIgnoreCase ) )
 //    {
 //        Mode = graphicsMode.GUI;
 //    }
 //    else
 //    {
 //        throw new Exception( "UIMode Setting invalid." );
 //    }
 //}
 public override void DisplayDiceRoll( Player p, DiceCollection roll )
 {
     switch( this.Mode )
     {
         case graphicsMode.CLI:
             Console.Write( "{0} rolled ", p.Name );
             foreach( KingsburgDie d in roll )
             {
                 Console.Write( d.ToString() + " " );
             }
             Console.WriteLine();
             break;
         case graphicsMode.GUI:
             throw new NotImplementedException();
     }
 }
Beispiel #33
0
        public override DiceCollection DisplayChooseDice( Player p, Advisor a )
        {
            switch( this.Mode )
            {
                case graphicsMode.CLI:
                    DiceCollection toReturn;
                    SumComboFinder sc = new SumComboFinder();
                    List<List<KingsburgDie>> combos = sc.Find( a.Order, p.RemainingDice );

                    // Return the only combo if there is only one
                    if( combos.Count == 1 )
                    {
                        toReturn = new DiceCollection( combos[0] );
                    }
                    else
                    {
                        Console.WriteLine( "\n{0}, pick which dice combo to use:", p.Name );
                        foreach( List<KingsburgDie> combo in combos )
                        {
                            Console.Write( "{0}: ", combos.IndexOf( combo ) );
                            foreach( KingsburgDie d in combo )
                            {
                                Console.Write( "{0}, ", d );
                            }
                            Console.WriteLine();
                        }
                        Console.WriteLine( "\"*\" indicates a white die." );
                        int chosenCombo = -1;
                        do
                        {
                            string input = Console.ReadLine();
                            chosenCombo = int.Parse( input );
                        }
                        while( chosenCombo == -1 || chosenCombo + 1 > combos.Count );
                        toReturn = new DiceCollection( combos[chosenCombo] );
                    }
                    return toReturn;
                case graphicsMode.GUI:
                    throw new NotImplementedException();
                default:
                    throw new Exception();
            }
        }
Beispiel #34
0
 public YatzyRules(DiceCollection diceCollection)
 {
     this.diceCollection = diceCollection;
     BasicRules          = new BasicRules(diceCollection);
 }
 public abstract void DisplayDiceRoll(Player p, DiceCollection roll);