Exemple #1
0
    public void LotteryEnterAggregateTest()
    {
        Lottery <int> lottery = new Lottery <int>();

        lottery.Enter(3, 2);
        lottery.Enter(3, 3);
        lottery.Enter(3, 1);
        Assert.That(lottery.GetTickets(3) == 6);
    }
Exemple #2
0
    public void LotteryRemoveDrawTest()
    {
        Lottery <int> lottery = new Lottery <int>();

        lottery.Enter(1, 2);
        lottery.Enter(2, 10);
        lottery.Remove(1, 1);
        lottery.Remove(2);
        Assert.AreEqual(1, lottery.Draw());
    }
Exemple #3
0
    public void LotterySimpleBatchDrawTest()
    {
        Lottery <int> lottery = new Lottery <int>(1);

        lottery.Enter(5, 20);
        lottery.Enter(3, 10);

        lottery.StartBatchDraw();
        var result = lottery.Draw(3);

        Assert.That(result[0] == 5 && result[1] == 3 ||
                    result[0] == 3 && result[1] == 5);
        Assert.AreEqual(default(int), result[2]);
    }
Exemple #4
0
    public void LotteryBlacklistDrawTest()
    {
        Lottery <int> lottery = new Lottery <int>();

        lottery.Enter(1);
        lottery.Enter(2);
        lottery.Enter(3);
        lottery.Enter(4);

        int result = lottery.Draw(new HashSet <int> {
            1, 3, 4
        });

        Assert.AreEqual(2, result);
    }
Exemple #5
0
    void TestLotteryPerformance()
    {
        Stopwatch timer = new Stopwatch();

        // setup
        Lottery <int> lottery   = new Lottery <int>(1000000);
        HashSet <int> blacklist = new HashSet <int>();

        for (int i = 0; i < 10000; i++)
        {
            lottery.Enter(i % 100, 100);
            if (i != 69)
            {
                blacklist.Add(i);
            }
        }
        lottery.StartBatchDraw();

        timer.Start();

        // actual test
        lottery.Draw(100);

        timer.Stop();
        Debug.Log($"Test took {timer.Elapsed.ToString("fffffff").Insert(3, ".").TrimStart('0')} ms");
    }
Exemple #6
0
    public void Lottery10000EnterTest()
    {
        Lottery <int> lottery = new Lottery <int>(1000000);
        Random        rng     = new Random();

        Dictionary <int, int> tickets = new Dictionary <int, int>(10000);

        for (int i = 0; i < 10000; i++)
        {
            int entrant = rng.Next();
            int n       = rng.Next(100) + 1;
            lottery.Enter(entrant, n);

            if (tickets.ContainsKey(entrant))
            {
                tickets[entrant] += n;
            }
            else
            {
                tickets.Add(entrant, n);
            }
        }

        foreach (var entrant in tickets.Keys)
        {
            Assert.That(tickets[entrant] == lottery.GetTickets(entrant));
        }
    }
Exemple #7
0
    public void LotterySimpleEnterTest()
    {
        Lottery <int> lottery = new Lottery <int>();

        lottery.Enter(1);
        Assert.That(lottery.GetTickets(1) == 1);
    }
Exemple #8
0
    public void LotteryRemoveTest()
    {
        Lottery <int> lottery = new Lottery <int>(3);

        lottery.Enter(1, 5);
        lottery.Enter(2, 10);
        lottery.Enter(3, 3);

        lottery.Remove(2, 4);
        Assert.That(lottery.GetTickets(2) == 6);
        lottery.Remove(2);
        Assert.That(lottery.GetTickets(2) == 0);
        lottery.Remove(1, 2);
        Assert.That(lottery.GetTickets(1) == 3);
        Assert.AreEqual(3, lottery.GetTickets(3));
    }
Exemple #9
0
    public void LotterySimpleDrawTest()
    {
        Lottery <int> lottery = new Lottery <int>();

        lottery.Enter(3);

        Assert.That(lottery.Draw() == 3);
    }
Exemple #10
0
    public void LotterySimpleRemoveTest()
    {
        Lottery <int> lottery = new Lottery <int>(1);

        lottery.Enter(2, 5);
        lottery.Remove(2, 2);
        Assert.AreEqual(3, lottery.GetTickets(2));
    }
Exemple #11
0
 public AffixPool(params AffixType[] types)
 {
     lottery = new Lottery <AffixType>();
     foreach (AffixType t in types)
     {
         lottery.Enter(t, 1);
     }
 }
Exemple #12
0
    public void LotteryReferenceDrawTest()
    {
        Lottery <TestReference> lottery = new Lottery <TestReference>();
        var reference = new TestReference();

        lottery.Enter(reference, 10);

        Assert.That(ReferenceEquals(reference, lottery.Draw()));
    }
Exemple #13
0
    /// <summary>
    /// Generates the Affixes and BaseAffixes for an item
    /// </summary>
    protected void GenerateAffixes(Item item)
    {
        item.Affixes.Clear();
        item.BaseAffixes.Clear();

        foreach (AffixType affixType in BaseAffixes)
        {
            item.BaseAffixes.Add(AffixInfo.GetAffixInfo(affixType).GenerateAffix(item.Tier));
        }

        // Create new lottery to decide tier roll of each affix
        // TODO: make nicer
        Lottery<int> tierLottery = new Lottery<int>();
        tierLottery.Enter(item.Tier, 10);
        if (item.Tier > 1)
            tierLottery.Enter(item.Tier - 1, 5);
        if (item.Tier > 2)
            tierLottery.Enter(item.Tier - 2, 2);
        if (item.Tier > 3)
            tierLottery.Enter(item.Tier - 3, 1);

        int quality = item.Quality;  

        // Guaranteed affixes don't care about possible pool
        foreach (AffixType affixType in GuaranteedAffixes)
        {
            int tier = tierLottery.Draw();
            tier = tier > quality ? quality : tier;
            item.Affixes.Add(AffixInfo.GetAffixInfo(affixType).GenerateAffix(tier));
            quality -= tier;
        }
        
        // Fill up the rest of the affixes
        Affix[] randomAffixes = PossibleAffixes.GetUniqueRandomAffixes(quality, tierLottery, new HashSet<AffixType>(GuaranteedAffixes));
        foreach (Affix affix in randomAffixes)
        {
            item.Affixes.Add(affix);
        }
    }
Exemple #14
0
    /// <summary>
    /// Puts this lottery into batch drawing mode with a preexisting blacklist.
    /// </summary>
    public void StartBatchDraw(HashSet <T> blacklist)
    {
        if (blacklist == null)
        {
            StartBatchDraw();
        }

        batchLottery = new Lottery <T>(entrants.Count);

        foreach (var e in entrantBlocks.Keys.Where(key => !blacklist.Contains(key)))
        {
            batchLottery.Enter(e, entrantBlocks[e].TotalSize);
        }
    }
Exemple #15
0
    public void LotteryRandom10000BatchDrawTest()
    {
        Lottery <int> lottery = new Lottery <int>(1000000);

        for (int i = 0; i < 10000; i++)
        {
            lottery.Enter(i);
        }

        lottery.StartBatchDraw();
        var result = lottery.Draw(10000);

        HashSet <int> set = new HashSet <int>();

        foreach (var item in result)
        {
            Assert.That(!set.Contains(item));
            set.Add(item);
        }
    }
Exemple #16
0
    /// <summary>
    /// Generates the areas for the map
    /// </summary>
    /// <param name="AreaTierCalculation">
    /// A Function that calculates the Tier for an area, gets called after the area
    /// has all cells set that will be in this area
    /// </param>
    void GenerateAreas(Func <Area, int> AreaTierCalculation)
    {
        System.Random rng = new System.Random((int)DateTime.Now.Ticks);
        // lottery for area size
        #region Area Size Lottery
        Lottery <int> lottery = new Lottery <int>();
        lottery.Enter(1, 30);
        lottery.Enter(2, 50);
        lottery.Enter(3, 42);
        lottery.Enter(4, 17);
        #endregion

        List <HexCell> nextPossibleAreaCenters = new List <HexCell> {
            this[0, 0]
        };
        //int i= 0;
        while (nextPossibleAreaCenters.Count > 0)
        {
            HexCell AreaBegin = nextPossibleAreaCenters[rng.Next(0, nextPossibleAreaCenters.Count)];
            nextPossibleAreaCenters.Remove(AreaBegin);
            List <HexCell> possibleCellsForArea = new List <HexCell>(GetNeighborsWithoutArea(AreaBegin));

            Area newArea = new Area(lottery.Draw());
            Areas.Add(newArea.AreaID, newArea);
            newArea.TryEstablishRelationWithCell(AreaBegin);
            //Debug.Log("Map::GenerateAreas - Chose Cell: " + AreaBegin.ToString());
            #region Fill area
            while (!newArea.IsFull() &&
                   possibleCellsForArea.Count > 0)
            {
                // get random cell from possible entries
                HexCell cell = possibleCellsForArea[rng.Next(0, possibleCellsForArea.Count)];
                //Debug.Log("Map::GenerateAreas - Chose Cell: " + cell.ToString());
                // add to area

                newArea.TryEstablishRelationWithCell(cell);

                // if cell was added to area
                // remove slectred cell form possneighbors and
                // if in nextPossibleAreaCenters remove it as well
                if (cell.ParentArea != null)
                {
                    possibleCellsForArea.Remove(cell);
                    if (nextPossibleAreaCenters.Contains(cell))
                    {
                        //Debug.Log("Map::GenerateAreas - Removing cell from next possible area centers list");
                        nextPossibleAreaCenters.Remove(cell);
                    } // end if next area begin contains
                }     // end if cell parent area null

                // get all neigbors without areas from this recently added cell
                // add them to possible neighbors
                foreach (HexCell c in GetNeighborsWithoutArea(cell))
                {
                    if (!possibleCellsForArea.Contains(c))
                    {
                        possibleCellsForArea.Add(c);
                    }
                }
            }// end while area not full and poss neighbors count > 0
            #endregion

            newArea.SetTier(AreaTierCalculation(newArea));
            //area finsihed
            //Debug.Log("Map::GenerateAreas - Finiehsd Area: "+ newArea.ToString());
            // add all cells in poss neigbors that are not already in nextPossibleAreaCenters to the list of
            // next possible area Centers
            //Debug.Log(possibleCellsForArea.Count + " cells left in possible cells for area");
            #region Adding outline of cells adjacent to cell with area assigned
            foreach (HexCell c in possibleCellsForArea)
            {
                if (!nextPossibleAreaCenters.Contains(c))
                {
                    //Debug.Log("Adding cell");
                    nextPossibleAreaCenters.Add(c);
                }
            }
            #endregion
        }// end while next poss area begins  count > 0
    }