public void Test() { List<int> nums = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; RangeRandom<int> random = new RangeRandom<int>(nums); var results = random.Generate(5); Assert.IsNotNull(results); Assert.AreEqual(results.Count, 5); Assert.IsTrue(results.Max() <= 10); Assert.IsTrue(results.Min() >= 1); }
private void OnChangeOptions(IPlayer player, GameOptions options) { Log.Default.WriteLine(LogLevels.Info, "ChangeOptions:{0} {1}", player.Name, options); IPlayer masterPlayer = _playerManager.ServerMaster; if (masterPlayer == player && State == ServerStates.WaitingStartGame) { // Remove duplicates (just in case) options.SpecialOccurancies = options.SpecialOccurancies.GroupBy(x => x.Value).Select(x => x.First()).ToList(); options.PieceOccurancies = options.PieceOccurancies.GroupBy(x => x.Value).Select(x => x.First()).ToList(); // Check options before accepting them bool accepted = RangeRandom.SumOccurancies(options.PieceOccurancies) == 100 && RangeRandom.SumOccurancies(options.SpecialOccurancies) == 100 && options.InventorySize >= 1 && options.InventorySize <= 15 && options.LinesToMakeForSpecials >= 1 && options.LinesToMakeForSpecials <= 4 && options.SpecialsAddedEachTime >= 1 && options.SpecialsAddedEachTime <= 4 && options.DelayBeforeSuddenDeath >= 0 && options.DelayBeforeSuddenDeath <= 15 && options.SuddenDeathTick >= 1 && options.SuddenDeathTick <= 30 && options.StartingLevel >= 0 && options.StartingLevel <= 100; if (accepted) { Options = options; // Options will be sent to players when starting a new game _pieceProvider.Occurancies = () => Options.PieceOccurancies; // Inform other players/spectators about options modification foreach (IEntity entity in Entities.Where(e => e != player)) { entity.OnOptionsChanged(Options); } } else { Log.Default.WriteLine(LogLevels.Info, "Invalid options"); } } else { Log.Default.WriteLine(LogLevels.Info, "Cannot change options"); } }
static void Main(string[] args) { //Program p = new Program(); //p.TestSpectator(); List <IntOccurancy> occurancies = new List <IntOccurancy> { new IntOccurancy { Value = 0, Occurancy = 10, }, new IntOccurancy { Value = 1, Occurancy = 10, }, new IntOccurancy { Value = 2, Occurancy = 10, }, new IntOccurancy { Value = 3, Occurancy = 10, }, new IntOccurancy { Value = 4, Occurancy = 10, }, new IntOccurancy { Value = 5, Occurancy = 10, }, new IntOccurancy { Value = 6, Occurancy = 10, }, new IntOccurancy { Value = 7, Occurancy = 10, }, new IntOccurancy { Value = 8, Occurancy = 10, }, new IntOccurancy { Value = 9, Occurancy = 10, }, }; int[] history = { 1, 2, 3, 4 }; int r = RangeRandom.Random(occurancies, history); }