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.
13 Replies
Beef
BeefOPā€¢3mo 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
Jarnoā€¢3mo 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
BeefOPā€¢3mo 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
Jarnoā€¢3mo 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
BeefOPā€¢3mo 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:
Robb
Robbā€¢2mo ago
even all few sulfur nodes behind barriers is not a problem because you can use portable miners to mine even when they're blocked. but certainly something to keep in mind
Rex
Rexā€¢2mo ago
There's a bunch of resource deposits scattered around too
Jarno
Jarnoā€¢2mo ago
I doubt you want to put collecting resources around the map in logic, however I did not know you could place portable miners near it
letsbsanta
letsbsantaā€¢4w ago
Is the purity of a node able to be changed at run? Might be able to just change that value and still get a wildly different feel from one save to the next
Beef
BeefOPā€¢4w ago
I am altering the types/locations/purities of nodes already - altering only purity feels bad when i was testing as grasslands becomes overpowered and other places underpowered in terms of resource availability i figured what i'd consider a new "default" recently - basically just increasing the grouping radius so that resources tend to clump together into regions. It feels challenging as resources are geographically distant when you want to combine things but also still plentiful where they are found
letsbsanta
letsbsantaā€¢4w ago
Do you have a build uploaded yet? Iā€™d be interested in giving this a few runs
Beef
BeefOPā€¢4w ago
my personal recommendation for now, either at newgame or in the savegame settings menu change the max node grouping distance to the highest value and re-roll to get the "regions" of resources however play around with it and see what you like šŸ™‚

Did you find this page helpful?