Randomization Logic

I'm trying to lay down good logic for randomization that makes sense, and wonder if I've made some oversights in my planning. I know there are efficiency optimizations that can be done, but wrapping my head around this one by itself has already bent my brains into a pretzel so that will come later. Variables:
NotProcessedResourceNodes (sorted by class and then by purity from pure->impure)
NotProcessedPossibleLocations (this is already in pseudorandom order based on seed)

NotProcessedSingleResourceNodes
NotProcessedSinglePossibleLocations
NotProcessedResourceNodes (sorted by class and then by purity from pure->impure)
NotProcessedPossibleLocations (this is already in pseudorandom order based on seed)

NotProcessedSingleResourceNodes
NotProcessedSinglePossibleLocations
Processing Logic
- While there are still nodes in NotProcessedResourceNodes (starting with the last one and working towards first one)
- Check to ensure we still have NotProcessedResourceNodes and we still have NotProcessedPossibleLocations available, otherwise break out of the loop
- If it's one of the non-groupable classes, add it to NotProcessedSingleResourceNodes and remove from NotProcessedResourceNodes.
- Otherwise, grab the last index of NotProcessedPossibleLocations
- Feed this possible location and the current list of all Possible locations into LocationGrouper, and recursively check what other NotProcessedPossibleLocations are within GroupingRadius. We use recursion to ensure we will get multiple resources that are all in a row or otherwise very close but are not all within the radius of the starting NotProcessedPossibleLocations.
- Return the list (and the list of their corresponding indexes in NotProcessedPossibleLocations) for each location within the group.
- If we have only 1 location in the group, then we use a Counter % 4 != 0 that's initialized at the start to give it a deterministic 25% chance of being used. If it fails (75% chance), then we insert the location to the NotProcessedSinglePossibleLocations and remove it from NotProcessedPossibleLocations.
- While there are still nodes in NotProcessedResourceNodes (starting with the last one and working towards first one)
- Check to ensure we still have NotProcessedResourceNodes and we still have NotProcessedPossibleLocations available, otherwise break out of the loop
- If it's one of the non-groupable classes, add it to NotProcessedSingleResourceNodes and remove from NotProcessedResourceNodes.
- Otherwise, grab the last index of NotProcessedPossibleLocations
- Feed this possible location and the current list of all Possible locations into LocationGrouper, and recursively check what other NotProcessedPossibleLocations are within GroupingRadius. We use recursion to ensure we will get multiple resources that are all in a row or otherwise very close but are not all within the radius of the starting NotProcessedPossibleLocations.
- Return the list (and the list of their corresponding indexes in NotProcessedPossibleLocations) for each location within the group.
- If we have only 1 location in the group, then we use a Counter % 4 != 0 that's initialized at the start to give it a deterministic 25% chance of being used. If it fails (75% chance), then we insert the location to the NotProcessedSinglePossibleLocations and remove it from NotProcessedPossibleLocations.
5 Replies
Beef
BeefOP4d ago
- If it succeeds or we have more than 1 location in the group, then
- We assign the first location to the node.location value, and add it to ProcessedResourceNodes
- We remove the location from NotProcessedPossibleLocations and the node from NotProcessedResourceNodes
- For each additional location, we check to see if there is a NotProcessedResourceNodes which has the same ResourceClass as the node
- If there is, then we compare it's .purity value with the .purity value of our already assigned node
- If the first assigned node has purity of EResourcePurity::RP_Pure, then the new node must not be RP_Inpure.
- If the first assigned node has a purity of EResourcePurity::RP_Inpure, then the new node must not be RP_Pure.
- If the first assigned node has a purity of EResourcePurity::RP_Normal, then the new node must be RP_Inpure.
- If it succeeds or we have more than 1 location in the group, then
- We assign the first location to the node.location value, and add it to ProcessedResourceNodes
- We remove the location from NotProcessedPossibleLocations and the node from NotProcessedResourceNodes
- For each additional location, we check to see if there is a NotProcessedResourceNodes which has the same ResourceClass as the node
- If there is, then we compare it's .purity value with the .purity value of our already assigned node
- If the first assigned node has purity of EResourcePurity::RP_Pure, then the new node must not be RP_Inpure.
- If the first assigned node has a purity of EResourcePurity::RP_Inpure, then the new node must not be RP_Pure.
- If the first assigned node has a purity of EResourcePurity::RP_Normal, then the new node must be RP_Inpure.
- If the node passes one of these tests, then we assign the location to this node, add it to ProcessedResourceNodes and remove this location (using its index) from the list of NotProcessedPossibleLocations and the node from the NotProcessedResourceNodes
- If we cannot find a node of the same resource class that pass any of the purity tests, then we will assign a node of same Resource class if it exists and has the same ResourceClass, add it to ProcessedResourceNodes, and remove this location from the list of NotProcessedPossibleLocations and the node from the NotProcessedResourceNodes.
In the event there is *not* a NotProcessedResourceNodes which has the same ResourceClass as the node, then we will add this location to NotProcessedSinglePossibleLocations and remove it from NotProcessedPossibleLocations

- As this loops around, the number of NotProcessedResourceNodes should decrease to 0. Once it does, we will then take what remains of NotProcessedPossibleLocations and add it to NotProcessedSinglePossibleLocations.

- Then, for each location in NotProcessedSinglePossibleLocations
- we will simply assign this location to each of the remaining NotProcessedSinglePossibleLocations.
- If the node passes one of these tests, then we assign the location to this node, add it to ProcessedResourceNodes and remove this location (using its index) from the list of NotProcessedPossibleLocations and the node from the NotProcessedResourceNodes
- If we cannot find a node of the same resource class that pass any of the purity tests, then we will assign a node of same Resource class if it exists and has the same ResourceClass, add it to ProcessedResourceNodes, and remove this location from the list of NotProcessedPossibleLocations and the node from the NotProcessedResourceNodes.
In the event there is *not* a NotProcessedResourceNodes which has the same ResourceClass as the node, then we will add this location to NotProcessedSinglePossibleLocations and remove it from NotProcessedPossibleLocations

- As this loops around, the number of NotProcessedResourceNodes should decrease to 0. Once it does, we will then take what remains of NotProcessedPossibleLocations and add it to NotProcessedSinglePossibleLocations.

- Then, for each location in NotProcessedSinglePossibleLocations
- we will simply assign this location to each of the remaining NotProcessedSinglePossibleLocations.
Jarno
Jarno4d ago
:adithinka: Randomizers that my kind of thing :adisweata: sorry i find this all very complicated to what your trying todo i guess you want to randomize resources nodes? then generate a list of all vanilla nodes and just change thier locations amoung eachother right? you will probably need some logic as you forexample dont want all few sulfur nodes ending up behind explosive barriars
Beef
BeefOP4d ago
that's correct I just am trying to ensure like-resources are grouped (aside from optional exceptions like uranium/sam etc) and then we go through the remaining single ones, and leave a couple outliers to toss around randomly for now I have more or less random randomization and its "ok" but not great no matter what there'll be a chance all the sulfur ends up behind explosive barriers, if not literally then proverbially, but it should be a low chance. I'll have an option to re-roll resources but that may be a a idea to allow re-rolling selectively (e.g. re-roll only sulfur/uranium) :interesting: but that adds complexity as i'll need to have nested seeds so that's a down the road one I already have the list of the properties of vanilla and modded resource nodes and their locations, which are stored in NotProcessedResourceNodes (sorted by class and then by purity from pure->impure) and NotProcessedPossibleLocations (this is already in a pseudorandom order based on seed)
Jarno
Jarno4d ago
ideally you dont just shuffle locations but add a bit of logic in like allowed locations, start with all directly accessable locations, (maybe even only those near the starting location) then place coal/coper/iron/limestone then you know your player can get to vehicles, so you place extend the pool of accessable locations with locations further away then place caterium / sulfur then you know your player has access to coal + sulfur, so you know they can make explosives, so add all explosive locked locations to the pool
Beef
BeefOP4d ago
Ah I see what you're suggesting The only issue is I now have to hardcode locations or at least regions to some degree to spawn resources in, vs right now its flexible to handle modded resources I like the idea though, theres certainly a way to implement it and ill figure something out :interesting:
Want results from more Discord servers?
Add your server