tfwr/main.py

75 lines
2.2 KiB
Python

import drone
import farm
from __builtins__ import *
from __utils__ import *
HAY_TARGET = 100
WOOD_TARGET = 100
POWER_TARGET = pow(get_world_size(), 2)
CARROT_TARGET = pow(get_world_size(), 2) * 3
MAZE_SIZE = 16
drone.goto_origin()
def main():
while True:
drone.goto_origin()
hay = num_items(Items.Hay)
wood = num_items(Items.Wood)
carrots = num_items(Items.Carrot)
pumpkins = num_items(Items.Pumpkin)
power = num_items(Items.Power)
substance = num_items(Items.Weird_Substance)
fertilizer = num_items(Items.Fertilizer)
gold = num_items(Items.Gold)
cactus = num_items(Items.Cactus)
hay_deficit = HAY_TARGET - hay
wood_deficit = WOOD_TARGET - wood
power_deficit = POWER_TARGET - power
maze_cost = MAZE_SIZE * pow(2, num_unlocked(Unlocks.Mazes) - 1)
grid = farm.WORLD_SIZE * farm.WORLD_SIZE
# Floors first — these gate everything (basic inputs / power supply)
if hay_deficit > 0 or wood_deficit > 0:
if hay_deficit >= wood_deficit:
farm.hay()
else:
farm.wood()
elif power_deficit > 0:
farm.sunflower()
else:
# Floors met — balance everything by raw count, top up the lowest.
# Each resource is only a candidate if its prereqs are met.
candidates = [(hay, "hay"), (wood, "wood"), (carrots, "carrot"), (cactus, "cactus")]
if carrots >= CARROT_TARGET:
candidates.append((pumpkins, "pumpkin"))
if fertilizer >= grid:
candidates.append((substance, "substance"))
if substance >= maze_cost:
candidates.append((gold, "maze"))
best = candidates[0]
for c in candidates:
if c[0] < best[0]:
best = c
choice = best[1]
if choice == "hay":
farm.hay()
elif choice == "wood":
farm.wood()
elif choice == "carrot":
farm.carrot()
elif choice == "cactus":
farm.cactus()
elif choice == "pumpkin":
farm.pumpkin()
elif choice == "substance":
farm.substance()
else:
farm.maze()
# Movement between cycles (only relevant for non-pumpkin since
# farm.pumpkin() controls its own movement and presumably returns
# the drone somewhere predictable)
drone.goto_next()
if get_water() < 0.25 and num_items(Items.Water) >= farm.pow(farm.WORLD_SIZE, 2):
farm.water()
main()