/// <summary> /// Generates Events and Tickets Data, then return the list of events that have been generated /// </summary> /// <param name="eventsGenerated">Output the list of events had been generated</param> /// <param name="eventsToGenerate">A user specified number of evnets being generated. Assign a negative number for a random quantity.</param> /// <param name="clearAllData">True: Wipe all the exsiting events and tickets data</param> public static void GenerateData(out List <Event> eventsGenerated, int eventsToGenerate = -1, bool clearAllData = false) { if (clearAllData) { //Clear all events and tickets data in the corresponding lists in World World.Events.Clear(); World.Tickets.Clear(); //Reset the next event id variable World.NextEventId = 0; } //Quantity of events being generated int eventsQuantity; //Check if the 'eventsToGenerate' (user set) has a genuine value (greater than 0) if (eventsToGenerate > 0) { //Apply the number and limit it to the remaining capcity of the world eventsQuantity = (int)Math.Min(eventsToGenerate, World.RemainingEventCapacity); } else //User has not specified a number, randomize the quantity to generate { //Set the quantity range of events generation Range generateRange = EventAmountRangeAdjusted; //Randomize the quantity of events being generated (int) from the range eventsQuantity = (int)Mathc.RandomRange(generateRange); } //Generate the events with the random value and output it eventsGenerated = GenerateEvents(eventsQuantity); //Add the events that have been generated World.AddEvents(eventsGenerated); }
/// <summary> ///Generate and return Random coordinates /// </summary> /// <param name="GeneratedEvents"></param> /// <returns>A random and valid coordinates</returns> public static Vector2 Randomcoordinates(List <Event> GeneratedEvents = null) { Vector2 coordinates; //Repeat generating coordinates until it is valid do { double x; double y; switch (World.CoordinateSystem) { default: case World.coordinateSystem.Integer: //Randomize the x and y value within the world axis range //Adding 1 to the max value are exclusive when convert to int (Unless the random is exactly 1 which is impossible) x = Mathc.RandomRange(World.AxisX.min, World.AxisY.max + 1); y = Mathc.RandomRange(World.AxisY.min, World.AxisY.max + 1); //Create a new coordinates(Vector2) coordinates = new Vector2(Math.Floor(x), Math.Floor(y)); break; //Randomize the x and y value within the world axis range case World.coordinateSystem.Decimal: x = Mathc.RandomRange(World.AxisX); y = Mathc.RandomRange(World.AxisY); //Convert the coordinates into decimal places and create a new coordinates (Vector2) coordinates = new Vector2(Mathc.ConvertToDecimalPlace(x, World.DecimalPlacesForDecimalCoordinateSystem), Mathc.ConvertToDecimalPlace(y, World.DecimalPlacesForDecimalCoordinateSystem)); break; } } while (!validCoordinates(coordinates, GeneratedEvents)); //Check if the coordinates are valid, repeat if invalid return(coordinates); }
/// <summary> /// Generates and returns a single event in a specific location /// </summary> /// <param name="location">The specific location the event being generated</param> /// <returns>A single Event object</returns> public static Event GenerateEvent(Vector2 location) { Event evt = new Event(location); // Create a new event object int totalTickets = (int)Mathc.RandomRange(ticketAmountRange); //Randomize the quantity of total ticket evt.AddTickets(GenerateTickets(totalTickets, TicketPriceRange)); //Generate a list of Ticket objects and pass it to the Event object return(evt); }
/// <summary> /// Generates and return a list of Ticket objects with random quantities and price /// </summary> /// <param name="totalTickets">The total quanity of tickets (NOT a Ticket object)</param> /// <param name="priceRange">The price range of tickets</param> /// <returns>A list of tickets</returns> static List <Ticket> GenerateTickets(int totalTickets, Range priceRange) { //Create a new list to store Ticket objects for the event List <Ticket> _tickets = new List <Ticket>(); //Generate Ticket objects until the totalTickets is 0 while (totalTickets > 0) { //Represent the quantity of tickets being generated int ticketQuantity = (int)Mathc.RandomRange(1, totalTickets); //Randomize the price with the range double ticketPrice = Mathc.RandomRange(priceRange); //Generate a new Ticket Object _tickets.Add(new Ticket(ticketPrice, ticketQuantity)); //Reduce the totalTickets value totalTickets -= ticketQuantity; } return(_tickets); //Return the whole list }
/// <summary> /// Sort and returns a list of events based on the distance between the event and the coodinates (Accending order) /// </summary> /// <param name="events">The list of events to sort</param> /// <param name="coodinates">The specific coodinate</param> /// <returns></returns> public static List <Event> SortedEventsInDistance(List <Event> events, Vector2 coodinates) { List <Event> _events = events; //Copy the list //Sort list by comparing distance between inputed location and each event's location _events.Sort( delegate(Event e1, Event e2) { //Compare the distance (lower first) int compare = Mathc.Distance(e1.Location, coodinates).CompareTo(Mathc.Distance(e2.Location, coodinates)); //If distance are the same, compare their lowest ticket price (lower first) if (compare == 0) { //If both of them have 0 tickets, return 0 (No change in order) if (e1.Tickets.Count < 1 && e2.Tickets.Count < 1) { compare = 0; } //If e1 has 0 tickets, return 1 (e1 increase the index) else if (e1.Tickets.Count < 1) { compare = 1; } //If e2 has 0 tickets, return -1 (e1 reduce the index) else if (e2.Tickets.Count < 1) { compare = -1; } //If e1 and e2 both have tickets, compare their ticket price else { compare = SortedTicketsInPrice(e1.Tickets)[0].Price.CompareTo(SortedTicketsInPrice(e2.Tickets)[0].Price); } } return(compare); }); return(_events); }