public void GetNRandomDoubles(int n) { var collection = RandomCollection.Random().Take(n); System.Console.WriteLine($"Get {n} items from an infinte collection"); ConsoleEx.WriteCollection <double>(collection); }
public void randomSymbolTest() { RandomCollection random = new RandomCollection(); string s = random.randomSymbol(); Assert.IsNotNull(s); }
public void randomIntTest() { RandomCollection randomCollection = new RandomCollection(); int i = randomCollection.randomInt(2, 2); Assert.AreEqual(2, i); }
public void WeightsOfZeroValueShouldNotBeIncluded() { var hi = new[] { new WeightedItem <Guid>(Guid.NewGuid(), 1), new WeightedItem <Guid>(Guid.NewGuid(), 0) }; var rc = new RandomCollection <Guid>(hi); rc.AsItems().Count().Should().Be(1, "An item of 0 weight should never be included in results"); }
static void Main() { RandomCollection r = new RandomCollection(15); foreach (int i in r) { Console.Write($"{i} "); } Console.WriteLine(); foreach (int i in r) { Console.Write($"{i} "); } }
private static RandomCollection <string> BuildRandomGuidCollection(int count) { var items = new List <WeightedItem <string> >(); var r = new Random(); for (var i = 0; i < count; i++) { var key = r.Next(1, 100); items.Add(new WeightedItem <string>(Guid.NewGuid().ToString(), key)); } var q = new RandomCollection <string>(items); return(q); }
public Player(RawNode initNode, RawNode repositoryNode) { this.repositoryNode = repositoryNode; dataSources = new DataSources(); var simpleResources = new SimpleResourceCollection(initNode.GetNode("simple-resources"), new SimpleResourceCategories(), this, new SimpleResourceDataSource(repositoryNode.GetNode("simple-resources"), this)); var objects = new SomeModelCollection(initNode.GetNode("objects"), new SomeModelCategories(), this, new SomeModelDataSource(repositoryNode.GetNode("objects"), this)); var random = new RandomCollection(initNode.GetNode("random"), new RandomCategories(), this, new RandomDataSource(repositoryNode.GetNode("random"), this)); var cities = new CityCollection(initNode.GetNode("cities"), new CityCategories(), this, new CityDescriptionDataSource(repositoryNode.GetNode("cities"), this)); AddChild(random); AddChild(simpleResources); AddChild(objects); AddChild(cities); }
public override TaskReturnValue Run(HierarchicalBlackboard blackboard) { RandomCollection.Shuffle(Children); return(base.Run(blackboard)); }
//Connect any number of points on the level grid. void ConnectPoints(LevelBlockRequirements[,] basicGrid, List<Point> points) { if (points.Count == 0) return; //Choose a random point and connect that to each other point. //This automatically guarantees that each point is connected to each other point, as //you can always travel to the first point and then to the target point. Point point = points.GetRandomItem(); for (int i = 0; i < points.Count; i++) { Point otherPoint = points[i]; if (point == otherPoint) continue; //Check how far we have to travel Point distanceDifference = new Point(otherPoint.X - point.X, otherPoint.Y - point.Y); //And store the directions we have to take into a RandomCollection of directions RandomCollection<Direction> directionsToTravel = new RandomCollection<Direction>(); if (distanceDifference.X < 0) directionsToTravel.Add(Direction.Left, -distanceDifference.X); if (distanceDifference.X > 0) directionsToTravel.Add(Direction.Right, distanceDifference.X); if (distanceDifference.Y < 0) directionsToTravel.Add(Direction.Up, -distanceDifference.Y); if (distanceDifference.Y > 0) directionsToTravel.Add(Direction.Down, distanceDifference.Y); //Then actually travel from the first point to the second one. Point position = point; while (directionsToTravel.Count != 0) { switch (directionsToTravel.Take()) { case Direction.Left: basicGrid[position.X, position.Y].LeftSideType = SideType.Exit; position.X -= 1; basicGrid[position.X, position.Y].RightSideType = SideType.Exit; break; case Direction.Right: basicGrid[position.X, position.Y].RightSideType = SideType.Exit; position.X += 1; basicGrid[position.X, position.Y].LeftSideType = SideType.Exit; break; case Direction.Up: basicGrid[position.X, position.Y].TopSideType = SideType.Exit; position.Y -= 1; basicGrid[position.X, position.Y].BottomSideType = SideType.Exit; break; case Direction.Down: basicGrid[position.X, position.Y].BottomSideType = SideType.Exit; position.Y += 1; basicGrid[position.X, position.Y].TopSideType = SideType.Exit; break; } } } }