thomas_2023/day_5/Maps.gd

64 lines
1.8 KiB
GDScript3
Raw Normal View History

2023-12-09 14:31:28 -05:00
class_name Maps
var seed2soil = []
var soil2fertilizer = []
var fertilizer2water = []
var water2light = []
var light2temperature = []
var temperature2humidity = []
var humidity2location = []
func _apply_map(map, input):
for entry in map:
# If something maps then use that
var out = entry.apply(input)
if out != null:
return out
return input
func find_closest(seed):
# Wholly nested loops
# TODO: This shit probably needs to become a precompiled map
# depending on what part2 wants me to do
# I assume ill be walking this backwards to find out what can be planted where?\
var soil = _apply_map(seed2soil, seed)
print("seed " + str(seed) + " -> soil " + str(soil))
var fert = _apply_map(soil2fertilizer, soil)
print("soil " + str(soil) + " -> fert " + str(fert))
var water = _apply_map(fertilizer2water, fert)
print("fert " + str(fert) + " -> water " + str(water))
var light = _apply_map(water2light, water)
print("water " + str(water) + " -> light " + str(light))
var temp = _apply_map(light2temperature, light)
print("light " + str(light) + " -> temp " + str(temp))
var hum = _apply_map(temperature2humidity, temp)
print("temp " + str(temp) + " -> hum " + str(hum))
var loc = _apply_map(humidity2location, hum)
print("hum " + str(hum) + " -> loc " + str(loc))
return loc
func _to_string():
return "seed2soil\n" + \
str(len(self.seed2soil)) + "\n" + \
"soil2fertilizer\n" + \
str(len(self.soil2fertilizer)) + "\n" + \
"fertilizer2water\n" + \
str(len(self.fertilizer2water)) + "\n" + \
"water2light\n" + \
str(len(self.water2light)) + "\n" + \
"light2temperature\n" + \
str(len(self.light2temperature)) + "\n" + \
"temperature2humidity\n" + \
str(len(self.temperature2humidity)) + "\n" + \
"humidity2location\n" + \
str(len(self.humidity2location)) + "\n"