In DTC, I’m having a problem with prioritizing mines. There are some instances in which a material has such a low priority that none of the ordered mines have the material. I need to make it so at least one mine produces every material.
Right now I’m looking at putting that in miningAlgorithm
after the priority has been calculated, but before the mine has been chosen.
First, I need to see how many minable materials I’m working with. I could loop through needsList
again, but there may be a better place to do this, such as counting at the time each material is being pushed to needsList
. We’ll call that number minableNeeds
.
Then, I’ll check to see if we’ve assigned almost all the other mines already. I want the top priorities assigned first, then at the end check for orphaned materials. Something like if (i > availableMines - minableNeeds)
Next I have to go through each of needsList
(yet again) to make sure that the material is minable. If it is, check it against sortingMines
to see if the material is being mined. If not, then I have to loop through all the mines and find the one with the material and the highest howMuch
.
I wonder if looping through the same data over and over is common, or if I’ve set myself up for frustration from the beginning. I also think it may be time to break up some of my bigger functions. miningAlgorithm
alone is up to about 85 lines.
Actually, that may be the solution to my problem. If I split the second half of miningAlgorithm
into its own function, I can pass it any material I want, not strictly the material with the highest priority.
So I’ll calculate the highest priority in one function, then decide whether I need to override that priority with an orphaned material. The winner of that battle gets passed into the mine choosing function.
I’ll get to work on that tomorrow.