tfwr/main.py
2026-05-04 00:25:13 +09:30

46 lines
1.1 KiB
Python

import farm
from __builtins__ import *
def my_min(values):
result = values[0]
i = 1
while i < len(values):
if values[i] < result:
result = values[i]
i += 1
return result
HAY_TARGET = 100
WOOD_TARGET = 100
CARROT_TARGET = get_world_size() * get_world_size() * 3
while True:
hay = num_items(Items.Hay)
wood = num_items(Items.Wood)
carrots = num_items(Items.Carrot)
pumpkins = num_items(Items.Pumpkin)
hay_deficit = HAY_TARGET - hay
wood_deficit = WOOD_TARGET - wood
# Floors first
if hay_deficit > 0 or wood_deficit > 0:
if hay_deficit >= wood_deficit:
farm.hay()
else:
farm.wood()
else:
# Pick the single lowest of the four
lowest = my_min([hay, wood, carrots, pumpkins])
if pumpkins == lowest and carrots >= CARROT_TARGET:
farm.pumpkin()
elif carrots == lowest:
farm.carrot()
elif wood == lowest:
farm.wood()
else:
farm.hay()
# Movement between cycles (only relevant for non-pumpkin since
# farm.pumpkin() controls its own movement and presumably returns
# the drone somewhere predictable)
if get_pos_y() == 0:
move(East)
move(North)