don't overbuild bots

This commit is contained in:
Luke Hubmayer-Werner 2022-12-20 00:03:57 +10:30
parent db2a2f451e
commit d2cfb99823
1 changed files with 20 additions and 17 deletions

View File

@ -18,6 +18,7 @@ def blueprintQuality(line: String, tMax: Int=24): (Int, Int, Int) =
val cost_geodebot_ore = nums(5) val cost_geodebot_ore = nums(5)
val cost_geodebot_obs = nums(6) val cost_geodebot_obs = nums(6)
val max_cost_ore = cost_orebot_ore max cost_claybot_ore max cost_obsbot_ore max cost_geodebot_ore
val maxPossibleInXMinutes = (0 to 32).toArray val maxPossibleInXMinutes = (0 to 32).toArray
for i <- 1 to 32 do for i <- 1 to 32 do
@ -40,7 +41,7 @@ def blueprintQuality(line: String, tMax: Int=24): (Int, Int, Int) =
nextRes(2) -= cost_geodebot_obs nextRes(2) -= cost_geodebot_obs
mostGeodes = mostGeodes max simStep(tn, numRobots, nextRes, totalGeodes + (tMax-tn), mostGeodes) mostGeodes = mostGeodes max simStep(tn, numRobots, nextRes, totalGeodes + (tMax-tn), mostGeodes)
// Try to make an Obs robot // Try to make an Obs robot
if numRobots(1) > 0 then if numRobots(1) > 0 && numRobots(2) < cost_geodebot_obs then
dt = 1 max (((cost_obsbot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build dt = 1 max (((cost_obsbot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build
dt = dt max (((cost_obsbot_clay - numRes(1)) ceilDiv numRobots(1)) + 1) // Must always spend at least 1 minute to build dt = dt max (((cost_obsbot_clay - numRes(1)) ceilDiv numRobots(1)) + 1) // Must always spend at least 1 minute to build
tn = t + dt tn = t + dt
@ -52,23 +53,25 @@ def blueprintQuality(line: String, tMax: Int=24): (Int, Int, Int) =
nextRes(1) -= cost_obsbot_clay nextRes(1) -= cost_obsbot_clay
mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes) mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes)
// Try to make an Ore robot // Try to make an Ore robot
dt = 1 max (((cost_orebot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build if numRobots(0) < max_cost_ore then
tn = t + dt dt = 1 max (((cost_orebot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build
if tn < (tMax-1) then // any ore past that point is worthless tn = t + dt
val nextRobots = numRobots.toArray if tn < (tMax-1) then // any ore past that point is worthless
nextRobots(0) += 1 val nextRobots = numRobots.toArray
val nextRes = (numRes zip numRobots).map((b,f) => b + f*dt).toArray nextRobots(0) += 1
nextRes(0) -= cost_orebot_ore val nextRes = (numRes zip numRobots).map((b,f) => b + f*dt).toArray
mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes) nextRes(0) -= cost_orebot_ore
mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes)
// Try to make a Clay robot // Try to make a Clay robot
dt = 1 max (((cost_claybot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build if numRobots(1) < cost_obsbot_clay then
tn = t + dt dt = 1 max (((cost_claybot_ore - numRes(0)) ceilDiv numRobots(0)) + 1) // Must always spend at least 1 minute to build
if tn < (tMax-2) then // any clay past that point is worthless, needs to turn to obs tn = t + dt
val nextRobots = numRobots.toArray if tn < (tMax-2) then // any clay past that point is worthless, needs to turn to obs
nextRobots(1) += 1 val nextRobots = numRobots.toArray
val nextRes = (numRes zip numRobots).map((b,f) => b + f*dt).toArray nextRobots(1) += 1
nextRes(0) -= cost_claybot_ore val nextRes = (numRes zip numRobots).map((b,f) => b + f*dt).toArray
mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes) nextRes(0) -= cost_claybot_ore
mostGeodes = mostGeodes max simStep(tn, nextRobots, nextRes, totalGeodes, mostGeodes)
return totalGeodes max mostGeodes return totalGeodes max mostGeodes
val mostGeodes = simStep(0, Vector(1,0,0).toArray, Vector(0,0,0).toArray) val mostGeodes = simStep(0, Vector(1,0,0).toArray, Vector(0,0,0).toArray)