Added Power farming with Sunflower support and utility methods
This commit is contained in:
parent
6c896867fc
commit
582bf2219e
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
5
__utils__.py
Normal file
5
__utils__.py
Normal file
@ -0,0 +1,5 @@
|
||||
def pow(integer: int, exp: int):
|
||||
result = 1
|
||||
for _ in range(exp):
|
||||
result *= integer
|
||||
return result
|
||||
55
farm.py
55
farm.py
@ -51,20 +51,20 @@ def goto(x, y):
|
||||
move(dy_dir)
|
||||
|
||||
|
||||
|
||||
|
||||
def hay():
|
||||
if can_harvest():
|
||||
harvest()
|
||||
if get_entity_type() == None and get_ground_type() != Grounds.Grassland:
|
||||
till()
|
||||
|
||||
|
||||
def bush():
|
||||
if can_harvest():
|
||||
harvest()
|
||||
if get_entity_type() == None or get_entity_type() == Entities.Grass:
|
||||
plant(Entities.Bush)
|
||||
|
||||
|
||||
def carrot():
|
||||
if can_harvest():
|
||||
harvest()
|
||||
@ -73,6 +73,7 @@ def carrot():
|
||||
till()
|
||||
plant(Entities.Carrot)
|
||||
|
||||
|
||||
def wood():
|
||||
if can_harvest():
|
||||
harvest()
|
||||
@ -81,6 +82,8 @@ def wood():
|
||||
plant(Entities.Tree)
|
||||
else:
|
||||
plant(Entities.Bush)
|
||||
|
||||
|
||||
def pumpkin_old():
|
||||
dead_kins = set()
|
||||
while True:
|
||||
@ -104,9 +107,8 @@ def pumpkin_old():
|
||||
move(East)
|
||||
move(North)
|
||||
|
||||
def pumpkin():
|
||||
wsize = get_world_size()
|
||||
|
||||
def pumpkin():
|
||||
# Build queue of all coords needing an alive pumpkin
|
||||
pending = []
|
||||
for x in range(wsize):
|
||||
@ -137,4 +139,47 @@ def pumpkin():
|
||||
pending.append(target)
|
||||
|
||||
harvest()
|
||||
|
||||
|
||||
|
||||
def sunflower():
|
||||
flowers = {}
|
||||
|
||||
# Setup: plant every tile, record petal count
|
||||
for x in range(wsize):
|
||||
for y in range(wsize):
|
||||
goto(x, y)
|
||||
harvest_except(Entities.Sunflower)
|
||||
auto_till()
|
||||
if get_entity_type != Entities.Sunflower:
|
||||
plant(Entities.Sunflower)
|
||||
flowers[(x, y)] = measure()
|
||||
|
||||
# Harvest highest-petal-count first
|
||||
while len(flowers) > 0:
|
||||
# Find the (key, value) pair with the largest value
|
||||
best_key = None
|
||||
best_val = -1
|
||||
for key in flowers:
|
||||
v = flowers[key]
|
||||
if v > best_val:
|
||||
best_val = v
|
||||
best_key = key
|
||||
|
||||
# Go harvest it
|
||||
bx = best_key[0]
|
||||
by = best_key[1]
|
||||
goto(bx, by)
|
||||
harvest()
|
||||
# Remove from dict so next iteration picks the next highest
|
||||
flowers.pop(best_key)
|
||||
|
||||
|
||||
|
||||
|
||||
def harvest_except(excluded_entity):
|
||||
if get_entity_type() != excluded_entity and can_harvest():
|
||||
harvest()
|
||||
|
||||
def auto_till():
|
||||
if get_ground_type() != Grounds.Soil:
|
||||
till()
|
||||
16
main.py
16
main.py
@ -1,24 +1,20 @@
|
||||
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
|
||||
from __utils__ import *
|
||||
HAY_TARGET = 100
|
||||
WOOD_TARGET = 100
|
||||
CARROT_TARGET = get_world_size() * get_world_size() * 3
|
||||
POWER_TARGET = pow(get_world_size(), 2)
|
||||
CARROT_TARGET = pow(get_world_size(), 2) * 3
|
||||
while True:
|
||||
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)
|
||||
|
||||
hay_deficit = HAY_TARGET - hay
|
||||
wood_deficit = WOOD_TARGET - wood
|
||||
power_deficit = POWER_TARGET - power
|
||||
|
||||
# Floors first
|
||||
if hay_deficit > 0 or wood_deficit > 0:
|
||||
@ -26,6 +22,8 @@ while True:
|
||||
farm.hay()
|
||||
else:
|
||||
farm.wood()
|
||||
elif power_deficit > 0:
|
||||
farm.sunflower()
|
||||
else:
|
||||
# Pick the single lowest of the four
|
||||
lowest = min(hay, wood, carrots, pumpkins)
|
||||
|
||||
@ -1 +1 @@
|
||||
{"items":{"serializeList":[{"name":"hay","nr":10158.0},{"name":"wood","nr":14107.0},{"name":"carrot","nr":8677.0},{"name":"pumpkin","nr":12127.0}]},"dockedFiles":[{"key":"main","value":"farm"}],"minimizedFiles":[],"openFilePositions":[{"key":"farm","value":{"x":-1031.4744873046875,"y":1670.5185546875}},{"key":"main","value":{"x":1484.2628173828125,"y":1700.00048828125}}],"openFileScrollPositions":[{"key":"farm","value":3164.333984375},{"key":"main","value":807.3118286132813}],"openFileSizes":[{"key":"farm","value":{"x":0.0,"y":861.5}},{"key":"main","value":{"x":1013.6471557617188,"y":600.0}}],"openDocPages":[],"unlocks":["grass_5","soil","harvest","pass","do_a_flip","pet_the_piggy","grassland","hay","straw_hat","tap","while","true","false","break","continue","loops","can_harvest","if","else","elif","speed_5","traffic_cone","move","north","south","east","west","expand_6","for","range","get_world_size","wood","bush","entities","clear","plant","change_hat","gray_hat","purple_hat","green_hat","brown_hat","hats","and","or","not","operators","carrot","till","can_trade","trade","items","carrot_seed","carrots_4","get_entity_type","get_ground_type","grounds","get_pos_x","get_pos_y","none","num_items","num_unlocked","senses","variables","functions","def","return","global","trees_4","tree","tree_hat","carrot_hat","append","remove","pop","insert","len","list","lists","print","quick_print","unlocks","str","debug","pumpkins_4","pumpkin","pumpkin_seed","dead_pumpkin","import","from","pumpkin_hat","utilities","min","max","abs","random","dictionaries","dicts","sets","add","dict","set","costs","get_cost","auto_unlock","unlock"],"version":3}
|
||||
{"items":{"serializeList":[{"name":"hay","nr":25030.0},{"name":"wood","nr":22989.0},{"name":"carrot","nr":24080.0},{"name":"pumpkin","nr":25951.0},{"name":"water","nr":507.0},{"name":"fertilizer","nr":267.0},{"name":"power","nr":2755.3881666666807}]},"dockedFiles":[],"minimizedFiles":[],"openFilePositions":[{"key":"farm","value":{"x":-947.4608154296875,"y":2463.12451171875}},{"key":"main","value":{"x":172.9576416015625,"y":2470.416015625}},{"key":"docs0","value":{"x":-1906.639892578125,"y":884.713134765625}},{"key":"docs1","value":{"x":-1937.482421875,"y":1556.6673583984375}},{"key":"docs2","value":{"x":-590.66552734375,"y":1308.072021484375}},{"key":"__utils__","value":{"x":785.8156127929688,"y":1809.6502685546875}}],"openFileScrollPositions":[{"key":"farm","value":4288.9580078125},{"key":"main","value":-0.0008544921875},{"key":"__utils__","value":0.0}],"openFileSizes":[{"key":"farm","value":{"x":0.0,"y":861.5}},{"key":"main","value":{"x":1554.4163818359375,"y":880.614990234375}},{"key":"docs0","value":{"x":900.0,"y":700.0}},{"key":"docs1","value":{"x":900.0,"y":700.0}},{"key":"docs2","value":{"x":900.0,"y":700.0}},{"key":"__utils__","value":{"x":0.0,"y":0.0}}],"openDocPages":[{"key":"docs0","value":"docs/unlocks/sunflowers.md"},{"key":"docs1","value":"docs/scripting/dicts.md"},{"key":"docs2","value":"docs/unlocks/sunflowers.md"}],"unlocks":["grass_5","soil","harvest","pass","do_a_flip","pet_the_piggy","grassland","hay","straw_hat","tap","while","true","false","break","continue","loops","can_harvest","if","else","elif","speed_5","traffic_cone","move","north","south","east","west","expand_6","for","range","get_world_size","wood","bush","entities","clear","plant","change_hat","gray_hat","purple_hat","green_hat","brown_hat","hats","and","or","not","operators","carrot","till","can_trade","trade","items","carrot_seed","carrots_5","get_entity_type","get_ground_type","grounds","get_pos_x","get_pos_y","none","num_items","num_unlocked","senses","variables","functions","def","return","global","trees_5","tree","tree_hat","carrot_hat","append","remove","pop","insert","len","list","lists","print","quick_print","unlocks","str","debug","pumpkins_4","pumpkin","pumpkin_seed","dead_pumpkin","from","import","pumpkin_hat","min","max","abs","random","utilities","dicts","sets","add","dict","set","dictionaries","get_cost","costs","unlock","auto_unlock","water","use_item","get_water","watering","sunflower_seed","sunflower","power","get_active_power","measure","sunflowers","weird_substance","fertilizer","sunflower_hat"],"version":3}
|
||||
Loading…
x
Reference in New Issue
Block a user