
编程农场




一个用于解决迷宫的极简嵌套函数方案。 其工作原理: 一个用于解决迷宫的极简嵌套函数方案。 定义执行分支(起点): 若获取实体类型()等于实体.宝藏: 收获() 返回真 若起点不等于西方且可移动(西方): 移动(西方) 若执行分支(东方): 返回真 若起点不等于北方且可移动(北方): 移动(北方) 若执行分支(南方): 返回真 若起点不等于东方且可移动(东方): 移动(东方) 若执行分支(西方): 返回真 若起点不等于南方且可移动(南方): 移动(南方) 若执行分支(北方): 返回真 移动(起点) 返回假 循环: 清除() 种植(实体.灌木) 使用物品(物品.奇异物质,获取世界大小()) 测量() 执行分支(南方) 此方案的工作方式?我们有一个简单的函数,它会针对无人机从当前位置可以移动的所有方向进行自我调用。如果找到宝藏,它将折叠所有函数树并生成一个新的迷宫。此代码会根据你的世界大小创建最大尺寸的迷宫。 这适用于单个无人机。我将更新为支持多个无人机的版本。

The maze levels are very different than the remainder of the game. It's possible that, while enjoying the rest of the game, someone may get stuck on a maze and end up just finding a solution. The goal of this guide is to walk someone through the process of solving the maze without simply providing a solution (although a working implementation is included). General maze-solving technique The mazes in The Farmer Was Replaced contain no loops, meaning the easiest method of solving the maze is to follow the left wall. It is not the most efficient solution given full knowledge of the maze, it is a classic technique used in both corn fields and firefighting. It will always lead to the exit (or in this case a certain square) eventually and requires no knowledge other than the wall state of the left. This guide implements this by taking every left turn whenever possible and testing if the floor beneath the drone contains the treasure. Since the drone harvesting on any square other than the treasure ends the maze, the treasure must be detected prior to attempting to collect it. The components of the program are as follows: Create Maze Navigate Maze Find Treasure Collect Treasure Collecting the treasure is trivial, but there remaining sections have multiple parts. Creating the maze The maze is created by using fertilizer on a bush, but currently has a low percentage of success. This means the drone needs to check if the maze has been created prior to beginning navigation. Since the maze replaces the bush, the drone can check to see if the bush exists to determine if the fertilization was successful. Using a while loop ensures that the drone will keep trying until the maze is spawned. Automating this system has a few issues, the largest of which is fertilizer isn't free. You can purchase fertilizer in the while loop, but this also means that you are continuously spending pumpkins. Without error checking, the drone could be stuck in an endless loop, hovering over a bush. As an example: #We require a bush to generate the maze. Code assumes clear() has been called plant(Entities.Bush) #This will continuously loop until the bush goes away (indicating the maze has spawned) while get_entity_type() == Entities.Bush: trade(Items.Fertilizer) use_item(Items.Fertilizer) if num_items(Items.Pumpkin) < 10: #If we can't afford more fertilizer return #Leave this function entirely Navigating the maze Navigation seems difficult, but can be broken down into a very simple procedure: If there's no wall to your left, turn and go left. If you can't go left, go straight. If you can't go straight, turn and go right. If you can't go right, turn around and back up. Since there's no way to sense a wall, the drone can only sense if it's moved. Therefore we need to *attempt* to move in a direction then detect if our position changed. The movement can be simplified by using a heading and realizing that testing for a left-hand wall is identical to trying to turn left and move forward. Therefore we can redefine the movement as: Turn left Try to move forward If drone has not moved, turn right and try to move forward until drone moves I implemented this as follows: # Directions based on the right hand rule # This is required because movement requires a cardinal direction as an object, # and switch statements made of if/elif take much more space. dirs = [North,West,South,East] dir = 0 #Starting direction -- North #... oldx = get_pos_x() oldy = get_pos_y() move(dirs[dir]) # Finds direction object from list and moves that way while checkmove(oldx,oldy) == False: # While the drone hasn't moved... dir += 1 #...turn left... if dir > 3: #...and if we just turned North... dir = 0 #...reset to zero... move(dirs[dir]) #...then move forward. dir -= 1 # Now that we've moved, turn right... if dir < 0: #...and if we turned East... dir = 3 #...reset to 3 with this as a support function: #Returns true if drone has moved from position X,Y. Else returns false def checkmove(X,Y): if X != get_pos_x(): return True if Y != get_pos_y(): return True return False Detecting/collecting the treasure A fairly simple section, there are two major ways to implement this. Finding the treasure is a matter of checking the ground, similarly to a plant. if get_entity_type() == Entities.Treasure: The above conditional statement can act as a trigger, or it can be modified in a while loop to navigate while the treasure isn't present, then break the loop once it's found. Once found, a simple harvest() will collect the treasure and end the maze. Implementation I highly encourage you to work out the problem on your own; it's incredibly satisfying and there are many alternate solutions and implementations. The joy is in the creation, not the having. But if you want a working implementation for reference or simply want to not do it yourself, I'm not here to tell you how to have fun. def Maze(): clear() # Setting board to known state dirs = [North,West,South,East] # See above dir = 0 oldx = 1 # Begin homing to 1,1 (not necessary) oldy = 1 while get_pos_x() != 1: move(West) while get_pos_y() != 1: move(South) # End homing plant(Entities.Bush) # Begin maze spawning, see above while get_entity_type() == Entities.Bush: trade(Items.Fertilizer) use_item(Items.Fertilizer) if num_items(Items.Pumpkin) < 10: harvest() return while get_entity_type() != Entities.Treasure: # Navigate the maze until drone sees the treasure oldx = get_pos_x() # See above for notes oldy = get_pos_y() move(dirs[dir]) while checkmove(oldx,oldy) == False: dir += 1 if dir > 3: dir = 0 move(dirs[dir]) dir -= 1 if dir < 0: dir = 3 harvest() # We spawned the maze and navigated until we see treasure beneath us. Collect it. def checkmove(X,Y): if X != get_pos_x(): return True if Y != get_pos_y(): return True return False The code is self contained, just enter the two functions and call "maze". You should have all required unlocks by the time you're trying to implement maze runs. I had a blast making this and writing it up. Hope you have as much fun implementing it!

This is my best program, consisting of three parts: The first program is a very good algorithm that tracks the tail's position and navigates to the apples quite optimally. The second program simply follows the edge of the field. If the tail is in the way, we climb up to x = 1 and then descend. If we detect an apple on the way up, we simply climb up to it. The third program, without tracking apples, repeats the movements, covering the entire field. Это моя лучшая программа из 3 частей: Первая программа очень хороший алгоритм отслеживающий положение хвоста и довольно оптимально идущий к яблокам Вторая программа просто едем по краю поля, Если на пути хвост, то поднимаемся до x = 1 и потом опускаемся Если фиксируем, что при подъеме будет яблоко, то просто поднимаемся к нему Третья программа без отслеживания яблок повторяем движения покрывая все поле Ссылка на мой youtube: https://www.youtube.com/@Andrey_Besjashiy/videos Ссылка на видео с объяснением кода: https://youtu.be/K3Tu9fWnKYw Programm clear() # Глобальные переменные для отслеживания хвоста tail = [] # список позиций хвоста: [(x0,y0), (x1,y1), ...], голова НЕ включена tail_length = 0 world_size = get_world_size() middle_tail = [] # список позиций хвоста [y и когда достигает] def simple_move_like_snake(): xnew = get_pos_x() ynew = get_pos_y() WorldSize = get_world_size() moved = False if xnew == 0 and ynew > 0: if not move(South): return False moved = True elif ynew % 2 == 0: if xnew == WorldSize - 1: if not move(North): return False moved = True else: if not move(East): return False moved = True elif xnew == 1 and ynew != WorldSize - 1: if not move(North): return False moved = True else: if not move(West): return False moved = True return moved # Двигаемся змейкой def move_like_snake(): xnew = get_pos_x() ynew = get_pos_y() WorldSize = get_world_size() moved = False if xnew == 0 and ynew > 0: if not move(South): return False add_to_tail(xnew, ynew - 1) moved = True elif ynew % 2 == 0: if xnew == WorldSize - 1: if not move(North): return False add_to_tail(xnew, ynew + 1) moved = True else: if not move(East): return False add_to_tail(xnew + 1, ynew) moved = True elif xnew == 1 and ynew != WorldSize - 1: if not move(North): return False add_to_tail(xnew, ynew + 1) moved = True else: if not move(West): return False add_to_tail(xnew - 1, ynew) moved = True return moved def move_to_YX(next_x, next_y): x = get_pos_x() y = get_pos_y() any_move = False while next_y > y: IfMove = move(North) if not IfMove: break add_to_tail(x, y + 1) y = get_pos_y() any_move = True while next_x < x: IfMove = move(West) if not IfMove: break x = get_pos_x() add_to_tail(x - 1, y) any_move = True if not any_move: move_like_snake() def reset_tail(): global tail global tail_length tail = [] tail_length = 0 def add_to_tail(x, y): #"""Добавить старую позицию головы в хвост""" global tail global tail_length tail.insert(0, (x, y)) # новая голова была здесь if len(tail) > tail_length: tail.pop() # удаляем кончик хвоста (он освобождается) def movement_to_point(next_x, next_y): x = get_pos_x() y = get_pos_y() return abs(next_x - x) + abs(next_y - y) def not_in_tail(next_x, next_y): global tail road = 0 y= get_pos_y() if y > next_y: next_y = y for i in range(next_y): if (next_x, y) in tail: x = get_pos_x() y = get_pos_y() road = abs(x - next_x) + abs(y - next_y) return road def move_not_tail(next_x, next_y): x = get_pos_x() y = get_pos_y() global tail global tail_length i = 0 for (x_tail, y_tail) in tail: i += 1 if x_tail != 0: if y_tail > y and y_tail <= next_y: count_movement = tail_length - i - movement_to_point(x_tail, y_tail) + 3 if count_movement > 0: return count_movement return 0 def move_to_apple(next_x, next_y): x = get_pos_x() y = get_pos_y() moved = False if x == 0: IfMove = move(East) if not IfMove: return False add_to_tail(x + 1, y) moved = True x = get_pos_x() if x > next_x and y % 2 == 0 and x != 0: IfMove = move(North) if not IfMove: return False add_to_tail(x, y + 1) moved = True elif x < next_x and y % 2 == 1 and x != 0: IfMove = move(North) if not IfMove: return False add_to_tail(x, y + 1) moved = True y = get_pos_y() while x != next_x: if move_like_snake(): moved = True else: break x = get_pos_x() while y < next_y: IfMove = move(North) if not IfMove: return False add_to_tail(x, y + 1) y = get_pos_y() moved = True return moved def move_not_tail_x0(): x = get_pos_x() y = get_pos_y() global tail global tail_length i = 0 for (x_tail, y_tail) in tail: i += 1 if x_tail == 0 and y_tail >= y: count_movement = tail_length - i - movement_to_point(x_tail, y_tail) + 3 if count_movement > 0: return count_movement return 0 def move_to_tail_x0(): x = get_pos_x() y = get_pos_y() moved = False if y % 2 == 0 and x != 0: IfMove = move(North) if not IfMove: return False add_to_tail(x, y + 1) return True else: while x != 0: IfMove = move(West) if not IfMove: break moved = True add_to_tail(x - 1, y) x = get_pos_x() return moved def check_apple(next_x, next_y): x = get_pos_x() y = get_pos_y() global tail global tail_length if x == next_x and y == next_y: next_x, next_y = measure() tail_length += 1 return next_x, next_y def new_snake(target): global tail global tail_length WorldSize = get_world_size() next_x, next_y = measure() tail_length += 1 move_like_snake() count_movement = 0 while tail_length < target: x = get_pos_x() y = get_pos_y() while count_movement > 0: if x == next_x and y == next_y: next_x, next_y = measure() tail_length += 1 move_like_snake() count_movement -= 1 x = get_pos_x() y = get_pos_y() if x == next_x and y == next_y: if tail_length < target - 1: next_x, next_y = measure() tail_length += 1 else: break if tail_length > target: if not simple_move_like_snake(): break elif y == WorldSize -1: if not move_like_snake(): break elif next_x == 0: count_movement = not_in_tail(next_x, next_y) if count_movement == 0: move_to_YX(next_x, next_y) elif y > next_y and x != 0: count_movement = move_not_tail_x0() if count_movement == 0: if not move_to_tail_x0(): x = get_pos_x() y = get_pos_y() if x == next_x and y == next_y: next_x, next_y = measure() tail_length += 1 move_like_snake() elif not move_like_snake(): break elif x == 0: if y < next_y: count_movement = move_not_tail(next_x, next_y) if count_movement == 0: if move(East): add_to_tail(x + 1, y) else: move_like_snake() if not move_like_snake(): break else: count_movement = move_not_tail(next_x, next_y) if count_movement == 0: if not move_to_apple(next_x, next_y): x = get_pos_x() y = get_pos_y() if x == next_x and y == next_y: next_x, next_y = measure() tail_length += 1 move_like_snake() else: if not move_like_snake(): break return next_x, next_y def late_snake(): while True: if not simple_move_like_snake(): break def midle_snake(target, next_x, next_y): global tail_length WorldSize = get_world_size() while tail_length < target: x = get_pos_x() y = get_pos_y() next_x, next_y = check_apple(next_x, next_y) if x == WorldSize - 1: if y == WorldSize - 1: simple_move_like_snake() elif (y == next_y - 2 or y == next_y - 1) and y < WorldSize - 2: new_len = x - next_x move(North) for i in range(new_len): simple_move_like_snake() next_x, next_y = check_apple(next_x, next_y) move(North) elif move(North): next_x, next_y = check_apple(next_x, next_y) move(North) else: next_x, next_y = check_apple(next_x, next_y) simple_move_like_snake() elif not simple_move_like_snake(): break return next_x, next_y WorldSize = get_world_size() while num_items(Items.Bone) > 33488928: change_hat(Hats.Dinosaur_Hat) reset_tail() next_x, next_y = new_snake(WorldSize*3) next_x, next_y = midle_snake(WorldSize*WorldSize / 3, next_x, next_y) late_snake() change_hat(Hats.Straw_Hat)
每分钟获取200万金币并解锁Maze Master成就的代码。 概述 该策略是创建16个迷宫,每个迷宫配备一个无人机,使用基本的沿墙走法来创建路径。沿着路径前进,直到收集到200/300个宝藏,然后移除足够的迷宫墙壁,使非优化的最短路径算法能够高效收集所需金币。 此过程存在一定随机性,但首次运行时应能成功,它需要几项解锁功能、32x32的世界大小、16架以上的无人机等条件。 代码 将此代码复制粘贴到游戏中,然后运行并等待。 clear() maze_size = 8 grid_size = 4 def move_to(x,y): while x != get_pos_x(): move(East) while y !无法识别或无法翻译,已删除。无法识别或无法翻译,已删除。无法识别或无法翻译,已删除。无法翻译,已删除。
本指南提供了《农夫被替换了》的经过测试且可正常运行的代码脚本,能帮助你高效推进游戏进程。非常适合想要了解自动化概念并查看实际应用示例的玩家。 1. 来自decimalist's code的辅助工具 鸣谢:decimalist's code 我们使用了这位优秀同行的这些库/辅助工具。你可能会问为什么?嗯,我不想自己编写这些内容,所以借用了它们,你可以自行查找名为“decimalist's code”的资源并复制所有工具代码。 2.现在,你来到这里的目的: 草地和树木的代码(我们绝对没有偷,只是借用了一下): clear() ws = get_world_size() for i in range(ws): for j in range(ws): # 偶数种植 - 树木 if (i % 2 == 1 and j % 2 == 0) or (i % 2 == 0 and j % 2 == 1): plant(Entities.Tree) else: # 非偶数 - 种植草地 if get_ground_type() != Grounds.Soil: plant(Entities.Grass) move(East) move(North) while True: for i in range(ws): for j in range(ws): curr_ent = get_entity_type() if curr_ent == Entities.Tree and can_harvest(): harvest() plant(Entities.Tree) elif curr_ent == Entities.Grass and can_harvest(): harvest() move(East) move(North) 3.胡萝卜和木材的代码: clear() ws = get_world_size() for i in range(ws): for j in range(ws): # 偶数区域种植树木 if (i % 2 == 1 and j % 2 == 0) or (i % 2 == 0 and j % 2 == 1): plant(Entities.Tree) else: # 非偶数区域种植胡萝卜 if get_ground_type() != Grounds.Soil: till() plant(Entities.Carrot) move(East) move(North) while True: for i in range(ws): for j in range(ws): curr_ent = get_entity_type() if curr_ent == Entities.Tree and can_harvest(): harvest() plant(Entities.Tree) elif curr_ent == Entities.Carrot and can_harvest(): harvest() if get_ground_type() != Grounds.土壤: 耕地() 种植(实体.胡萝卜) 移动(东) 移动(北) 4. 胡萝卜、南瓜、木材的代码 (在上述指南的朋友更新代码前,快速简单的 farming 代码): 清除() 世界尺寸 = 获取世界尺寸() 南瓜行数 = 2 # 在此设置南瓜行数 默认:2 对于 i 在 0 到 世界尺寸-1 范围内: 对于 j 在 0 到 世界尺寸-1 范围内: 如果 i < 南瓜行数: 如果获取地面类型() 不等于 地面.土壤: 耕地() 种植(实体.南瓜) 否则如果 (i 除以 2 的余数等于 1 且 j 除以 2 的余数等于 0) 或 (i 除以 2 的余数等于 0 且 j 除以 2 的余数等于 1): 种植(实体.树) 否则: 如果获取地面类型() 不等于 地面.土壤: 耕地() 种植(实体.(内容无法识别,已删除)南瓜) elif curr_ent == None: # 空槽位 if get_ground_type() != Grounds.Soil: 耕地() 种植(Entities.Pumpkin) # 农场其余部分 胡萝卜 - 树木 elif curr_ent == Entities.Tree and can_harvest(): 收获() 种植(Entities.Tree) elif curr_ent == Entities.Carrot and can_harvest(): 收获() if get_ground_type() != Grounds.Soil: 耕地() 种植(Entities.Carrot) 移动(东) 移动(北) 5.这里没什么好说的——如果你有需要,请留言。
很遗憾,这款游戏没有被翻译成所有语言,因为像这种实用的、教授编程的游戏应该面向所有人,包括那些英语掌握不够熟练的人。有一种观点认为,如果从事编程工作,就应该懂英语或者必须懂英语。这种理念是有害的,因为缺乏翻译很可能会让那些想学习Python但不懂英语的人却步,比如还在上学、没学过英语的孩子。因此,翻译成所有语言非常重要。我第一次翻译这款游戏时,是通过长时间搜索并导出/导入嵌入在Unity资源文件resourses.assets中的文本文件完成的。好在开发者最终将文本文件以便于翻译的格式导出。 说明:俄语翻译(适用于2025年1月23日的游戏版本) 感谢用户SAVEon提供的帮助,使我能够制作本指南。 翻译下载:由于我尚未弄清楚如何在指南中添加可供下载的文件,您可以通过相关渠道获取翻译。(内容包含外部链接,已按规则处理)要展开它,请点击“Assets”一词旁边的三角形。 安装 下载翻译压缩包。打开游戏主文件夹(启动快捷方式所在位置)- SteamLibrary steamapps common The Farmer Was Replaced。如果您难以找到该文件夹,请在Steam库中右键点击游戏,选择【属性】,然后在【已安装文件】选项卡中点击右上角的【浏览】按钮。此时会打开【The Farmer Was Replaced】文件夹。将压缩包中的内容复制到该文件夹,并替换所有文件。安装视频指南 补充信息 目前我发现游戏文件夹中存在德语翻译文件,但未找到在游戏内切换翻译的方法。因此需要替换原始的EN文件。 在游戏新版本中,开发者将所有文本移至单独文件夹,无需再操作resources.assets文件,这显著简化了翻译流程。不过,目前仍无法实现100%的文本翻译。显然,某些字符串和词汇存储在游戏引擎的某个位置,或者是动态生成的。换句话说,所有可翻译的内容都已完成翻译。我甚至在资源文件中都找不到这些字符串……请注意,并非所有文本都已翻译(但这仅占文本总量的一小部分),例如设置中的【Back】按钮、解锁窗口中的部分文本:升级名称、物品名称、【Unlock cost】、【right click for more info】以及【You have {} of them】等字符串。 在包含所有文章链接的主菜单链接部分,以下几个分类的链接尚未进行翻译:【Разблокировки】、【Программирование】、【Предметы】、【Сущности】、【Земля】。这似乎也与游戏版本不完善有关。这不算翻译错误。
It's the cactus farm, with explanations inside the code as comments. You can just copy and paste it in a new file. So, spoilers...I guess. Assorted sorted cacti code: W = get_world_size() WATER_THRESHOLD = 0.75 # ---------- Movement helpers ---------- def go_home(): # Move to (0,0) without wiping the field (do NOT call clear() here). x = get_pos_x() y = get_pos_y() k = 0 while k < x: move(West) k += 1 k = 0 while k < y: move(South) k += 1 def serpentine_row_pass_east_west(): # Position assumed at (0,0). Traverse row by row in serpentine pattern. i = 0 eastward = True while i < W: steps = W - 1 s = 0 while s < steps: if eastward: move(East) else: move(West) s += 1 if i < W - 1: move(North) eastward = not eastward i += 1 def serpentine_row_pass_west_east(): # Same as above but starting by going West first. i = 0 eastward = False while i < W: steps = W - 1 s = 0 while s < steps: if eastward: move(East) else: move(West) s += 1 if i < W - 1: move(North) eastward = not eastward i += 1 # ---------- Tile helpers ---------- def ensure_soil_and_cactus_here(): if get_ground_type() != Grounds.Soil: till() ent = get_entity_type() if ent == None: plant(Entities.Cactus) else: if ent != Entities.Cactus: if can_harvest(): harvest() plant(Entities.Cactus) def maybe_water_after_plant(): if get_water() < WATER_THRESHOLD: use_item(Items.Water) # ---------- Field maintenance ---------- def fill_field_with_cactus(): # One sweep that ensures every tile is cactus on soil (no harvesting mature cacti here). go_home() i = 0 while i < W: j = 0 while j < W: ensure_soil_and_cactus_here() j += 1 if j < W: move(East) if i < W - 1: move(North) i += 1 def all_mature_cacti(): go_home() i = 0 all_ok = True while i < W: j = 0 while j < W: ent = get_entity_type() if ent != Entities.Cactus: all_ok = False else: if not can_harvest(): all_ok = False j += 1 if j < W: move(East) if i < W - 1: move(North) i += 1 return all_ok def trigger_cascade_harvest(): # Only harvest if every cactus is mature; otherwise wait for next cycle if all_mature_cacti(): go_home() if can_harvest(): harvest() # ---------- Sorting passes ---------- def row_compare_swap_pass(): # Bubble once across each row, comparing with the neighbor in the travel direction. # Returns True if any swap happened. go_home() swapped = False i = 0 eastward = True while i < W: # At the start of each row, set how many comparisons we can do j = 0 # We do W-1 comparisons per row, but the neighbor direction changes with 'eastward' while j < W - 1: if eastward: # We're somewhere from col 0..W-2: compare with East neighbor a = measure() # current b = measure(East) # neighbor if a > b: swap(East) swapped = True move(East) else: # Traveling West: we're somewhere from col W-1..1: compare with West neighbor a = measure() # current b = measure(West) # neighbor if a < b: # Put the smaller on the West: swap with West neighbor swap(West) swapped = True move(West) j += 1 # Go up a row and flip direction if i < W - 1: move(North) eastward = not eastward i += 1 return swapped def column_compare_swap_pass(): # Bubble once along each column, always comparing toward North (ascending). # Returns True if any swap happened. go_home() swapped = False col = 0 while col < W: row = 0 while row < W - 1: a = measure() # current b = measure(North) # neighbor above if a > b: swap(North) # put smaller below, larger above swapped = True move(North) row += 1 # go back down to y=0 before stepping to next column while row > 0: move(South) row -= 1 if col < W - 1: move(East) col += 1 return swapped def sort_field_rows_then_columns(): # Repeatedly apply row pass then column pass until no swaps. #This converges to a matrix that is sorted by rows and columns. # Classic alternating relaxation: row-bubble then column-bubble # Continue until a full cycle makes no changes. while True: any_swapped = False s1 = row_compare_swap_pass() if s1: any_swapped = True s2 = column_compare_swap_pass() if s2: any_swapped = True if not any_swapped: break # ---------- Harvest trigger ---------- def trigger_cascade_harvest(): # Harvest from (0,0) once the matrix is sorted and all are mature. go_home() if can_harvest(): harvest() # ---------- Main loop ---------- # 1) Ensure field is filled with cactus clear() fill_field_with_cactus() # 2) Maintenance loop while True: # Let everything grow; keep tiles cactus if anything was disturbed fill_field_with_cactus() go_home() i = 0 while i < W: j = 0 while j < W: if get_water() < WATER_THRESHOLD: use_item(Items.Water) j += 1 if j < W: move(East) if i < W - 1: move(North) i += 1 # 3) If (and only if) every cactus is mature, sort & harvest if all_mature_cacti(): sort_field_rows_then_columns() trigger_cascade_harvest() # After the cascade, the field is cleared—loop will refill and repeat.


With code, so if any new update comes, it's easy to get the new ones. Pure code upgrades You don't lose these for the full reset leaderboard All of them are just one single level. Loops / AKA "While" Item Price Hay 5 Operators / AKA "1 + i" Item Price Hay Wood 150 10 Senses / AKA "(x,y)" Item Price Hay 100 Variables / AKA "a = 2" Item Price Carrot 35 Lists / AKA "[1,2,3]" Item Price Carrot 500 Functions / AKA "def f():" Item Price Carrot 40 Dictionaries / AKA "{1:2}" Item Price Pumpkin 2 500 Import / AKA "import" Item Price Carrot 80 Utilities / AKA "random()" Item Price Pumpkin 1 000 Costs / AKA "get_cost()" Item Price Pumpkin 2 500 Auto_Unlock / AKA "unlock()" Item Price Pumpkin 5 000 Debug codes You lose these on full reset leaderboard, you don't need Debug_2 to complete the leaderboard Debug / AKA Print()" Item Price Hay Wood 50 50 Debug_2 / AKA set_speed()" Item Price Gold 500 Timing / AKA get_time()" Name Price Pumpkin 1 000 Simulation / AKA simulate()" Item Price Gold 5 000 Leaderboards / AKA Print()" Item Price Bone Gold 2 000 000 1 000 000 Farm upgrades Speed Lv Item Price 1 Hay 20 2 Wood 20 3 Wood Carrot 50 50 4 Carrots 500 5 Carrots 1 000 Expand Lv Item Price 1 Hay 30 2 Wood 20 3 Wood Carrots 30 20 4 Wood Carrot 100 50 5 Pumpkin 1 000 6 Pumpkin 8 000 7 Pumpkin 64 000 8 Pumpkin 512 000 9 Pumpkin 4 100 000 Plant Item Price Hay 50 Fertilizer Lv Item Price 1 Wood 500 2 Wood 1 500 3 Wood 9 000 4 Wood 54 000 Watering Lv Item Price 1 Wood 50 2 Wood 200 3 Wood 800 4 Wood 3 200 5 Wood 12 800 6 Wood 51 200 7 Wood 205 000 8 Wood 819 000 9 Wood 3 280 000 Megafarm Lv Item Price 1 Gold 2 000 2 Gold 8 000 3 Gold 32 000 4 Gold 128 000 5 Gold 512 000 Crops Grass Lv Item Unlock Price 1 Hay 100 2 Hay 300 3 Wood 500 4 Wood 2 500 5 Wood 12 500 6 Wood 62 500 7 Wood 312 000 8 Wood 1 560 000 9 Wood 7 810 000 10 Wood 39 100 000 CarrotsPrice to plant: 2**CarrotLevel (Hay + Wood) 512 Hay + 512 Wood at level 10 Lv Item Unlock Price 1 Wood 50 2 Wood 250 3 Wood 1 250 4 Wood 6 250 5 Wood 31 200 6 Wood 156 000 7 Wood 781 000 8 Wood 3 910 000 9 Wood 19 500 000 10 Wood 97 700 000 TreesBushes are unlocked with the Plant upgrade, they're also buffed by the tree's level. Lv Item Unlock Price 1 Wood Carrot 50 70 2 Hay 300 3 Hay 1 200 4 Hay 4 800 5 Hay 19 200 6 Hay 76 800 7 Hay 307 000 8 Hay 1 230 000 9 Hay 4 920 000 10 Hay 19 700 000 SunflowersPrice to plant: 1 Carrot Item Unlock Price Carrot 500 PumpkinsPrice to plant: 2**PumpkinLevel (Carrots) 512 Carrots at level 10 Lv Item Unlock Price 1 Wood Carrot 500 200 2 Carrot 1 000 3 Carrot 4 000 4 Carrot 16 000 5 Carrot 64 000 6 Carrot 256 000 7 Carrot 1 020 000 8 Carrot 4 100 000 9 Carrot 16 400 000 10 Carrot 65 500 000 CactusPrice to plant: 2**CactusLevel (Pumpkin) 64 Pumpkins at level 6 Lv Item Unlock Price 1 Pumpkin 5 000 2 Pumpkin 20 000 3 Pumpkin 120 000 4 Pumpkin 720 000 5 Pumpkin 4 320 000 6 Pumpkin 25 900 000 MazesRecomended substance usage to both spawn a maze and use on chest: substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes)-1) Lv Item Unlock Price 1 Weird Substance 1 000 2 Cactus 12 000 3 Cactus 72 000 4 Cactus 432 000 5 Cactus 2 590 000 6 Cactus 15 600 000 DinosaursPrice to plant: 2**DinossaurLevel (Cactus) 64 Cacti at level 6 Lv Item Unlock Price 1 Cactus 2 000 2 Cactus 12 000 3 Cactus 72 000 4 Cactus 432 000 5 Cactus 2 590 000 6 Cactus 15 600 000 Vanity Hats Item Unlock Price Hay 50 Top Hat Item Unlock Price Hay Wood Carrot Cactus Gold 1 000 000 000 10 000 000 000 1 000 000 000 1 000 000 000 100 000 000 The Farmers Remains Item Unlock Price Bone 100 000 000 Code and how to check it As of the time of writing this guide, these are all the possible upgrades and levels. Since the Output will be too long, you might need to remove a few from the listBuyables to see what you want. #Author RubyNg allCosts = { "Loop" : {"name" : Unlocks.Loops, "max" : 1}, "Hats" : {"name" : Unlocks.Hats, "max" : 1}, "Speed" : {"name" : Unlocks.Speed, "max" : 5}, "Grass" : {"name" : Unlocks.Grass, "max" : 10}, "Expand" : {"name" : Unlocks.Expand, "max" : 9}, "Plant" : {"name" : Unlocks.Plant, "max" : 1}, "Carrots" : {"name" : Unlocks.Carrots, "max" : 10}, "Watering" : {"name" : Unlocks.Watering, "max" : 9}, "Trees" : {"name" : Unlocks.Trees, "max" : 10}, "Fertilizer" : {"name" : Unlocks.Fertilizer, "max" : 4}, "Sunflowers" : {"name" : Unlocks.Sunflowers, "max" : 1}, "Pumpkins" : {"name" : Unlocks.Pumpkins, "max" : 10}, "Mazes" : {"name" : Unlocks.Mazes, "max" : 6}, "Cactus" : {"name" : Unlocks.Cactus, "max" : 6}, "Polyculture" : {"name" : Unlocks.Polyculture, "max" : 5}, "Top_Hat" : {"name" : Unlocks.Top_Hat, "max" : 1}, "Megafarm" : {"name" : Unlocks.Megafarm, "max" : 5}, "Dinosaurs" : {"name" : Unlocks.Dinosaurs, "max" : 6}, "The_Farmers_Remains" : {"name" : Unlocks.The_Farmers_Remains, "max" : 1}, "Debug" : {"name" : Unlocks.Debug, "max" : 1}, "Operators" : {"name" : Unlocks.Operators, "max" : 1}, "Debug_2" : {"name" : Unlocks.Debug_2, "max" : 1}, "Timing" : {"name" : Unlocks.Timing, "max" : 1}, "Senses" : {"name" : Unlocks.Senses, "max" : 1}, "Variables" : {"name" : Unlocks.Variables, "max" : 1}, "Simulation" : {"name" : Unlocks.Simulation, "max" : 1}, "Lists" : {"name" : Unlocks.Lists, "max" : 1}, "Functions" : {"name" : Unlocks.Functions, "max" : 1}, "Leaderboard" : {"name" : Unlocks.Leaderboard, "max" : 1}, "Dictionaries" : {"name" : Unlocks.Dictionaries, "max" : 1}, "Import" : {"name" : Unlocks.Import, "max" : 1}, "Utilities" : {"name" : Unlocks.Utilities, "max" : 1}, "Costs" : {"name" : Unlocks.Costs, "max" : 1}, "Auto_Unlock" : {"name" : Unlocks.Auto_Unlock, "max" : 1}, } listBuyables = ["Loop", "Hats", "Speed", "Grass", "Expand", "Plant", "Carrots", "Watering", "Trees", "Fertilizer", "Sunflowers", "Pumpkins", "Mazes", "Cactus", "Top_Hat", "Megafarm", "Dinosaurs", "The_Farmers_Remains", "Debug", "Operators", "Debug_2", "Timing", "Senses", "Variables", "Simulation", "Lists", "Functions", "Leaderboard", "Dictionaries", "Import", "Utilities", "Costs", "Auto_Unlock"] for i in range(len(listBuyables)): unlockName = listBuyables[i] quick_print(allCosts[unlockName]["name"]) for j in range(allCosts[unlockName]["max"]): quick_print(get_cost(allCosts[unlockName]["name"], j)) quick_print(" ")
My script list that enabled me to complete most of the achievements. /! Guide not up to date since the last update. It appears that some scripts have become broken. Intro Most of the codes below were not written by me. I just modified/improved them (except for 1-2, which I didn't touch at all). I just did a lot of research throughout my epic journey on The Farmer Was Replaced (Discord, YouTube, Web, Steam, AI). I don't take credit for the codes below, even though I spent time on them. But I'm sharing them with you in the hope that they will help you as much as they helped me. I can't credit each script to each person because I picked them up from all over the place, but if you're sure one of yours is there, let me know and I'll mention you. Hay hay farm with polyculture and multiple drones clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} hay_mapping = {} def track_companion(curr_x, curr_y): global companion_mapping global hay_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity hay_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def drone_hay_task(): global world_size global companion_mapping global hay_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() harvest() if get_ground_type() == Grounds.Soil: till() if (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] if target_entity == Entities.Carrot: if get_ground_type() != Grounds.Soil: till() plant(Entities.Carrot) elif target_entity != Entities.Grass: plant(target_entity) else: if (curr_x, curr_y) in hay_mapping: companion_pos = hay_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) move(North) NUM_DRONES_TO_SPAWN = world_size - 1 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_hay_task) move(East) drone_hay_task()Or hay farm with only one drone (for leaderboard maybe) companion_mapping = {} hay_mapping = {} def track_companion(): global companion_mapping global hay_mapping target_entity, (target_x, target_y) = get_companion() while target_entity == Entities.Carrot and num_items(Items.Wood) < 1: harvest() target_entity, (target_x, target_y) = get_companion() if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity hay_mapping[(x_curr, y_curr)] = (target_x, target_y) while True: if num_items(Items.Hay) >= 1000000000000: break x_curr = get_pos_x() y_curr = get_pos_y() if get_entity_type() == Entities.Grass: if can_harvest(): harvest() if (x_curr, y_curr) in hay_mapping: # Had a companion that was already planted companion_pos = hay_mapping[(x_curr, y_curr)] hay_mapping.pop((x_curr, y_curr)) companion_mapping.pop(companion_pos) if (x_curr, y_curr) in companion_mapping: # Plant a companion target_entity = companion_mapping[(x_curr, y_curr)] if target_entity not in [Entities.Bush, Entities.Tree]: till() plant(target_entity) else: # Only when current position is growing grass track_companion() else: # Entity is not grass AKA it is / was a companion if (x_curr, y_curr) not in companion_mapping: # Companion has served its purpose # Reset land back to grassland if get_ground_type() != Grounds.Grassland: till() else: harvest() track_companion() if y_curr == get_world_size() - 1: move(East) move(North) Wood Wood farm with polyculture and multiple drones clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} tree_mapping = {} def tree_tile(curr_x, curr_y): return curr_x % 2 == curr_y % 2 def track_companion(curr_x, curr_y): global companion_mapping global tree_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity tree_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def drone_tree_task(): global world_size global companion_mapping global tree_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() if tree_tile(curr_x, curr_y): if can_harvest(): harvest() plant(Entities.Tree) else: pass if (curr_x, curr_y) in tree_mapping: companion_pos = tree_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) if get_water() < 0.40: use_item(Items.Water) elif (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] harvest() if target_entity == Entities.Grass: if get_ground_type() != Grounds.Grassland: till() elif target_entity == Entities.Carrot: if get_ground_type() != Grounds.Soil: till() plant(target_entity) else: harvest() plant(Entities.Bush) move(North) NUM_DRONES_TO_SPAWN = 31 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_tree_task) move(East) drone_tree_task()and wood farm with polyculture and only one drone world_size = get_world_size() target_num = 10000000000 companion_mapping = {} tree_mapping = {} def track_companion(curr_x, curr_y): global companion_mapping global hay_mapping target_entity, (target_x, target_y) = get_companion() if not tree_tile(target_x, target_y) and (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity tree_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def tree_tile(curr_x, curr_y): return curr_x % 2 == curr_y % 2 while True: curr_x = get_pos_x() curr_y = get_pos_y() if tree_tile(curr_x, curr_y): if (curr_x, curr_y) in tree_mapping: while not can_harvest(): use_item(Items.Fertilizer) harvest() plant(Entities.Tree) if (curr_x, curr_y) in tree_mapping: # Had a companion that was already planted companion_pos = tree_mapping[(curr_x, curr_y)] tree_mapping.pop((curr_x, curr_y)) companion_mapping.pop(companion_pos) if track_companion(curr_x, curr_y) and get_water() < 0.10: use_item(Items.Water) elif (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] curr_entity = get_entity_type() harvest() if target_entity == Entities.Grass: if get_ground_type() != Grounds.Grassland: # Grass that needs tilling. Grass never needs any planting though. till() elif target_entity == Entities.Carrot and get_ground_type() != Grounds.Soil: # Carrot that needs tilling till() plant(target_entity) else: # Not grass, but does not need any tilling. plant(target_entity) else: # not a tree tile, but is not a companion harvest() plant(Entities.Bush) if num_items(Items.Wood) >= target_num: break move(North) curr_y = get_pos_y() if curr_y == world_size - 1: move(East) Carrots Farm with polyculture and multiple drones clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} carrot_mapping = {} def track_companion(curr_x, curr_y): global companion_mapping global carrot_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity carrot_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def prepare_and_plant(entity_type): if entity_type in (Entities.Carrot, Entities.Bush, Entities.Tree) and get_ground_type() != Grounds.Soil: till() plant(entity_type) def drone_carrot_task(): global world_size global companion_mapping global carrot_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() harvest() if (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] prepare_and_plant(target_entity) if target_entity == Entities.Carrot and get_water() < 0.10: use_item(Items.Water) elif (curr_x, curr_y) in carrot_mapping: prepare_and_plant(Entities.Carrot) if get_water() < 0.10: use_item(Items.Water) companion_pos = carrot_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) else: prepare_and_plant(Entities.Carrot) if get_water() < 0.10: use_item(Items.Water) track_companion(curr_x, curr_y) move(North) NUM_DRONES_TO_SPAWN = world_size - 1 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_carrot_task) move(East) drone_carrot_task() Just a mix between woods and carrots clear() set_world_size(max_drones() - 1) change_hat(Hats.Brown_Hat) hats = [Hats.Green_Hat, Hats.Purple_Hat] world_size = get_world_size() def plant_crop(i, j): if (i + j) % 2 == 0: plant(Entities.Tree) else: plant(Entities.Carrot) if get_water() < 0.5: use_item(Items.Water) def run_drone(): global hats change_hat(hats[get_pos_x() % 2]) for j in range(get_world_size()): if get_ground_type() != Grounds.Soil: till() plant_crop(get_pos_x(), j) if can_harvest(): harvest() plant_crop(get_pos_x(), j) move(North) def run_carrots_trees(): global world_size for i in range(world_size): spawn_drone(run_drone) while num_drones() >= max_drones(): pass move(East) while True: run_carrots_trees() Sunflowers Replaces the previous code to unlock the "Sunflower master" achievement. clear() def harvest_column(): while True: if get_pos_y() != 0: move_to(get_pos_x(), 0) for _ in range(get_world_size()): if get_ground_type() != Grounds.Soil: till() if get_water() < 0.75: use_item(Items.Water) if can_harvest(): harvest() if get_entity_type() == None: plant(Entities.Sunflower) move(North) def main_loop(): world_size = get_world_size() for i in range(world_size - 1): if spawn_drone(harvest_column): move(East) harvest_column() while True: main_loop() Pumpkins There is certainly room for improvement, but it does the job. This code is not sufficient to achieve 20M in 1 minute, but there are now other players who have shared their excellent codes for this, so I invite you to visit them if you need to! clear() change_hat(Hats.Brown_Hat) world_size = get_world_size() first_pass = True def check_pumpkin(): if get_pos_x() != 0: move(East) left_id = measure() move(West) right_id = measure() move(East) return left_id == right_id def wait_for_drones(drones): for drone in drones: wait_for(drone) def plant_column(): global world_size global first_pass for j in range(world_size): if get_entity_type() != Entities.Pumpkin: if get_ground_type() != Grounds.Soil: till() plant(Entities.Pumpkin) if not first_pass: while not can_harvest(): if get_entity_type() == Entities.Dead_Pumpkin: plant(Entities.Pumpkin) use_item(Items.Fertilizer) move(North) if not first_pass: for j in range(world_size): if get_entity_type() == Entities.Dead_Pumpkin: plant(Entities.Pumpkin) move(North) def plant_pumpkins(): global world_size global first_pass drones = [] if get_pos_x() != 0: move(East) for i in range(world_size - 1): drones.append(spawn_drone(plant_column)) move(East) plant_column() wait_for_drones(drones) while True: plant_pumpkins() first_pass = False if check_pumpkin(): harvest() first_pass = True move(West)But you can try this code for the pumpkin achievement. Submitted by Arthradax in the comments section ! (Thanks!) 引用自 Arthradax:For anyone having issues: run the sunflower code to stockpile on power (around 10k should be enough), as it will double the execution speed. Also, make sure to have a lot of fertilizer; can't tell how much is enough - I used a little under 10k simulating on a fixed seed, but a little over 4k when running it for real clear() change_hat(Hats.Brown_Hat) world_size = get_world_size() needs_till=True def check_pumpkin(): if get_pos_x() != 0: move(East) left_id = measure() move(West) right_id = measure() move(East) return left_id == right_id def wait_for_drones(drones): for drone in drones: wait_for(drone) def till_column(): for _ in range(world_size): till() move(North) def plant_first_batch(): for _ in range(world_size): plant(Entities.Pumpkin) move(North) def plant_nth_batch(): for _ in range(world_size): while not can_harvest(): if get_entity_type() == Entities.Dead_Pumpkin: plant(Entities.Pumpkin) use_item(Items.Fertilizer) move(North) def check_done(): return measure()==measure(South) def drone_plant_loop(): if needs_till: till_column() plant_first_batch() while not check_done(): plant_nth_batch() def plant_pumpkins(): for _ in range(world_size-1): spawn_drone(drone_plant_loop) move(East) drone_plant_loop() while num_drones()>1: pass harvest() move(East) while True: plant_pumpkins() needs_till=False Cactus clear() hats = [Hats.Green_Hat, Hats.Purple_Hat] world_size = get_world_size() def _shortest_delta(curr, dest): size = world_size d = (dest - curr) % size if d > size / 2: d -= size return d def move_to_x_pos(x_target): x_curr = get_pos_x() moves_needed = _shortest_delta(x_curr, x_target) if moves_needed > 0: dir = East else: dir = West for i in range(abs(moves_needed)): move(dir) def move_to_y_pos(y_target): y_curr = get_pos_y() moves_needed = _shortest_delta(y_curr, y_target) if moves_needed > 0: dir = North else: dir = South for i in range(abs(moves_needed)): move(dir) def wait_for_drones(drones): for drone in drones: wait_for(drone) def drone_action_plant_cacti(): global world_size change_hat(hats[get_pos_x() % 2]) for j in range(world_size): if get_ground_type() != Grounds.Soil: till() plant(Entities.Cactus) move(North) def plant_cacti(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(drone_action_plant_cacti)) move(East) drone_action_plant_cacti() move(East) move(North) wait_for_drones(drones) def shake_row(): global world_size change_hat(hats[get_pos_y() % 2]) left = 0 right = world_size - 1 while left < right: move_to_x_pos(left) loc_last_swap = left x_curr = get_pos_x() while x_curr < right: if measure() > measure(East): swap(East) loc_last_swap = x_curr move(East) x_curr += 1 right = loc_last_swap if left >= right: break move_to_x_pos(right) loc_last_swap = right x_curr = get_pos_x() while x_curr > left: if measure(West) > measure(): swap(West) loc_last_swap = x_curr move(West) x_curr -= 1 left = loc_last_swap def shake_col(): global world_size change_hat(hats[get_pos_x() % 2]) left = 0 right = world_size - 1 while left < right: move_to_y_pos(left) loc_last_swap = left y_curr = get_pos_y() while y_curr < right: if measure() > measure(North): swap(North) loc_last_swap = y_curr move(North) y_curr += 1 right = loc_last_swap if left >= right: break move_to_y_pos(right) loc_last_swap = right y_curr = get_pos_y() while y_curr > left: if measure(South) > measure(): swap(South) loc_last_swap = y_curr move(South) y_curr -= 1 left = loc_last_swap def sort_columns(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(shake_col)) move(East) shake_col() move(East) move(North) wait_for_drones(drones) def sort_rows(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(shake_row)) move(North) shake_row() move(North) wait_for_drones(drones) while True: plant_cacti() sort_columns() sort_rows() harvest()For the "Wrong Order" achievement clear() hats = [Hats.Green_Hat, Hats.Purple_Hat] set_world_size(6) world_size = get_world_size() def _shortest_delta(curr, dest): size = world_size d = (dest - curr) % size if d > size / 2: d -= size return d def move_to_x_pos(x_target): x_curr = get_pos_x() moves_needed = _shortest_delta(x_curr, x_target) if moves_needed > 0: dir = East else: dir = West for i in range(abs(moves_needed)): move(dir) def move_to_y_pos(y_target): y_curr = get_pos_y() moves_needed = _shortest_delta(y_curr, y_target) if moves_needed > 0: dir = North else: dir = South for i in range(abs(moves_needed)): move(dir) def wait_for_drones(drones): for drone in drones: wait_for(drone) def drone_action_plant_cacti(): global world_size change_hat(hats[get_pos_x() % 2]) for j in range(world_size): if get_ground_type() != Grounds.Soil: till() plant(Entities.Cactus) move(North) def plant_cacti(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(drone_action_plant_cacti)) move(East) drone_action_plant_cacti() move(East) move(North) wait_for_drones(drones) def shake_row(): global world_size change_hat(hats[get_pos_y() % 2]) left = 0 right = world_size - 1 while left < right: move_to_x_pos(left) loc_last_swap = left x_curr = get_pos_x() while x_curr < right: # Condition inversée pour le passage Est/droite : # Si l'élément courant est PLUS PETIT que le suivant, on échange. if measure() < measure(East): swap(East) loc_last_swap = x_curr move(East) x_curr += 1 right = loc_last_swap if left >= right: break move_to_x_pos(right) loc_last_swap = right x_curr = get_pos_x() while x_curr > left: # Condition inversée pour le passage Ouest/gauche : # Si l'élément précédent est PLUS GRAND que le courant, on échange. if measure(West) > measure(): swap(West) loc_last_swap = x_curr move(West) x_curr -= 1 left = loc_last_swap def shake_col(): global world_size change_hat(hats[get_pos_x() % 2]) left = 0 right = world_size - 1 while left < right: move_to_y_pos(left) loc_last_swap = left y_curr = get_pos_y() while y_curr < right: # Condition inversée pour le passage Nord/haut : # Si l'élément courant est PLUS PETIT que le suivant, on échange. if measure() < measure(North): swap(North) loc_last_swap = y_curr move(North) y_curr += 1 right = loc_last_swap if left >= right: break move_to_y_pos(right) loc_last_swap = right y_curr = get_pos_y() while y_curr > left: # Condition inversée pour le passage Sud/bas : # Si l'élément précédent est PLUS GRAND que le courant, on échange. if measure(South) > measure(): swap(South) loc_last_swap = y_curr move(South) y_curr -= 1 left = loc_last_swap def sort_columns(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(shake_col)) move(East) shake_col() move(East) move(North) wait_for_drones(drones) def sort_rows(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for i in range(world_size - 1): drones.append(spawn_drone(shake_row)) move(North) shake_row() move(North) wait_for_drones(drones) while True: plant_cacti() sort_columns() sort_rows() harvest() Dino world_size = get_world_size() world_size_minus_one = world_size - 1 edge_positions = [0, world_size_minus_one] offlimit_columns_stage1 = { } offlimit_columns_stage2 = { } clear() change_hat(Hats.Dinosaur_Hat) apple_pos = measure() squares_occupied = 1 game_complete = False aggressive_stage = True def measure_apple(): global apple_pos global squares_occupied global apple_pos_queue apple_pos = measure() squares_occupied += 1 def move_and_check_apple(direction): global apple_pos if not move(direction): return False if (get_pos_x(), get_pos_y()) == apple_pos: measure_apple() return True def move_to_col(target_x_pos, do_measure=True): global world_size global apple_pos curr_x = get_pos_x() direction = West if curr_x < target_x_pos: direction = East for x in range(abs(target_x_pos - curr_x)): this_check = move if do_measure: this_check = move_and_check_apple if not this_check(direction): return False return True def move_to_row(target_y_pos, do_measure=True): global world_size global apple_pos curr_y = get_pos_y() direction = South if curr_y < target_y_pos: direction = North for y in range(abs(target_y_pos - curr_y)): this_check = move if do_measure: this_check = move_and_check_apple if not this_check(direction): return False return True def transition_to_stage_2(): global offlimit_columns_stage1 global world_size global world_size_minus_one move_to_col(world_size_minus_one) move_to_row(0) offlimit_columns_stage1 = { } return False def transition_to_stage_1(): global offlimit_columns_stage2 global world_size global world_size_minus_one move_to_col(0) move_to_row(world_size_minus_one) offlimit_columns_stage2 = { } return False def stage_1_apple_collect(): global apple_pos global world_size global offlimit_columns_stage1 global offlimit_columns_stage2 global world_size_minus_one apple_pos_x, apple_pos_y = apple_pos if apple_pos_y == 0 or apple_pos_x in edge_positions or (apple_pos_x in offlimit_columns_stage1 and apple_pos_y <= offlimit_columns_stage1[apple_pos_x]): return transition_to_stage_2() else: apple_x_odd = apple_pos_x % 2 target_x_pos = apple_pos_x if not apple_x_odd: target_x_pos = apple_pos_x - 1 if target_x_pos <= get_pos_x(): return transition_to_stage_2() else: move_to_col(target_x_pos) move_to_row(apple_pos_y) offlimit_columns_stage2[target_x_pos] = apple_pos_y offlimit_columns_stage2[target_x_pos + 1] = apple_pos_y move_and_check_apple(East) move_to_row(world_size_minus_one) return True def stage_2_apple_collect(): global apple_pos global world_size global offlimit_columns_stage1 global offlimit_columns_stage2 global world_size_minus_one apple_pos_x, apple_pos_y = apple_pos if apple_pos_y == world_size_minus_one or apple_pos_x in edge_positions or (apple_pos_x in offlimit_columns_stage2 and apple_pos_y >= offlimit_columns_stage2[apple_pos_x]): return transition_to_stage_1() else: apple_x_odd = apple_pos_x % 2 target_x_pos = apple_pos_x if apple_x_odd: target_x_pos = apple_pos_x + 1 if target_x_pos >= get_pos_x(): return transition_to_stage_1() else: move_to_col(target_x_pos) move_to_row(apple_pos_y) offlimit_columns_stage1[target_x_pos] = apple_pos_y offlimit_columns_stage1[target_x_pos - 1] = apple_pos_y move_and_check_apple(West) move_to_row(0) return True def move_to_right_col_wavy(): global world_size global world_size_minus_one global offlimit_columns_stage1 # Assume curr x is zero for x in range(world_size): if x % 2: target_y = 1 if x in offlimit_columns_stage1: target_y = offlimit_columns_stage1[x] + 1 while get_pos_y() != target_y: move(South) move(East) else: # x is even, go up to top row, then move right while get_pos_y() != world_size_minus_one: move(North) move(East) def find_top_left(): global world_size_minus_one while get_pos_x() > 0: move(West) while get_pos_y() < world_size_minus_one: move(North) def transition_to_route(): find_top_left() move_to_right_col_wavy() while get_pos_y() != 0: move(South) while get_pos_x() != 0: move(West) # STAGE 1 move_to_row(world_size_minus_one) while aggressive_stage: while stage_1_apple_collect() and get_pos_x() < world_size_minus_one: pass while stage_2_apple_collect() and get_pos_x() > 0: pass if squares_occupied > (world_size_minus_one) * 4 - 4: break transition_to_route() while True: for i in range(world_size / 2): game_complete = not move_to_row(world_size_minus_one, False) game_complete = game_complete or not move(East) game_complete = game_complete or not move_to_row(1, False) if i != world_size / 2 - 1: game_complete = game_complete or not move(East) if game_complete: break game_complete = game_complete or not move_to_row(0, False) game_complete = game_complete or not move_to_col(0,) if game_complete: break change_hat(Hats.Straw_Hat) Maze ALL_DIRECTIONS = [North, South, East, West] def opposite_direction(direction): if direction == North: return South elif direction == East: return West elif direction == South: return North elif direction == West: return East def explore_option_iterative(start_direction): global ALL_DIRECTIONS if not move(start_direction): return False path_stack = [(start_direction, 0)] while path_stack and num_items(Items.Gold) < 9863168000000: if get_entity_type() == Entities.Treasure: harvest() start_maze() return True last_move_direction, next_dir_index = path_stack[-1] while next_dir_index < len(ALL_DIRECTIONS): explore_direction = ALL_DIRECTIONS[next_dir_index] path_stack[-1] = (last_move_direction, next_dir_index + 1) if opposite_direction(explore_direction) != last_move_direction: if move(explore_direction): path_stack.append((explore_direction, 0)) break next_dir_index += 1 if next_dir_index == len(ALL_DIRECTIONS): path_stack.pop() move(opposite_direction(last_move_direction)) move(opposite_direction(start_direction)) return False def start_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def search(): global drone_id global ALL_DIRECTIONS for _ in range(drone_id): do_a_flip() if drone_id % 2: ALL_DIRECTIONS = ALL_DIRECTIONS[::-1] if drone_id % 3: ALL_DIRECTIONS[0], ALL_DIRECTIONS[1] = (ALL_DIRECTIONS[1], ALL_DIRECTIONS[0]) if drone_id % 5: ALL_DIRECTIONS[1], ALL_DIRECTIONS[3] = (ALL_DIRECTIONS[3], ALL_DIRECTIONS[1]) while True: for direction in ALL_DIRECTIONS: if explore_option_iterative(direction): break drone_id = 0 start_maze() for i in range(max_drones()): drone_id = i spawn_drone(search) drone_id = 0 search() For the "Recycling" and "Big Gold Farmer" achievements def generate_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def maze(): while True: if num_drones() == 25: if get_entity_type() == Entities.Treasure: harvest() generate_maze() clear() set_world_size(5) list = [] while num_drones() < 26: pos_x = get_pos_x() pos_y = get_pos_y() current = (pos_x, pos_y) if current not in list: list.append(current) spawn_drone(maze) move(North) else: move(East) For some, this code did not work for the ‘Recycling’ achievement. Here are two codes to do this, which were shared in the comments section : By Arthradax set_world_size(5) times_reused=0 substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) def generate_maze(): plant(Entities.Bush) use_item(Items.Weird_Substance, substance) def maze(): global times_reused while True: if num_drones() == 25: if get_entity_type() == Entities.Treasure: if times_reused>=300: times_reused=0 harvest() generate_maze() else: use_item(Items.Weird_Substance, substance) times_reused+=1 clear() list = [] while num_drones() < 26: pos_x = get_pos_x() pos_y = get_pos_y() current = (pos_x, pos_y) if current not in list: list.append(current) spawn_drone(maze) move(North) else: move(East) generate_maze() And by ᴛᴀᴛᴀʀᴏᴄʜᴋᴀ def generate_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def maze(): i = 0 end = 300 while True: if num_drones() == 25: if get_entity_type() == Entities.Treasure and (i == end): harvest() i = 0 elif get_entity_type() == Entities.Treasure: substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) i += 1 generate_maze() clear() set_world_size(5) list = [] while num_drones() < 26: pos_x = get_pos_x() pos_y = get_pos_y() current = (pos_x, pos_y) if current not in list: list.append(current) spawn_drone(maze) move(North) else: move(East) Thanks to them!
这里我们来讨论一种用于快速便捷通过最大尺寸迷宫的算法。 关于无人机通过迷宫功能的程序代码 创建maze_finisher模块 1. 新建一个代码窗口。 2. 为其命名,例如maze_finisher。 3. 在其中粘贴以下代码: maze = [] for i in range(get_world_size()): maze.append([]) for j in range(get_world_size()): maze[ i ].无法识别或无法翻译,已删除。无法翻译的跳过无法识别或无法翻译,已删除。奇怪物质,物质) 路径 = 广度优先搜索() 对于路径中的每一步: 移动(步骤) 采集() 函数调用 现在为主要代码创建一个新窗口并将其粘贴到那里: 从迷宫完成器导入完成迷宫 清除() 种植(实体.灌木) 物质 = 获取世界大小() * 2 ** (已解锁数量(解锁项.迷宫) - 1) 使用物品(物品.奇怪物质,物质) 完成迷宫(10) 运行 1. 保存两个窗口。 2. 运行主脚本。 3. 无人机自身: * 探索迷宫 * 计算最短路径 * 按要求次数完成迷宫 * 收集奖励 无人机迷宫通过功能的程序代码 创建迷宫完成器模块 1. 创建一个新的代码窗口。 2.请将其命名为例如maze_finisher 3. 在其中插入以下代码: maze = [] for i in range(get_world_size()): maze.append([]) for j in range(get_world_size()): maze[ i ].append({ 'visited': False, 'walls': {North: False, East: False, South: False, West: False} }) DIRECTIONS = [North, East, South, West] DX = {North: 0, East: 1, South: 0, West: -1} DY = {North: 1, East: 0, South: -1, West: -1} substance = get_world_size() * 2 ** (num_unlocked(Unlocks.无法翻译的跳过无法识别或无法翻译,已删除。调用函数 现在创建一个新窗口用于主代码,并在其中粘贴以下内容: from maze_finisher import complete_maze clear() plant(Entities.Bush) substance = get_world_size() * 2 ** (num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) complete_maze(10) 运行 1. 保存两个窗口。 2. 运行主脚本。 3. 无人机将自动: * 探索迷宫 * 计算最短路径 * 按所需次数通过迷宫
自动化 farming 的终极挑战是尽可能快速地自动完成游戏流程。以下是游戏自动化相关的解锁内容概述: 解锁树 本指南包含游戏 1.0 版本前的解锁成本信息。
速度 物品.干草: 20 物品.木材: 10 物品.木材: 50, 物品.胡萝卜: 100 物品.木材: 100, 物品.胡萝卜: 200 物品.胡萝卜: 350 物品.胡萝卜: 500 物品.胡萝卜: 800 物品.胡萝卜: 1100 物品.胡萝卜: 1400 物品.胡萝卜: 1700 物品.胡萝卜: 2100 物品.胡萝卜: 2500 物品.能量: 2000 物品.能量: 2600 物品.能量: 3380 物品.能量: 4390 物品.能量: 5710 物品.能量: 7430 物品.能量: 9650 物品.能量: 12500 草地 物品.干草: 100 物品.干草: 300 物品.干草: 450 物品.干草: 675 物品.干草: 1010 物品.干草: 1520 物品.干草: 2280 物品.干草: 3420 物品.干草: 5130 物品.干草: 7690 物品.干草: 11500 物品.干草: 17300 扩展 物品.干草: 30 物品.木材: 20 物品.木材: 50, 物品.胡萝卜:50 物品.木材:100,物品.南瓜:200 物品.南瓜:500 物品.南瓜:1750 物品.南瓜:6120 物品.南瓜:21400 物品.南瓜:75000 胡萝卜 物品.木材:100 物品.木材:300 物品.木材:480 物品.木材:768 物品.木材:1230 物品.木材:1970 物品.木材:3150 物品.木材:5030 物品.木材:8050 物品.木材:12900 物品.木材:20600 物品.木材:33000 树木 物品.木材:50,物品.胡萝卜:200 物品.干草:300 物品.干草:480 物品.干草:768 物品.干草:1230 物品.干草:1970 物品.干草:3150 物品.干草:5030 物品.干草:8050 物品.干草:12900 物品.干草:20600 物品.干草:33000 向日葵 物品.胡萝卜:500 物品.金币:1000 物品.金币:2000 物品.金币:4000 物品黄金:8000 物品.黄金:16000 南瓜 物品.木材:500,物品.胡萝卜:1000 物品.胡萝卜:1200 物品.胡萝卜:1920 物品.胡萝卜:3070 物品.胡萝卜:4920 物品.胡萝卜:7860 物品.胡萝卜:12600 物品.胡萝卜:20100 物品.胡萝卜:32200 物品.胡萝卜:51500 仙人掌 物品.黄金:5000 物品.黄金:10000 物品.黄金:20000 物品.黄金:40000 迷宫 物品.胡萝卜:2000,物品.南瓜:3000 物品.南瓜:4000 物品.南瓜:8000 物品.南瓜:16000 物品.南瓜:32000 单次解锁(植物、肥料、混养、排行榜) 植物:物品.干草:50 肥料:物品.南瓜:1000 混养:物品.干草:3000,物品.木材:3000,物品.胡萝卜:3000 排行榜:物品.骨头:2000
*DUE TO STILL GOING THROUGH THE GAME, THIS IS A WIP. * I have never created, learned, played, or used "code" before I purchased this game. That being said, if you want to see my own approaches (codes) that I created (without researching the "solutions' elsewhere) then feel free to compare, critic, grade, insult, or otherwise comment on my codes! I am pretty proud of my solutions, and I feel that they are "bug-free", but if you happen to run into any issue(s) using my codes, PLEASE let me know! I'm certain that my codes (custom functions, variables, etc.) will not be friendly to all other player's custom content. BEGINNER TIPS *** I will dive "deeper" into each topic in further chapters. Right now, I'm just giving basic information/tips.*** 1. VARIABLES (ONCE UNLOCKED) ARE YOUR FRIENDS! If you are familiar with variables in algebra, this game is using almost the exact same thing (I say "almost" because this game allows variables to equal words, function names, etc. which eventually return with their own values, including "True", "False", and "None" values. However, if you don't like algebra, that's OK, because another way to look at this portion of the game-play is like you're creating your own dictionary (words, definitions, etc.) Throughout this game (via Variables, etc.) you're basically just defining things with a custom acronym, word, or phrase (the latter of which would need to be separated using "_" instead of a "space" character; for example: "this_is_an_example".) 2. FUNCTIONS (ONCE UNLOCKED) ARE VERY, VERY, VERY USEFUL IN SAVING YOU TIME!! If you want to go far in this game, and do so quicker than the alternative, then "functions" should be a term you are not only familiar with, but they should be a function of the game you use often (pun intended!) Functions basically contain as many actions, commands, local variables, etc. that you want to place "inside them". Once that is done, you can perform ALL of those actions, etc. simply by calling the function's name (for example, " harvest() * is actually a built-in function for the game, and it does exactly what it seems like it would do; it harvests any ripe resource (that the drone is currently flying over) that is capable of being harvested. So, if your drone is over a grassy "square", calling harvest() would reap the hay from the grassy block and send it to your stored resources. This can quickly become not only overwhelming (until you experiment , learn, etc.) but also VERY rewarding. One way I use functions to make my life easier is by creating 'global' shortcuts that I can use throughout the code file (as well as with other files, but that's another chapter...) For instance, I have a function called "reap_and_water()", or "raw()" for short, if you don't like long-winded function titles. This code is actually very easy to make (meaning that if you don't like the example given below, make your own!) but it saves you a lot of time when you are learning new crops and needing to adapt to their own needs, etc. The function "reap_and_water()" could look something like this: def reap_and_water(): if can_harvest(): harvest() use_item(Items.Water) however, once you get far enough in the game, you may need/want to be a little more complicated with this function. Below is another example, but somewhat more complex: def reap_and_water(): if can_harvest(): harvest() if get_water() < .80: use_item(Items.Water) else: if get_entity_type() == None: pass Alright, so some people may disagree with my choice to water the square before planting a new crop, but there's actually a good reason behind making this decision. REASON: because I said so... OTHER, LESS IMPORTANT REASON: Using water once does not fully saturate the ground in that square. It takes multiple water 'deliveries' to fully saturate the ground. Therefore, the more you water, the more fertile the ground will be. There is actually no downside to this (other than using water, if you're a water hoarder...) because the following things will NOT reset or negatively impact the water level: tilling does not change or erase the water level. planting AFTER watering does not change or erase the water level. That's why I water after reaping (as well as before planting, but that's just me so I can make sure the water levels are good in every square.) BUT ANYWAY, BACK TO THE TOPIC AT HAND! The above-listed functions took lots of characters, time, typing, thought process, etc. HOWEVER, after making the function, you can simply type "reap_and_water()" and the entire function (actions, etc.) will trigger after the function is called. That saves me from having to input the above-listed code EVERY time I want to harvest and reap a world square. 3. DID I MENTION THAT VARIABLES ARE YOUR FRIENDS??? Seriously though, variables are pretty complex. For example, you can assign (define) a variable within a function, and that variable will compute differently than if you use the exact same variable outside of the function (unless the 'global' variable is called/used in the function, then scratch everything I just said (lol, like I said, complex.) An example is listed below: x = 0 def get_x(): x = get_pos_x() the first-listed "x" (otherwise known as a "variable", since it's meaning, result, etc. can change based on the provided input) computes to the number zero (because I told it to.) However, the SECOND "x" variable is assigned/defined inside the function "get_x()". In that function, I simply define "x" as being the same thing as "get_pos_x()". When the function begins/triggers, the system will actually check what "x" position the drone is in. After it gets that result, the second "x" variable is made to be EQUAL to that value. For example, if your drone is in position "2" on the "x" coordinates, then "x" would equal 2. Thus the function's variable translates to "x = 2" instead of "x = get_pos_x()". I won't go much further into this just yet, but it can later get VERY complex when you create functions that change the variable multiple times within the same function. A simple "x = x +1" is a good example of an always-changing variable. This concludes my introduction, or rather, "beginner tips". I hope you all are enjoying this game as much as I am! I have been blown away with how easily I am able to learn the game's pseudo Python coding language, and think of creative ways to become more efficient as a farming drone! Variables May Vary Very Much in their Many Varying Varieties Sorry for the redundantly-repetitive title... (dang it, I did it again!) Variables are simply the same thing as Algebraic variables (something that equals something else, and is capable of changing itself as well.) These are extremely useful in not only saving time while writing code, but also in performing mathematical equations (including the ones that can change in a second depending on how each variable's value changes.) A simple example of this is listed below: x = 0 while True: move(East) x = 0 + 1 in this code, (especially if used in a "while" loop) the value of "x" continues to change in a predictable and reliable manner. Basically, "x = 0" outside of the loop (or rather, before the loop begins.) Once the loop begins, however, each time the drone moves East, the "x" increases in value (increasing by 1.) A different (though somewhat similar) "x" variable is listed below: x = get_pos_x() while True: while x != 0: move(West) x = x - 1 this "x" variable is more adaptable in the sense that it can detect "where" it is to begin with. For instance, if the drone was on/over position "4" on the x-coordinates, then x = 4. Yet almost immediately, the value of "x" begins to decrease with each loop, due to the variable equation "x = x - 1". This code would work in getting your drone to be on the "x0" coordinate/square. The below-listed codes are actually some of my favorites because of their usefulness in a lot of my different codes: global x global y x = get_pos_x() y = get_pos_y() # ========== GET_X ========== def get_x(): global x x = get_pos_x() return x # ========== GET_Y ========== def get_y(): global y y = get_pos_y() return y # ======= GET_XY ======== def get_xy(): global x global y return x, y # ===== STEP(DIR) ===== def step(dir): global x global y if dir == East: move(East) x = (x + 1) % ws elif dir == West: move(West) x = (x - 1) % ws elif dir == North: move(North) y = (y + 1) % ws elif dir == South: move(South) y = (y - 1) % ws # ========== GO_TO ========== def go_to(tx, ty): global x global y dx_right = (tx - x) % ws dx_left = (x - tx) % ws if dx_right <= dx_left: int = dx_right for _ in range(int): step(East) else: int = dx_left for _ in range(int): step(West) dy_up = (ty - y) % ws dy_down = (y - ty) % ws if dy_up <= dy_down: int = dy_up for _ in range(int): step(North) else: int = dy_down for _ in range(int): step(South) return x, y basically, this code (though likely more complicated than a senior coder, dev, etc.) allows me to, at any point call (for example) "go_to(0,0)" and the drone will move to those coordinates (which are 0 , 0; x coordinate zero and y coordinate zero.) I have found that, though it is often dependent on inputting the coordinates by yourself, it also allows the following code to work, perfectly "scaling" to any world size automatically: for yy in range(ws): for xx in range(ws): go_to(xx, yy) that 'simple' code now automatically travels each world square one time, no matter what size world you have. Another way you can use (and honestly, should be using) variables is by shortening some of the functions that result in simple number values or "True", "False", or "None" values. For example, I like my functions to have longer names so that, should I need to troubleshoot functions that I made a while ago, I know what the intended purpose was. I then just use a simple variable to "shortcut" that function's result. Below is an shortened example of what I mean, (aka, not listing all of the items): tct = testing_crop_type def testing_crop_type(): carrot = Entities.Carrot if get_entity_type() == carrot: return(carrot) tct() this means that, when multiple items and variables are listed, it would correctly return with whatever entity it detects underneath the drone. To clarify, "carrot" is the variable, and that variable is made to equal the actual carrot entity. Therefore, instead of having to type "Entities.Carrot" every time I was to refer to the game's carrot item, all I have to type "carrot" and the game translates that to the item itself. Additionally, as you can see i made a variable "tct" which equaled the phrase/words "testing_crop_type", and as long as you leave the "()" out of both portions of the variable, then you can call the function using the shorter variable by immediately following it with "()". This is just a brief overview of variables. I am so excited to continue experimenting and learning new methods, etc. for the variables capabilities in this game. Functions and Importing Files This chapter is not able to be efficiently discussed without also talking about one of the "upgrades" which assist functions' functionality in the game (there I go with the puns again...) It may be helpful to see functions as the definitions of an action. This is initially easy to comprehend since each function is assigned/created by "def" which means "define". for instance, the code below is an example of a function: def example(): while get_pos_x() != get_world_size(): x = get_pos_x() move(East) x = x + 1 the function name/title is "example()", and the portion of the name which tells the system to trigger a function (as well as knowing the name of the function itself) is the "()". The function, "example()" is defined as performing the following actions (in the example above): 1. get the current "x" position in the world, and assigned it's value to the variable "x". 2. move East one time. 3. change the local "x" variable in accordance with moving east one time. All of these things happen ONLY while the drone is not on/over the last x position for the current world size.(meaning that it will not move east if it is at the easternmost side of the world.) Another thing to know is that you can actually "call" (activate) another function within a different function, however, this is contingent on the current file (the minimize-able/close-able window in which you are typing the current code, etc.) having access to any and all functions and variables being activated/used. One example is listed below, after which we will get into "files" and how the "import" upgrade is SUPER helpful in saving space, troubleshooting code's incompatibilities with one another, etc. def reap(): if can_harvest(): harvest() def water(): if get_water() < .80: use_item(Items.Water) def reap_and_water(): reap() water() The first two functions are combined and utilized in the third/last function. This is possible as long as the "master" function has access to the lesser functions. FILES, AND THEIR USES (LIKE, IMPORTING): Alright, so... (SPOILER ALERT, SPOILER WARNING, DO NOT PASS GO, DO NOT COLLECT $200!) Files (and importing) are important to purchase/upgrade, and here's why: Files are the windows you type code in. That's obvious. But importing is less-so... Importing allows the ability to jump from one file to another (similar to jumping from one function to another, as mentioned above.) so if I have one file (window) that has a "reap()" function, I would NOT be able to use that in a totally different file unless I copy-and-paste it into the new file, OR "import" it into the new file. Below are some examples of importing files (via their file names) into another file: from example import * from example import reap() example.reap() import example the first-listed line allows the import of all variables (global, etc.) to be imported (copied and used, essentially) in the new file. the second-listed line allows a specific function to be imported into the new file. For this example, the new file can now call on the function "reap()" by first listing the file name, followed by a period character/symbol, then listing the function name. i.e. "example.reap()" the last-listed line allows the entire file to be imported (but this may be a bad choice, if you are using similar function names, variables, etc. for different files. For example, if I import a global "x" variable from the example file, and also have a global "x" variable in my current file, then the global "x" will conflict with itself (or rather, assume the newer value assigned to it, thus potentially conflicting with one of the files, if not both.) The same can be said for functions such as "reap()" if, for example, you have a "pumpkin" file that has it's own reap() function (for obvious reasons, if you know about pumpkins yet.) there can be a good reason to change a function's actions for a specific file, while not wanting to change the name itself. Just keep this in mind if you find yourself doing this. Me, personally? I simply name my similar-but-different functions to be, well, similar but different... for example: my pumpkin "reap" could be called "reap_p()" for reaping pumpkins, or maybe the "x" variable could be assigned/created as "pum_x" instead of simply "x". These are just examples, of course. CODE OPTIONS In this chapter, I will simply be providing some of the codes I made during my play through. Keep in mind that I made these: 1. without any prior coding experience, and 2. without researching any "veteran" code solutions made by persons more capable than yours truly. Below is my "sunflower" file, which I have found effective in only harvesting the highest measurement in the field during that sweep (which is the intended challenge/change provided by the sunflower crop.) HERE YOU GO! import globals from globals import * from mov import * import mov from paw import * import paw x = mov.get_x() bx = x y = mov.get_y() by = y m = measure() bm = m def measuring(): global x global bx global y global by global m global bm # Current position & measurement x = mov.get_x() y = mov.get_y() cur_m = measure() # If we're at (0,0) and it's empty, plant once, then re-measure if (x, y) == (0, 0): if cur_m == None: paw.paw_sunflower() cur_m = measure() # Normalize None -> 0 for safe numeric comparison if cur_m == None: cur_val = 0 else: cur_val = cur_m if bm == None: best_val = 0 else: best_val = bm # Update "best" if improved if cur_val >= best_val: bm = cur_val bx = x by = y return (bx, by) def farm_sunflower(): global x global bx global y global by global m global bm # Scan a 5x5 area (0..4, 0..4) for yy in range(ws): for xx in range(ws): mov.go_to(xx, yy) soil.soilmeasuring() if get_entity_type() == None: paw.paw_sunflower() # Go reap the best spot found mov.go_to(bx, by) reap_best() def reap_best(): global x global y global bx global by global m global bm mov.go_to(bx, by) if measure() == bm: harvest() m = 0 bm = 0 x = 0 bx = 0 y = 0 by = 0 now, as you can see, this file is dependent on several other files in order to work effectively. Obviously, I've already provided the "mov" file to you in an earlier chapter. But, in order to encourage you to simply use this code as inspiration and not a cheat, I am intentionally not going to provide the necessary files (that I created) which this file is dependent on. What I can say is that this file (as you can tell based on reading the functions, etc.) and its dependent files, variables, etc. are capable of planting a field of sunflowers while measuring/scanning each one. After it has measured the whole field, it then knows which square had the best sunflower measurement. It will go to that square and harvest that sunflower. It will then continue to do this (planting on empty squares, scanning, harvesting the best sunflower) forever (until I stop it, of course.) NEXT The next code I will provide (without fully "providing") is for the pumpkin crop. This crop is unique in that you will get a LOT more pumpkins if you let it grow to it's max size (the current world size) before you reap it. While studying this crop, I noticed that it generates a random code for every pumpkin, and the numbers are not predictable. Therefore the solution I came up with was essentially this: scan each pumpkin. Make sure pumpkins are being planted. If the whole field has the same "measurement" that must mean that it's a single BIG pumpkin. Harvest... Here's the code! from globals import * import globals from mov import * import mov from paw import * import paw from reap import * import reap global x global y x = get_pos_x() y = get_pos_y() mov.go_to(0,0) def farm_pumpkin(): global x global y x = get_pos_x() y = get_pos_y() # FIRST 'SEED' TO COMPARE TO OTHERS: reap.reap_and_plant_pumpkin() measure() seed1 = measure() for yy in range(ws): for xx in range(ws): measure() seed2 = measure() if seed2 == seed1: if get_entity_type() == None: reap.reap_and_plant_pumpkin() else: pass if seed2 != seed1: reap.reap_and_plant_pumpkin() mov.go_to(xx, yy) if get_entity_type() == None: paw.paw_pumpkin() if seed1 == seed2: harvest() while True: farm_pumpkin() Both of these crops' codes work perfectly for me. So, if you run into any issues, that is simply because you likely don't have the same function(s), variable(s), etc. that I do (which I imported from other files.) I SUPER appreciate you guys for reading so far! I definitely intend on updating this with each new crop/solution that I come across. Let me know if you have any advise, comments, complaints (except for the lack of my other files, that is intentional) and GOOD LUCK!
Title is self explaining I want to say something First of all im not a native speaker so im sorry if there are any spelling or grammar mistakes. Second of all NOT all of the codes below are self written. A lot of them are copied from other websites and sometimes modified to fit the conditions. I do not know anymore where they came from but i wanted to share working code for every or nearly every Achievement in the game. Important: These codes are most likely not working in the early stages of the game. So far i can tell that you need to unlock at least 32 Drones; Polyculture; 32x32 Farmsize; Basic math stuff; funktions; Import maybe im missing something Hello World; Infinityloop; Error; Acrobat; Stylish For every one that managed to skip the inevitable Achievemnts: while True: pet_the_piggy() do_a_flip() change_hat(Hats.Brown_Hat) Make_Error() Hay clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} hay_mapping = {} def track_companion(curr_x, curr_y): global companion_mapping global hay_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity hay_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def drone_hay_task(): global world_size global companion_mapping global hay_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() harvest() if get_ground_type() == Grounds.Soil: till() if (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] if target_entity == Entities.Carrot: if get_ground_type() != Grounds.Soil: till() plant(Entities.Carrot) elif target_entity != Entities.Grass: plant(target_entity) else: if (curr_x, curr_y) in hay_mapping: companion_pos = hay_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) move(North) NUM_DRONES_TO_SPAWN = world_size - 1 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_hay_task) move(East) drone_hay_task() Carrots clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} carrot_mapping = {} def track_companion(curr_x, curr_y): global companion_mapping global carrot_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity carrot_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def prepare_and_plant(entity_type): if entity_type in (Entities.Carrot, Entities.Bush, Entities.Tree) and get_ground_type() != Grounds.Soil: till() plant(entity_type) def drone_carrot_task(): global world_size global companion_mapping global carrot_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() harvest() if (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] prepare_and_plant(target_entity) if target_entity == Entities.Carrot and get_water() < 0.10: use_item(Items.Water) elif (curr_x, curr_y) in carrot_mapping: prepare_and_plant(Entities.Carrot) if get_water() < 0.10: use_item(Items.Water) companion_pos = carrot_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) else: prepare_and_plant(Entities.Carrot) if get_water() < 0.10: use_item(Items.Water) track_companion(curr_x, curr_y) move(North) NUM_DRONES_TO_SPAWN = world_size - 1 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_carrot_task) move(East) drone_carrot_task() Wood clear() world_size = get_world_size() change_hat(Hats.Brown_Hat) companion_mapping = {} tree_mapping = {} def tree_tile(curr_x, curr_y): return curr_x % 2 == curr_y % 2 def track_companion(curr_x, curr_y): global companion_mapping global tree_mapping result = get_companion() if result == None: return False target_entity, (target_x, target_y) = result if (target_x, target_y) not in companion_mapping: companion_mapping[(target_x, target_y)] = target_entity tree_mapping[(curr_x, curr_y)] = (target_x, target_y) return True return False def drone_tree_task(): global world_size global companion_mapping global tree_mapping while True: for j in range(world_size): curr_x = get_pos_x() curr_y = get_pos_y() if tree_tile(curr_x, curr_y): if can_harvest(): harvest() plant(Entities.Tree) if (curr_x, curr_y) in tree_mapping: companion_pos = tree_mapping.pop((curr_x, curr_y)) if companion_pos in companion_mapping: companion_mapping.pop(companion_pos) track_companion(curr_x, curr_y) if get_water() < 0.40: use_item(Items.Water) elif (curr_x, curr_y) in companion_mapping: target_entity = companion_mapping[(curr_x, curr_y)] harvest() if target_entity == Entities.Grass: if get_ground_type() != Grounds.Grassland: till() elif target_entity == Entities.Carrot: if get_ground_type() != Grounds.Soil: till() plant(target_entity) else: harvest() plant(Entities.Bush) move(North) NUM_DRONES_TO_SPAWN = 31 for i in range(NUM_DRONES_TO_SPAWN): while num_drones() >= max_drones(): pass spawn_drone(drone_tree_task) move(East) drone_tree_task() Sunflower clear() change_hat(Hats.Purple_Hat) def Sunflower(): def harvestColum(): for _ in range(get_world_size()): if get_ground_type()!=Grounds.Soil: till() plant(Entities.Sunflower) if can_harvest(): harvest() plant(Entities.Sunflower) move(North) else: move(North) while num_items(Items.Power)<40000000: if spawn_drone(harvestColum): move(East) Sunflower() Pumpkin clear() change_hat(Hats.Brown_Hat) set_world_size(32) world_size = get_world_size() first_pass = True def check_pumpkin(): if get_pos_x() != 0: move(East) left_id = measure() move(West) right_id = measure() move(East) return left_id == right_id def wait_for_drones(drones): for drone in drones: wait_for(drone) def plant_column(): global world_size for j in range(world_size): if get_entity_type() != Entities.Pumpkin: if get_ground_type() != Grounds.Soil: till() plant(Entities.Pumpkin) if not first_pass: while not can_harvest(): if get_entity_type() == Entities.Dead_Pumpkin: plant(Entities.Pumpkin) use_item(Items.Fertilizer) move(North) def plant_pumpkins(): global world_size #global first_pass drones = [] if get_pos_x() != 0: move(East) for i in range(world_size - 1): drones.append(spawn_drone(plant_column)) move(East) plant_column() wait_for_drones(drones) while True: plant_pumpkins() first_pass = False if check_pumpkin(): harvest() first_pass = True move(West) Cactus while True: WORLD_SIZE = get_world_size() MAX_DRONES = max_drones() def main(): plant_and_sort_all_rows() sort_all_columns() def plant_and_sort_all_rows(): global WORLD_SIZE for row in range(WORLD_SIZE): if num_drones() >= WORLD_SIZE: move_to(0, row) pas_current_row() break move_to(0, row) drone = spawn_drone(pas_current_row) move_to(0,1) while num_drones() > 1: pass def pas_current_row(): global WORLD_SIZE row = get_pos_y() for col in range(WORLD_SIZE): move_to(col, row) till() plant(Entities.Cactus) insertion_sort_row_step() def insertion_sort_row_step(): while get_pos_x() > 0: if measure() < measure(West): swap(West) move(West) else: break def sort_all_columns(): global WORLD_SIZE global MAX_DRONES for col in range(WORLD_SIZE): move_to(col, 1) while num_drones() >= MAX_DRONES: sort_current_column() break spawn_drone(sort_current_column) while num_drones() > 1: pass def sort_current_column(): global WORLD_SIZE while get_pos_y() < (WORLD_SIZE - 1): insertion_sort_column_step() insertion_sort_column_step() def insertion_sort_column_step(): if get_pos_y() == 0: move(North) return if measure() < measure(South): swap(South) if get_pos_y() > 1: move(South) insertion_sort_column_step() return move(North) def move_to(x, y): global WORLD_SIZE dx = x - get_pos_x() dy = y - get_pos_y() if dx > 0: if dx > WORLD_SIZE/2: move(West) else: move(East) elif dx < 0: if abs(dx) > WORLD_SIZE/2: move(East) else: move(West) if dy > 0: if dy > WORLD_SIZE/2: move(South) else: move(North) elif dy < 0: if abs(dy) > WORLD_SIZE/2: move(North) else: move(South) if not (get_pos_x() == x and get_pos_y() == y): move_to(x, y) else: return if __name__ == "__main__": clear() main() harvest() Maze (Recycling&Labyrinthmaster not working) ALL_DIRECTIONS = [North, South, East, West] #change map size here ( remove "#" below) #set_world_size(15) clear() def opposite_direction(direction): if direction == North: return South elif direction == East: return West elif direction == South: return North elif direction == West: return East def explore_option_iterative(start_direction): global ALL_DIRECTIONS if not move(start_direction): return False path_stack = [(start_direction, 0)] while path_stack and num_items(Items.Gold) < 9863168000000: if get_entity_type() == Entities.Treasure: harvest() start_maze() return True last_move_direction, next_dir_index = path_stack[-1] while next_dir_index < len(ALL_DIRECTIONS): explore_direction = ALL_DIRECTIONS[next_dir_index] path_stack[-1] = (last_move_direction, next_dir_index + 1) if opposite_direction(explore_direction) != last_move_direction: if move(explore_direction): path_stack.append((explore_direction, 0)) break next_dir_index += 1 if next_dir_index == len(ALL_DIRECTIONS): path_stack.pop() move(opposite_direction(last_move_direction)) move(opposite_direction(start_direction)) return False def start_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def search(): global drone_id global ALL_DIRECTIONS for _ in range(drone_id): do_a_flip() if drone_id % 2: ALL_DIRECTIONS = ALL_DIRECTIONS[::-1] if drone_id % 3: ALL_DIRECTIONS[0], ALL_DIRECTIONS[1] = (ALL_DIRECTIONS[1], ALL_DIRECTIONS[0]) if drone_id % 5: ALL_DIRECTIONS[1], ALL_DIRECTIONS[3] = (ALL_DIRECTIONS[3], ALL_DIRECTIONS[1]) while True: for direction in ALL_DIRECTIONS: if explore_option_iterative(direction): break drone_id = 0 start_maze() for i in range(max_drones()): drone_id = i spawn_drone(search) drone_id = 0 search() # For the "Recycling" and "Big Gold Farmer" achievements def generate_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def maze(): while True: if num_drones() == 25: if get_entity_type() == Entities.Treasure: harvest() generate_maze() clear() set_world_size(5) list = [] while num_drones() < 26: pos_x = get_pos_x() pos_y = get_pos_y() current = (pos_x, pos_y) if current not in list: list.append(current) spawn_drone(maze) move(North) else: move(East) Dino #change worldsize below by removing "#" #set_world_size(12) world_size = get_world_size() world_size_minus_one = world_size - 1 edge_positions = [0, world_size_minus_one] offlimit_columns_stage1 = { } offlimit_columns_stage2 = { } clear() change_hat(Hats.Dinosaur_Hat) apple_pos = measure() squares_occupied = 1 game_complete = False aggressive_stage = True def measure_apple(): global apple_pos global squares_occupied global apple_pos_queue apple_pos = measure() squares_occupied += 1 def move_and_check_apple(direction): global apple_pos if not move(direction): return False if (get_pos_x(), get_pos_y()) == apple_pos: measure_apple() return True def move_to_col(target_x_pos, do_measure=True): global world_size global apple_pos curr_x = get_pos_x() direction = West if curr_x < target_x_pos: direction = East for x in range(abs(target_x_pos - curr_x)): this_check = move if do_measure: this_check = move_and_check_apple if not this_check(direction): return False return True def move_to_row(target_y_pos, do_measure=True): global world_size global apple_pos curr_y = get_pos_y() direction = South if curr_y < target_y_pos: direction = North for y in range(abs(target_y_pos - curr_y)): this_check = move if do_measure: this_check = move_and_check_apple if not this_check(direction): return False return True def transition_to_stage_2(): global offlimit_columns_stage1 global world_size global world_size_minus_one move_to_col(world_size_minus_one) move_to_row(0) offlimit_columns_stage1 = { } return False def transition_to_stage_1(): global offlimit_columns_stage2 global world_size global world_size_minus_one move_to_col(0) move_to_row(world_size_minus_one) offlimit_columns_stage2 = { } return False def stage_1_apple_collect(): global apple_pos global world_size global offlimit_columns_stage1 global offlimit_columns_stage2 global world_size_minus_one apple_pos_x, apple_pos_y = apple_pos if apple_pos_y == 0 or apple_pos_x in edge_positions or (apple_pos_x in offlimit_columns_stage1 and apple_pos_y <= offlimit_columns_stage1[apple_pos_x]): return transition_to_stage_2() else: apple_x_odd = apple_pos_x % 2 target_x_pos = apple_pos_x if not apple_x_odd: target_x_pos = apple_pos_x - 1 if target_x_pos <= get_pos_x(): return transition_to_stage_2() else: move_to_col(target_x_pos) move_to_row(apple_pos_y) offlimit_columns_stage2[target_x_pos] = apple_pos_y offlimit_columns_stage2[target_x_pos + 1] = apple_pos_y move_and_check_apple(East) move_to_row(world_size_minus_one) return True def stage_2_apple_collect(): global apple_pos global world_size global offlimit_columns_stage1 global offlimit_columns_stage2 global world_size_minus_one apple_pos_x, apple_pos_y = apple_pos if apple_pos_y == world_size_minus_one or apple_pos_x in edge_positions or (apple_pos_x in offlimit_columns_stage2 and apple_pos_y >= offlimit_columns_stage2[apple_pos_x]): return transition_to_stage_1() else: apple_x_odd = apple_pos_x % 2 target_x_pos = apple_pos_x if apple_x_odd: target_x_pos = apple_pos_x + 1 if target_x_pos >= get_pos_x(): return transition_to_stage_1() else: move_to_col(target_x_pos) move_to_row(apple_pos_y) offlimit_columns_stage1[target_x_pos] = apple_pos_y offlimit_columns_stage1[target_x_pos - 1] = apple_pos_y move_and_check_apple(West) move_to_row(0) return True def move_to_right_col_wavy(): global world_size global world_size_minus_one global offlimit_columns_stage1 # Assume curr x is zero for x in range(world_size): if x % 2: target_y = 1 if x in offlimit_columns_stage1: target_y = offlimit_columns_stage1[x] + 1 while get_pos_y() != target_y: move(South) move(East) else: # x is even, go up to top row, then move right while get_pos_y() != world_size_minus_one: move(North) move(East) def find_top_left(): global world_size_minus_one while get_pos_x() > 0: move(West) while get_pos_y() < world_size_minus_one: move(North) def transition_to_route(): find_top_left() move_to_right_col_wavy() while get_pos_y() != 0: move(South) while get_pos_x() != 0: move(West) # STAGE 1 move_to_row(world_size_minus_one) while aggressive_stage: while stage_1_apple_collect() and get_pos_x() < world_size_minus_one: pass while stage_2_apple_collect() and get_pos_x() > 0: pass if squares_occupied > (world_size_minus_one) * 4 - 4: break transition_to_route() while True: for i in range(world_size / 2): game_complete = not move_to_row(world_size_minus_one, False) game_complete = game_complete or not move(East) game_complete = game_complete or not move_to_row(1, False) if i != world_size / 2 - 1: game_complete = game_complete or not move(East) if game_complete: break game_complete = game_complete or not move_to_row(0, False) game_complete = game_complete or not move_to_col(0,) if game_complete: break change_hat(Hats.Straw_Hat) Import Zyklus You need 2 different code-windows First window: def f0(): import ImportzyklusZubehör ImportzyklusZubehör.f1() f0() Second Window: def f1(): import ImportZyklus ImportZyklus.f0() You get the Achievement by running the first code-window Wrong Order clear() hats = [Hats.Green_Hat, Hats.Purple_Hat] #set_world_size(6) world_size = get_world_size() def _shortest_delta(curr, dest): size = world_size d = (dest - curr) % size if d > size / 2: d -= size return d def move_to_x_pos(x_target): x_curr = get_pos_x() moves_needed = _shortest_delta(x_curr, x_target) direction = East if moves_needed > 0: pass else: direction = West for _ in range(abs(moves_needed)): move(direction) def move_to_y_pos(y_target): y_curr = get_pos_y() moves_needed = _shortest_delta(y_curr, y_target) direction = North if moves_needed > 0: pass else: direction = South for _ in range(abs(moves_needed)): move(direction) def wait_for_drones(drones): for drone in drones: wait_for(drone) def drone_action_plant_cacti(): global world_size change_hat(hats[get_pos_x() % 2]) for _ in range(world_size): if get_ground_type() != Grounds.Soil: till() plant(Entities.Cactus) move(North) def plant_cacti(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for _ in range(world_size - 1): drones.append(spawn_drone(drone_action_plant_cacti)) move(East) drone_action_plant_cacti() move(East) move(North) wait_for_drones(drones) def shake_row(): global world_size change_hat(hats[get_pos_y() % 2]) left = 0 right = world_size - 1 while left < right: move_to_x_pos(left) loc_last_swap = left x_curr = get_pos_x() # Left-to-right pass while x_curr < right: # If the current element is smaller than the next, swap if measure() < measure(East): swap(East) loc_last_swap = x_curr move(East) x_curr += 1 right = loc_last_swap if left >= right: break move_to_x_pos(right) loc_last_swap = right x_curr = get_pos_x() # Right-to-left pass while x_curr > left: # If the previous element is larger than the current, swap if measure(West) > measure(): swap(West) loc_last_swap = x_curr move(West) x_curr -= 1 left = loc_last_swap def shake_col(): global world_size change_hat(hats[get_pos_x() % 2]) left = 0 right = world_size - 1 while left < right: move_to_y_pos(left) loc_last_swap = left y_curr = get_pos_y() # Bottom-to-top pass while y_curr < right: # If the current element is smaller than the one above, swap if measure() < measure(North): swap(North) loc_last_swap = y_curr move(North) y_curr += 1 right = loc_last_swap if left >= right: break move_to_y_pos(right) loc_last_swap = right y_curr = get_pos_y() # Top-to-bottom pass while y_curr > left: # If the element below is larger than the current, swap if measure(South) > measure(): swap(South) loc_last_swap = y_curr move(South) y_curr -= 1 left = loc_last_swap def sort_columns(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for _ in range(world_size - 1): drones.append(spawn_drone(shake_col)) move(East) shake_col() move(East) move(North) wait_for_drones(drones) def sort_rows(): global world_size move_to_x_pos(0) move_to_y_pos(0) drones = [] for _ in range(world_size - 1): drones.append(spawn_drone(shake_row)) move(North) shake_row() move(North) wait_for_drones(drones) while True: plant_cacti() sort_columns() sort_rows() harvest() Fashionshow def newHat(): hats = [Hats.Gold_Hat, Hats.Golden_Cactus_Hat, Hats.Golden_Carrot_Hat, Hats.Golden_Sunflower_Hat, Hats.Golden_Tree_Hat] while True: move(North) change_hat(hats[get_pos_x() % 5]) while True: spawn_drone(newHat) move(East) Labyrinthmaster def generate_maze(): plant(Entities.Bush) substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1) use_item(Items.Weird_Substance, substance) def maze(): while True: if num_drones() == 25: if get_entity_type() == Entities.Treasure: harvest() generate_maze() clear() set_world_size(5) list = [] while num_drones() < 26: pos_x = get_pos_x() pos_y = get_pos_y() current = (pos_x, pos_y) if current not in list: list.append(current) spawn_drone(maze) move(North) else: move(East) Leaderboard Achievements ----Comming soon---- Trubelshooting Every bracket "()" closed? Every " : " placed? Every indentation correct? Right Version(code was written in version 1.0 and till 18.11.2025 working)? Hope it was usefull. If anything doesn´t work let me know :)
✨ Updated for Release 1.0 ✨ Goal: To equip beginners with the foundational knowledge to ask informed questions and understand advanced programming tutorials (e.g., on YouTube). About This Guide: This workbook is for individuals new to coding who may face an experience paradox, where you have to know how to code to paste code on forums to ask for help. However if you cannot code, you cannot ask for coding help. Do the tasks in this workbook to break through the paradox. The workbook contains ten tasks designed to progressively introduce coding concepts based on the The Farmer Was Replaced, tech tree. The learning pace and tech unlocks are intentionally slow to allow for ample practice. Each new tech is referenced from the in-game documentation (I show you where), and variations of the documentation examples are used for practice. Completing this workbook will cover approximately 50% of the tech tree, providing enough coding knowledge to seek help on online forums. 📗 Using the In-Game Documentation: Throughout the workbook, you will be directed to specific in-game documentation. For example: "Have the Tuples doc handy -- [ i ] ➡️ Programming ➡️ Tuples." 📺 Supplementary Video Resources: Where relevant, links to concise YouTube videos explaining coding concepts will be provided. 🌾 🌾 🌾 PART I: Introduction 🌾 🌾 🌾 🌾 ⚜️ PART I -- intro We delve into creating tiny programs by following the game documentation. How to Use This Workbook Effectively: The tasks are presented first, and the corresponding answer key is located at the end. Before consulting the answer key, make a genuine attempt to solve each task or at least formulate a guess to engage your mind. Initially, the tasks will provide explicit instructions. From PART II, you will receive more hints and broader goals to encourage problem-solving. Complete Task 5 and then restart the game. After finishing Task 10, restart the game again. If you are brand new to coding and find The Farmer Was Replaced too hard I recommend these, in order of difficulty, easy to hard: Lightbot -- mobile and Flash -- demo/Flash $0 Flash --> https://lightbot.com/flash.html One Dreamer -- Steam -- demo $0 Modulo Code -- Microsoft Store -- $0 May's Journey -- Steam -- $0 Sam & MaRU -- Steam -- $10 📝 T01 - Hello Farm! | First Program Task T01 Explore functions and crop growth cycle works 🔓 Goals - Loop tech. Note: 📺 What are Functions? Coding for Kids | Kodable -- https://youtu.be/3JIZ40yuZL0?si=LF4RG9XB4xx-0oLq * Comments are preceded by # -- read [ i ] ➡️ Programming ➡️ Comments * Functions are small reusable of code appended by “()”. * Loops unlock cost -- [ Unlocks ] ➡️ (mouse over) [ Loops ] ➡️ 5 🌾 Hay * Read First Program -- [ i ] ➡️ General Info ➡️ First Program * Read First Program -- [ i ] ➡️ Built-in Functions Field -- what the field looks like before reaping -- one plot with 🌾[Grass]: 🌾 1. First Program doc shows two functions harvest() and do_a_flip() while pet_the_piggy() is under Built-in Functions 2. Create Program P01 - Hello Farm! i. Prepend the harvest functions with pet_the_piggy() ii. Define (type out) harvest() five times (refer to aforementioned First Program). iii. Append harvest functions with do_a_flip()3. Observe that the Hay Items (inventory) on the upper left of the screen is 5 4. Loop unlock requirements met -- unlock Loops in the tech tree -- [ Unlocks ] ➡️ (click) Loops . 5. Observe that unlocking tech can trigger an info window popup -- While Loop. Starter code -- copy the following into the code editor: #📝 Program P01 -- Hello Farm! #Explore built-in functions #Unlock Goal - Loops #read [ i ] ➡️ General Info ➡️ First Program #Reaping Phase #Reap 5 Hay #Write you code below #pet the pig #harvest 5 times #do a flip #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T02 - Mean While | Loops 📝 Task 02 Explore While loops 🔓 Goals - Speed tech. Note: 📺 Coding Basics: While Loops & Do While Loops | Programming for Beginners | Transcode 📰 the game does not offer do-while. https://youtu.be/v-K-4KuA8mQ?si=XBo_7OdGcgmU30gn * Unlock costs for Loops -- [ Unlocks ] ➡️ (mouse over) [ Speed ] ➡️ 20 🌾 Hay * Read While Loop doc -- [ i ] ➡️ Unlocks ➡️ Loops Field: 🌾 1. Refer to the While loop doc to create Program P02 Mean While i. Define two while loops, one that performs a flip under False conditions and another that harvests under True conditions. ii. Hint -- While Loop, the examples near the end of doc. iii. Observe that while False code block is not triggered, no flips are performed. iv. Observe that an infinite loop occurs and you only escape by terminating the program.2. Stop program when the reaping goal of 20 Hay is met. 3. Unlock Speed in the tech tree, triggering Speed Upgrade doc popup Starter code -- copy the following into the code editor: #📝 Program P02 -- Mean While #Explore While Loop #Unlock Goal - Speed #Reaping Phase #Reap 20 Hay #Write your code below: #Define -- a while loop, while in False conditions, performs a flip while False: do_a_flip() #Define -- a while loop, while in True conditions, harvest while True: harvest() #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T03 - Iffy Lube | Speed 📝 Task 03 Explore if statements and can_harvest() function 🔓 Goals - Expand tech. Note: 📺 Coding Basics: If Statements, If Else, Else - Coding Tutorial For Java, C, and C++! | Transcode 📰 the concept is same for Pyhton https://youtu.be/HQ3dCWjfRZ4?si=k7f7vkuCIDcqDIA2 * Verify Expand tech unlock cost of 30 🌾 Hay. * Read Speed -- [ i ] ➡️ Unlocks ➡️ Speed * From this point, read the new tech unlock docs without reminder -- commonly known in the tech field as RTFM (read the fine manual). Field: 🌾 1. Create Program P03 Iffy Lube. i. Define a function that if harvest is possible, harvests or else performs a flip. ii. Hint -- Read the fine manual (RTFM) -- [ i ] ➡️ Unlocks ➡️ Speed iii. Observe that harvesting is always successful since no premature harvest is performed. iv. Note that infinite loops will keep occurring until we find a fix. 2. Stop when the reaping goal of 30 Hay is met. 3. Unlock Expand tech triggering Expand 1 doc popup. Starter code -- copy the following into the code editor: #📝 Program P03 -- Iffy Lube #Explore if statements #Unlock Goal - Expand #Reaping Phase #Reap 30 Hay #Write your code below: #Define a function that if harvest is possible, harvests or else performs a flip. #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T04 - On The Move | Expand 📝 Task 04 Explore the movement function 🔓 Goals - Plant tech Note: What is Python? Why Python is So Popular? | Programming with Mosh https://youtu.be/Y8Tko2YC5hA?si=wI23ZwrjuEbd8g2k * Plant tech unlock cost is 50 🌾 Hay * Read Expand 1 doc -- [ i ] ➡️ Unlocks ➡️ Expand 1. Create and run Program P04 -- The Haymaker i. Check if harvest is possible, harvest, then move South. ii. Hint -- It’s similar to previous program, P032. Stop program to break the infinite loop when 50 Hay is harvested. 3. Unlock Plant tech, triggering Plant popup. Starter code -- copy the following into the code editor: #📝 Program P04 -- On The Move #Explore movement #Unlock Goal - Plant #you wrap back when going over the edge #Reaping Phase #Reap 30 Hay #Write code below: #while, if harvest is possible, harvest, then move South. #hint -- similar to previous program, P03 #else not needed since moving to new plot ensures harvest ready #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 🌲 🌲 🌲 PART II: Alea Iacta Est 🌲 🌲 🌲 🌲 ⚜️ PART II -- Alea Iacta Est You have unlocked enough techs that you can make more complex and clever programs. 📝 T05 - Bush League | Plant 📝 Task 05 Explore the Plant tech 🔓 Goals - Operators & Debug Note: * Operator tech unlock cost is 150 Hay and 10 Wood * Debug tech unlock cost is 50 🌾 Hay and 50 🌳 Wood * Read Expand 1 doc -- [ i ] ➡️ Unlocks ➡️ Plant We now have two phases Sowing and Reaping. Sowing is for prepping the field and practice coding but will at least have clear() to reset the field while reaping is for harvesting. The programs in the Answer Keys will have these to denote phases: #,_,_, SOWING PHASE ,_,_,_,_,_,_, #|_|_| REAPING PHASE |_|_|_|_|_|_| Wood takes longer than Hay to grow. Therefore we will allocate two square plots for 🌳 Bush and one for 🌾 Grass. Field: 🌾 🌳 🌳 1. Create Program P05 Bush League i. Harvest then sow Bush twice, and harvest Grass once (see the Field above). ii. Hint -- three separate harvests, repeated2. Stop program when 200 Hay and 60 Wood is harvested. 3. Unlock both Operators tech and Debug triggering doc popups. Starter code -- copy the following into the code editor: #📝 Task 05 Program P05 -- Bush League #,_,_, SOWING PHASE ,_,_,_,_,_,_, #clear the field clear() #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goal 100 Hay and 100 Wood #write your code below # Harvest then sow Bush twice, and harvest Grass once (see the Field above). # Hint -- three separate harvests, repeated #while loop here #1st plot -- check harvest ready #harvest #🌳 sow bush #move North to 2nd plot #2nd plot -- check harvest ready #harvest #🌳 sow bush #move North to 3rd plot #3rd plot -- check harvest ready #harvest #🌾no sowing -- keep grass #move North. wrapping around to 1st plot #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T06 - Press Zero For | Operators & Debug 📝 Task 06 Explore Operators & Debug 🔓 Goals - Senses Note: 📺 Evaluating compound boolean expressions | Intro to CS - Python | Khan Academy https://youtu.be/p7pJMvD2sag?si=lklqRtUcQbHjqsCC * Senses tech unlock costs of 100 🌾 Hay * Have the Operators doc handy -- [ i ] ➡️ Programming ➡️ Operators * Have the Debug doc handy -- [ i ] ➡️ Programming ➡️ Debug 1. Starter code -- Practice -- copy & paste then predict the outcome: #📝 Task 06 -- Program P06 -- Press Zero for #Explore Operators and Debug #Unlock Goal - Senses #PRACTICE 1 -- 👨🏫 Modulo Operator, an Arithmetic Operator #You can check if a number is odd or even since even number do not have remainders. #even numbers have 0 remainder #odd number have >0 remainders # 👨🏫Print() -- you can print to the screen as a way to double check things. if 4 % 2 == 0: print("even number") else: print("odd number") move(North) if 5 % 2 == 0: print("even number") else: print("odd number") move(South) #--- [||] PAUSE --- [|>] Run the program then proceed #PRACTICE 2 -- 👨🏫 Comparison Operators, if 1 > 0: print(1 > 0) move(North) if 0 != 5: print(0 != 5) move(North) if 0 == 0: print(0 == 0) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #End of practice -- continue to the next section of code, Sowing and Reaping. 2. Finish up by creating the reaping phase and copy i. Create code to harvest two Grass and one Bush (see above pic) ii. Hint -- Bush need to be replanted. 3. 6. Unlock Senses, triggering Senses doc popup. Add the following code to the starter code: #Append the following code to the starter code: ,_,_, SOWING PHASE ,_,_,_,_,_,_, #PRACTICE 3 -- 👨🏫 Logic Operators #Observe how logic operators work. #guess which plot will grow Bush clear() if not False: plant(Entities.Bush) print("not False -->", not False) move(North) if True and False: plant(Entities.Bush) print("True and False -->", True and False) move(North) if True or False: plant(Entities.Bush) print("True or False -->", True or False) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reap 100 Hay #The field should look like this after the Sowing Phase above : #🌾 Grass #🌳 Bush #🌾 Grass #Create a while loop to harvest then move North, harvesting Grass, Bush, then Grass. #Hint -- Bush need to be replanted. #write code below: #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T07 - Sensitivity Training | Sense & Debug 📝 Task 07 Explore Sense & Debug 🔓 Goals - Expand 2, Speed 2, Grass 2, Carrot, Hats, and Watering. Note: 📺 Python Program to Check Even or Odd Number Using Modulus Operator | Python for Beginners | ProgramGuru https://youtu.be/hZcC6R8vZYs?si=04d0EDL7Itp54DAE * Carrot and Hat tech unlock cost is 50 🌾 Hay and 50 🌳 Wood * infinite while loops can be exited by meeting conditions or via break. * Read Break -- [ i ] ➡️ Programming ➡️ Break. * Read Senses doc -- [ i ] ➡️ Unlocks ➡️ Senses * Read Debug doc -- [ i ] ➡️ Unlocks ➡️ Debug Starter code -- copy the following into the code editor: #📝 Program P07 -- Sensitivity Training #Explore Senses #Unlock Goal - Carrot, Hats, Expand 2, Grass 2, Speed 2 #,_,_, SOWING PHASE ,_,_,_,_,_,_, #* We used the modulo operator, % figure out odd or even numbers in Program P06. #* Use get_pos_y() with modulo operator to plant Bush only in even numbered y-axis. #* after reaching y-axis 2, move north to y-axis 0, then break out the loop #* How to stop loops early -- [ i ] ➡️ Programming ➡️ Break #* print() your location and modulo remainders after each move to help troubleshoot #Create a while loop to create this field: #🌳 bush #🌾 grass #🌳 bush clear() #reset your field #write code to prep field for harvest below: #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reaping goal -- 350 Hay and 90 Wood # add 350 and 90 to your existing inventory to get your harvest goal print(num_items(Items.Hay) + 350, "Hay", num_items(Items.Wood) + 90, "Wood", "required" ) #verify printed goals -- [ i ] ➡️ Output ➡️ output.txt (click link to open file) #Create a while loop reap: #* identify Entities.Bush, harvest then replant bush or else harvest hay. #* If both 50 Hay and 50 Wood beyond your inventory is harvested, exit loop. #Write code below: #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T08 - Gone Loopy | Hats, Carrot, Expand 2 (For Loop) Explore for loops, Hats and Carrot 🔓 Goals - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables 📺 For loops in Python are easy 🔁 | Fundraiser Bro Code -- https://youtu.be/KWgYha0clzw?si=hSQHRRTx3FbwmKIL * Create red dot on the left margin to put pause [||] points * Have the Expand II doc handy -- [ i ] ➡️ Unlocks ➡️ Expand 2 Here is how the relationship between ground, plant and crop works. There is a ground (Grassland and Soil) type that hosts plant (entity--Grass and Bush) type that yields crops (items--Hay and Wood). Use following functions to check for ground and plant type and item quantity.: * get_ground_type() * get_entity_type() * num_items() #Program P08 -- Gone Loopy #Explore Hats, Carrot, Expand 2 #Unlock Goal - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() #get_world_size() returns the length of the field print(get_world_size(), "-- field length") move(North) print((get_world_size() + get_world_size()), "-- field length 2X") #change hats for pure esthetics change_hat(Hats.Brown_Hat) #while loop that runs while Hay inventory is less than 987654321. #observe the the increase in Hay #example using if aconditional to break out of loop while num_items(Items.Hay) < 987654321: print(num_items(Items.Hay), "- before harvest") harvest() do_a_flip() print(num_items(Items.Hay), "- after harvest") if num_items(Items.Hay) > 0: print("Break condition met--exit") break #carrots require ground prep, till() --> Grounds.Soil #entity check: check the enitity, if not Carrot, till if get_entity_type() != Entities.Carrot: print(get_entity_type()) till() #ground check: check the ground, if Soil, plant carrot if get_ground_type() == Grounds.Soil: print(get_ground_type()) plant(Entities.Carrot) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ... ➿ Let us practice using for loops. # ... continued from above #For Loops #create a for loop named y-loop to traverse columns, y-axis #y_counter is an interger variable to count loops #y-loop - code block: print y_counter variable then move north, repeat 3 times #note - choosing range 3 will make y == 0, 1, 2 for y_counter in range(3): print("y ==", y_counter , "-- loop number", y_counter + 1) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #create a for loop named x-loop to traverse rows #use x_counter as the variable and get_world_size() for range #code block: print get_pos_x then moves east, repeat 3 times for x_counter in range(get_world_size()): print("x-axis is", x_counter ) move(East) #reset field clear() #--- [||] PAUSE --- [|>] Run the program then proceed #Traverse the entire field #Move N, N, N, and E, repeat 3 times by putting x-loop within y-loop (nesting). #x_counter and y_counter are variables and use get_world_size() for range #outer x loop code block: wear purple hat, print x position, move east #inner y loop code block: wear green hat, print y position, move north for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): change_hat(Hats.Green_Hat) print(get_pos_y(), "-- y-axis, Inner loop number", y_counter + 1) move(North) change_hat(Hats.Purple_Hat) print(get_pos_x(), "-- x-axis, Outer loop number", x_counter + 1) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ... Finally prep the field and harvest. # ... continued from above #,_,_, SOWING PHASE ,_,_,_,_,_,_, #prep the field with a nested for loop #carrots are more needed than wood, plant carrots in column 0 and 2 #outer loop -- prints x-axis, calls an inner loop, then moves east #inner loop -- checks for x-axis, plants carrots or bush, then move north #field prep goal #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | #write your code here #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goals 80 Wood and 125 Carrot #Expand 3 - 30 Wood 20 Carrot #Speed 3 - 50 Wood 50 Carrot #Grass 3 - 500 Wood #Carrot 2 - 250 Wood #Trees - 50 Wood 70 Carrot #Watering - 50 Wood #Variables - 35 Carrot # ====================== # 880 Wood 175 Carrot #--- [||] PAUSE --- [|>] Run the program then proceed #create a nested for loop within a while true loop. #if your Wood AND Carrot reach reaping goals, then break out of loop #write your code here #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 T09 -- Large Order | 🔓 Trees, Watering, and Variables Program P09 -- Large Order Explore Trees, Watering, and Variables Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions 📺 Coding Basics: Variables | Programming for Beginners | Transcode https://youtu.be/ghCbURMWBD8?si=WEfD2m3nSP3SWRJ2 [ i ] ➡️ Unlocks ➡️ Watering [ i ] ➡️ Built-in Functions ➡️ get_water [ i ] ➡️ Items ➡️ Water [ i ] ➡️ Unlocks ➡️ Trees [ i ] ➡️ Entities ➡️ Tree [ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator [ i ] ➡️ Unlocks ➡️ Variables Carrots require tilled soil, 2 Hay and 2 Wood. We can use variables to and seeds have costs. We are no longer over harvesting, and harvest goals are the exact unlock costs. 🌲Trees are different from 🌳 Bush, it grows best when staggered like below: 🌲🌾🌲 🌾🌲🌾 🌲🌾🌲 Program P09 -- Large Order #Explore Trees, Watering, and Variables #Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() # Watering # [ i ] ➡️ Unlocks ➡️ Watering # [ i ] ➡️ Built-in Functions ➡️ get_water # [ i ] ➡️ Items ➡️ Water while True: print(get_water() ) use_item(Items.Water) move(North) if get_water() > 0.25: print(get_water() ) break #--- [||] PAUSE --- [|>] Run the program then proceed clear() #variables # [ i ] ➡️ Unlocks ➡️ Variables farmside = get_world_size() #odds & evens # [ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator for y_counter in range( farmside ): move(North) if get_pos_y() % 2 == 0: print("even number") plant(Entities.Tree) move(East) for y_counter in range( farmside ): move(North) if get_pos_y() % 2 > 0: print("odd number") plant(Entities.Tree) #--- [||] PAUSE --- [|>] Run the program then proceed #using varibles to making a for loop max_loop = 3 loop = 0 while loop < max_loop: pet_the_piggy() #imcrement counter ➡️ reassign loop as loop number plus one loop = loop + 1 print(loop) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ⬇️ ... Trees will take the most space since Wood is a requirement to sow Carrots. # ... continued from above ⬆️ #,_,_, SOWING PHASE ,_,_,_,_,_,_, # Trees # [ i ] ➡️ Unlocks ➡️ Trees # [ i ] ➡️ Entities ➡️ Tree #Field prep visual map: # | 🥕C | 🌲T | 🥕C | 🌲T | # | 🌲T | 🌾G | 🌲T | 🌾G | # | 🥕C | 🌲T | 🥕C | 🌲T | # | 🌲T | 🌾G | 🌲T | 🌾G | # x, y coordinates: # | 0,3 C | 1,3 T | 2,3 C | 1,3 T | # | 0,2 T | 1,2 G | 2,2 T | 1,2 G | # | 0,1 C | 1,1 T | 2,1 C | 1,1 T | # | 0,0 T | 1,0 G | 2,0 T | 3,0 G | # Sowing Locations: #🌲 T-Tee (x-even and y-even) #🌲 T-Tree (x-odd and y-odd) #🥕 C-Carrot (x-even and y-odd) #🌾 G-Grass (x-odd and y-even) automatic -- leave alone #create a nested for loop, an x-row outer loop an y-column inner loop #define 3 if/elif statments: # checks for odd or even number with modulo operator for x,y pair # then check the x,y pair against the Sowing Locations table above for x_counter in range(farmside): for y_counter in range(farmside): #if statement for (x-even, y-even) check # your code here #if statement for(x-odd, y-odd) # your code here #if statement for(x-even, y-odd) # your code here move(North) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 4 - 500 Carrot # Grass 4 - 2500 Wood # Expand 4 - 100 Wood 50 Carrot # Carrot 3 - 1250 Wood # Trees 2 - 300 Hay # Watering 2 - 200 Wood # Pumpkin - 500 Wood 200 Carrot # Fertilizer - 500 Wood # Lists - 500 Carrot # Functions - 40 Carrot #==================== # 300 Hay, 5050 Wood, & 1290 Carrot #put on your work hat, the Staw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 300 ) wood_goal = ( num_items(Items.Wood) + 5050 ) carrot_goal = ( num_items(Items.Wood) + 1290 ) print( "Reaping goals --", hay_goal , "Hay", wood_goal , "Wood", carrot_goal , "Carrot" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed #Hay costs zero to produce and thus is not monitored while ( (num_items(Items.Wood) < wood_goal) or (num_items(Items.Carrot) < carrot_goal) ): # your code here move(East) #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ 📝 Task 10 - Pumpkin Patch | Pumpkin, Lists, & Functions Program P10 -- Pumpkin Patch Explore - Pumpkin, Lists, & Functions 🔓 Unlock Goal - Fertilizer, Dictionaries, Import, Utilities 📺 Coding Basics: Variables | Programming for Beginners | Transcode https://youtu.be/ghCbURMWBD8?si=WEfD2m3nSP3SWRJ2 Pumpkins 🎃 require more planning. Copy the following starter code: #Program P10 -- Pumpkin Patch #Explore - Pumpkin, Fertilizer, Lists, & Functions #Unlock Goal - Fertilizer, Dictionaries, Import, Utilities #Reaping goal -- # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #Note: this field is self suffcient provifing all inputs needed for carrot 🥕 and pumpkin 🎃. # »»---------------► PRACTICE #reset the field clear() # Functions # [ i ] ➡️ Unlocks ➡️ Functions # [ i ] ➡ Programming ➡️ Name Scopes #simple function to find if a number is odd #input an intger and the function will return true or false def oddity(integer): # take arugment, interger return integer % 2 != 0 #invoke oddity function with an argument and print it print(oddity(5), "-- is odd" ) move(North) print(oddity(2), "-- is even" ) do_a_flip() #Scope #what happens when variables are delcared inside of a function #assign tip to 0.10 then reassign tip as 0.50 inside the function tip = 0.11 def tipper(number): tip = 0.55 return number * tip #invoke tipper function with an argument and print it, then print tip variable print(tipper(1000)) move(North) print(tip) do_a_flip() #observe that outside of function, variables tip is unchanged # Lists # [ i ] ➡️ Unlocks ➡️ Lists # create a list with three elements # access elements by position, index numbers 0, 1, 2 easyas = [1, 2, 3] move(North) print( easyas[0], "...", easyas[2] ) do_a_flip() # create an empty list warehouse = [] print(warehouse) move(North) # add Items.Hay, Items.Carrot, Items.Carrot, Items.Water then print warehouse # add the following to the end of the list (append): warehouse.append(Items.Hay) warehouse.append(Items.Carrot) warehouse.append(Items.Pumpkin) warehouse.append(Items.Carrot) warehouse.append(Items.Carrot) warehouse.append("multipass") warehouse.append(Items.Water) warehouse.append(Items.Water) #how many elements are in the array?? print(len(warehouse)) #print the array before we change it move(North) print(warehouse) # change the list and print each time: # remove the 5th element warehouse.pop(5) print(warehouse) move(North) # remove the last element warehouse.pop() print(warehouse) move(North) # remove the first occurance of Carrot warehouse.remove(Items.Carrot) print(warehouse) move(North) # remove the first occurance of Carrot, again warehouse.remove(Items.Carrot) print(warehouse) move(North) # add Items.Wood at index 2 warehouse.insert(2, Items.Wood) print(warehouse) move(North) # remove first instance of pumpkin warehouse.remove(Items.Pumpkin) # print final size and content of the array print(len(warehouse), "--", warehouse) #--- [||] PAUSE --- [|>] Run the program then proceed continued ... #,_,_, SOWING PHASE ,_,_,_,_,_,_, #Field prep map P-umpkin, T-ree, C-arrot, G-rass: # | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | # | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🥕C | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🌾G | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # Coordinates Table: # | 0,5 | 1,5 | 2,5 | 3,5 | 4,5 | 5,5 | # | 0,4 | 1,4 | 2,4 | 3,4 | 4,4 | 5,4 | # | 0,3 | 1,3 | 2,3 | 3,3 | 4,3 | 5,3 | # | 0,2 | 1,2 | 2,2 | 3,2 | 4,3 | 5,2 | # | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | # | 0,0 | 1,0 | 2,0 | 3,0 | 4,0 | 5,0 | # Sowing Locations: # 1 southwest - 0,0 to 3,3 - pumpkin patch # 2 southeast - 4,0 to 5,5 - trees, grass, and carrots # 3 north - 0,4 to 5,5 - trees and carrots # Pumpkins require retangualr space, see docs: # [ i ] ➡️ Unlocks ➡️ Pumpkins # [ i ] ➡️ Entities ➡️ Pumpkin 🎃 # create a nested for loop, an x-row outer loop an y-column inner loop # define 3 if/elif statments: # checks for odd or even numbers # then check the x,y pair against the SCoordinates Table above clear() farmside = get_world_size() # x + y, if x or y is odd, the sume is aslo odd thus use modulus of x+y to find odd numbers # define odditor function that modifies the oddity function to take in two numbers as arguments then add it. def odditor(num1, num2): -- your code here -- # southwest - 0,0 to 3,3 - pumpkin patch # you need to move North more than once to wrap around for x_counter in ... for y_counter ... -- your code here -- # southeast - 4,0 to 5,5 - trees, grass, and carrots # you need to move North more than once to wrap around # exception -- carrot on plot 5,3 for x_counter in ... for y_counter ... -- your code here -- #north - 0,4 to 5,5 - trees and carrots for x_counter in ... for y_counter ... -- your code here -- #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 5 1000 Carrot # Grass 5 12500 Wood # Expand 5 1000 Pumpkin # Carrot 4 6250 Wood # Watering 3 800 Wood # Trees 3 1200 Hay # Fertilizer 2 1500 Wood # Dictionaries 2500 Pumpkin # Import 80 Carrot # Utilities 1000 Pumpkin #==================== # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #put on your work hat, the Straw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 1200 ) wood_goal = ( num_items(Items.Wood) + 22050 ) carrot_goal = ( num_items(Items.Wood) + 1080 ) pumpkin_goal = ( num_items(Items.Pumpkin) + 4500 ) print( "Reaping goals --", reap[0] , "Hay", reap[1] , "Wood", reap[2] , "Carrot", reap[3] , "Pumpkin" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed # Hay costs zero to produce and thus is not monitored # dead pumpkins -- sow pumpkin, cannot harvest # harvesting a pumpkin larger than one plot will leave multiple plots empty # Pumpkins are in x <4 and y<4 reap = [ hay_goal, wood_goal, carrot_goal, pumpkin_goal ] while ( num_items(Items.Wood) < reap[1] or num_items(Items.Carrot) < reap[2] or num_items(Items.Wood) < reap[3] ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping -- your code here -- #Carrot reaping -- your code here -- #pumpkin reaping #deap pumpkin - sow -- your code here -- #Hay reaping move(East) 🌵Cactus Cooler -- Final Project Final Project -- 🌵🕶️ Cactus Cooler Sorting data is a common task that pro programmer perform. Create a program to bubble sort data in the following coding challenge. Bubble sort is required for Cactus harvesting. Python Coding Problem: Bubble Sort the Numbers 1–9 Problem Statement: Write a Python function called bubble_sort that takes a list of integers containing the numbers 1 through 9 in any random order and returns a new list with the numbers sorted in ascending order using the bubble sort algorithm. Requirements: Do not use Python’s built-in sort() or sorted() functions. Implement the bubble sort algorithm explicitly. The function should return a new sorted list, not modify the input list in place. Example: # Example input numbers = [5, 9, 3, 1, 8, 6, 4, 2, 7] # Function call sorted_numbers = bubble_sort(numbers) # Expected output print(sorted_numbers) # Output: [1, 2, 3, 4, 5, 6, 7, 8, 9] Bonus: Count and return the number of swaps performed during the sorting process, along with the sorted list. Example Bonus Output:: sorted_numbers, swap_count = bubble_sort(numbers) print(sorted_numbers) # [1, 2, 3, 4, 5, 6, 7, 8, 9] print(swap_count) # e.g., 18 Hint: 📺 Visualization of Bubble Sort | G Bhat https://youtu.be/0BkoXZBbhfU?si=38eLIN8EvYrm7NkA ----------------- 🌵 Project Task Attempt to solve it in Python Online Compiler - Code Editor[www.programiz.com] Go to an large language model AI prompt, e.g. Open AI, Copilot, Gemini, Llama, Grok... input "solve the following problem and comment line by line" and the Copy, paste and enter the entire problem, with examples into the prompt. : input -- Solve the following problem and comment line by line. Python Coding Problem: Bubble Sort the Numbers 1–9 Write a Python function called bubble_sort that takes a list of integers containing the numbers 1 through 9 in any random order and returns a new list with the numbers sorted in ascending order using the bubble sort algorithm. Observe and learn from the comments. Reproduce the answer in the Python Online Compiler - Code Editor[www.programiz.com] If you need a basic guide on AI prompting grab 🤖 Tina Huang's AI Prompting Guide[offers.hubspot.com] ⏹️⏪▶️ Restart the game using instructions and hints only. 🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️ ⚜️ Part III: Answer Key If you really, really want to absorb this material, apply the Feynman technique and make a walkthrough guide like mine. https://www.youtube.com/watch?v=q-16DPh_VWw 💾Program P01 -- Hello Farm! #📝 Program P01 -- Hello Farm! #Explore built-in functions #Unlock Goal - Loops #read [ i ] ➡️ General Info ➡️ First Program #Reaping Phase #Reap 5 Hay #Write you code below #pet the pig pet_the_piggy() #harvest 5 times harvest() harvest() harvest() harvest() harvest() #do a flip do_a_flip() 💾Program P02 -- Mean While #📝 Program P02 -- Mean While #Explore While Loop #Unlock Goal - Speed #Reaping Phase #Reap 20 Hay #Write your code below: #Define -- a while loop, while in False conditions, performs a flip while False: do_a_flip() #Define -- a while loop, while in True conditions, harvest while True: harvest() 💾Program P03 -- Iffy Lube #📝 Program P03 -- Iffy Lube #Explore if statements #Unlock Goal - Expand #Reaping Phase #Reap 30 Hay #Write your code below: #Define a function that if harvest is possible, harvests or else performs a flip. while True: if can_harvest(): harvest() else: do_a_flip() 💾Program P04 -- On The Move #📝 Program P04 -- On The Move #Explore movement #Unlock Goal - Plant #you wrap back when going over the edge #Reaping Phase #Reap 30 Hay #Write code below: #while, if harvest is possible, harvest, then move South. #hint -- similar to previous program, P03 #else not needed since moving to new plot ensures harvest ready while True: if can_harvest(): harvest() move(South) 💾Program P05 -- Bush League #📝 Task 05 Program P05 -- Bush League #,_,_, SOWING PHASE ,_,_,_,_,_,_, clear() #clear the field #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goal 100 Hay and 100 Wood #write your code below # Harvest then sow Bush twice, and harvest Grass once (see the Field above). # Hint -- three separate harvests, repeated #while loop here while(True): if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() move(North) 💾Program P06 -- Press Zero for ... #📝 Task 06 -- Program P06 Press Zero for #Explore Operators and Debug #Unlock Goal - Senses #PRACTICE sessions #modulo operator % from Arthmetic Operators, checks for even or odd number #even numbers have 0 remainder #odd number have >0 remainders clear() if 4 % 2 == 0: print("even number") else: print("odd number") move(North) if 5 % 2 == 0: print("even number") else: print("odd number") move(South) #--- [||] PAUSE --- [|>] Run the program then proceed #observe how comparison operators work if 1 > 0: print(1 > 0) move(North) if 0 != 5: print(0 != 5) move(North) if 0 == 0: print(0 == 0) move(North) #--- [||] PAUSE --- [|>] Run the program then pr #,_,_, SOWING PHASE ,_,_,_,_,_,_, #observe how logic operators work #guess which plot will grow Bush clear() if not False: plant(Entities.Bush) print("not False -->", not False) move(North) if True and False: plant(Entities.Bush) print("True and False -->", True and False) move(North) if True or False: plant(Entities.Bush) print("True or False -->", True or False) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reap 100 Hay while True: if can_harvest(): harvest() move(North) if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() move(North) 💾Program P07 -- Sensitivity Training #Task 07 -- Program P07 -- So Sensitive #Explore Senses #Unlock Goal - Carrot, Hats, Expand 2, Grass 2, Speed 2 #,_,_, SOWING PHASE ,_,_,_,_,_,_, clear() #inventory check while get_pos_y() < 3: print(get_pos_y(), "y-axis", (get_pos_y() % 2), "remainder") if (get_pos_y() % 2) == 0: plant(Entities.Bush) if get_pos_y() == 2: move(North) break else: move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reaping goal -- 350 Hay and 90 Wood print(num_items(Items.Hay) + 350, "Hay", num_items(Items.Wood) + 90, "Wood", "required" ) while True: if can_harvest(): if get_entity_type() == Entities.Bush: harvest() plant(Entities.Bush) else: harvest() if (num_items(Items.Hay) > 550) and (num_items(Items.Wood) > 190): break move(North) 💾Program P08 -- Gone Loopy #Program P08 -- Gone Loopy #Explore Hats, Carrot, Expand 2 #Unlock Goal - Expand 3, Trees, Variables #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() #get_world_size() returns the length of the field print(get_world_size(), "-- field length") move(North) print((get_world_size() + get_world_size()), "-- field length 2X") #change hats for pure esthetics change_hat(Hats.Brown_Hat) #while loop that runs while Hay inventory is less than 987654321. #observe the the increase in Hay #example using if aconditional to break out of loop while num_items(Items.Hay) < 987654321: print(num_items(Items.Hay), "- before harvest") harvest() do_a_flip() print(num_items(Items.Hay), "- after harvest") if num_items(Items.Hay) > 0: print("Break condition met--exit") break #carrots require ground prep, till() --> Grounds.Soil #entity check: check the enitity, if not Carrot, till if get_entity_type() != Entities.Carrot: print(get_entity_type()) till() #ground check: check the ground, if Soil, plant carrot if get_ground_type() == Grounds.Soil: print(get_ground_type()) plant(Entities.Carrot) #--- [||] PAUSE --- [|>] Run the program then proceed # for loops #create a for loop named y-loop to traverse columns, y-axis #y_counter is an interger variable to count loops #y-loop - code block: print y_counter variable then move north, repeat 3 times #note - choosing range 3 will make y == 0, 1, 2 for y_counter in range(3): print("y ==", y_counter , "-- loop number", y_counter + 1) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #create a for loop named x-loop to traverse rows #use x_counter as the variable and get_world_size() for range #code block: print get_pos_x then moves east, repeat 3 times for x_counter in range(get_world_size()): print("x-axis is", x_counter ) move(East) #reset field clear() #--- [||] PAUSE --- [|>] Run the program then proceed #Traverse the entire field #Move N, N, N, and E, repeat 3 times by putting x-loop within y-loop (nesting). #x_counter and y_counter are variables and use get_world_size() for range #outer x loop code block: wear purple hat, print x position, move east #inner y loop code block: wear green hat, print y position, move north for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): change_hat(Hats.Green_Hat) print(get_pos_y(), "-- y-axis, Inner loop number", y_counter + 1) move(North) change_hat(Hats.Purple_Hat) print(get_pos_x(), "-- x-axis, Outer loop number", x_counter + 1) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed #,_,_, SOWING PHASE ,_,_,_,_,_,_, #prep the field with a nested for loop #carrots are mone needed than wood, plant carrots in column 0 and 2 #outer loop -- prints x-axis, calls an inner loop, then moves east #inner loop -- checks for x-axis, plants carrots or bush, then move north #field prep goal #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | for x in range(get_world_size()): for y in range(get_world_size()): if get_pos_x() == 1: plant(Entities.Bush) else: till() plant(Entities.Carrot) move(North) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goals 80 Wood and 125 Carrot #Expand 3 - 30 Wood 20 Carrot #Speed 3 - 50 Wood 50 Carrot #Grass 3 - 500 Wood #Carrot 2 - 250 Wood #Trees - 50 Wood 70 Carrot #Watering - 50 Wood #Variables - 35 Carrot # ====================== # 880 Wood 175 Carrot #put on your work hat, Staw Hat #print reaping goals change_hat(Hats.Straw_Hat) print( "Reaping goals --", (num_items(Items.Wood) + 880), "Wood", (num_items(Items.Carrot) + 175), "Carrot" ) #--- [||] PAUSE --- [|>] Run the program then proceed #create a nested for loop within a while true loop. ##if your Wood AND Carrot reach reaping goals, then break out of loop while True: for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): # using continue, [ i ] ➡️ Programming ➡️ Continue if not can_harvest(): move(North) continue harvest() if get_ground_type() == Grounds.Soil: plant(Entities.Carrot) else: plant(Entities.Bush) move(North) move(East) if ( ( num_items(Items.Wood) > 950 ) and ( num_items(Items.Carrot) > 200) ): break 💾Program P09 -- Large Order #Program P09 -- Large Order #Explore Trees, Watering, and Variables #Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() # Watering # [ i ] ➡️ Unlocks ➡️ Watering # [ i ] ➡️ Built-in Functions ➡️ get_water # [ i ] ➡️ Items ➡️ Water while True: print(get_water() ) use_item(Items.Water) move(North) if get_water() > 0.25: print(get_water() ) break #--- [||] PAUSE --- [|>] Run the program then proceed clear() #variables # [ i ] ➡️ Unlocks ➡️ Variables farmside = get_world_size() #odds & evens # [ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator for y_counter in range( farmside ): move(North) if get_pos_y() % 2 == 0: print("even number") plant(Entities.Tree) move(East) for y_counter in range( farmside ): move(North) if get_pos_y() % 2 > 0: print("odd number") plant(Entities.Tree) #--- [||] PAUSE --- [|>] Run the program then proceed #using varibles to making a for loop max_loop = 3 loop = 0 while loop < max_loop: pet_the_piggy() #imcrement counter ➡️ reassign loop as loop number plus one loop = loop + 1 print(loop) #--- [||] PAUSE --- [|>] Run the program then proceed #,_,_, SOWING PHASE ,_,_,_,_,_,_, # Trees # [ i ] ➡️ Unlocks ➡️ Trees # [ i ] ➡️ Entities ➡️ Tree #Field prep map with x, y cordinates: # 🥕🌲🥕🌲 | 0,3 Carrot | 1,3 Tree__ | 2,3 Carrot | 1,3 Tree__ | # 🌲🌾🌲🌾 | 0,2 Tree__ | 1,2 Hay___ | 2,2 Tree__ | 1,2 Hay___ | # 🥕🌲🥕🌲 | 0,1 Carrot | 1,1 Tree__ | 2,1 Carrot | 1,1 Tree__ | # 🌲🌾🌲🌾 | 0,0 Tree__ | 1,0 Hay___ | 2,0 Tree__ | 3,0 Hay___ | # Sowing Locations: #🌲 Tree (x-even and y-even) #🌲 Tree (x-odd and y-odd) #🥕 Carrot (x-even and y-odd) #🌾 Hay (x-odd and y-even) automatic -- leave alone #create a nested for loop, an x-row outer loop an y-column inner loop #define 3 if/elif statments: # checks for odd or even number with modulo operator for x,y pair # then check the x,y pair against the Sowing Locations table above for x_counter in range(farmside): for y_counter in range(farmside): #(x-even, y-even) if get_pos_x() % 2 == 0 and get_pos_y() % 2 == 0: plant(Entities.Tree) #(x-odd, y-odd) elif get_pos_x() % 2 > 0 and get_pos_y() % 2 > 0: plant(Entities.Tree) #(x-even, y-odd) elif get_pos_x() % 2 == 0 and get_pos_y() % 2 > 0: till() plant(Entities.Carrot) move(North) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 4 - 500 Carrot # Grass 4 - 2500 Wood # Expand 4 - 100 Wood 50 Carrot # Carrot 4 - 1250 Wood # Trees 2 - 300 Hay # Watering 2 - 200 Wood # Pumpkin - 500 Wood 200 Carrot # Fertilizer - 500 Wood # Lists - 500 Carrot # Functions - 40 Carrot #==================== # 300 Hay, 5050 Wood, & 1290 Carrot #put on your work hat, the Staw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 300 ) wood_goal = ( num_items(Items.Wood) + 5050 ) carrot_goal = ( num_items(Items.Wood) + 1290 ) print( "Reaping goals --", hay_goal , "Hay", wood_goal , "Wood", carrot_goal , "Carrot" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed #Hay costs zero to produce and thus is not monitored while ( (num_items(Items.Wood) < wood_goal) or (num_items(Items.Carrot) < carrot_goal) ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping if get_entity_type() == Entities.Tree: #water here if get_water() < 0.25: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Tree) #Carrot reaping elif get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) #Hay reaping else: harvest() move(North) move(East) 💾Program P10 - Pumpkin Patch #Program P10 -- Pumpkin Patch #Explore - Pumpkin, Fertilizer, Lists, & Functions #Unlock Goal - Fertilizer, Dictionaries, Import, Utilities #Reaping goal -- # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #Note: this field is self suffcient provifing all inputs needed for carrot 🥕 and pumpkin 🎃. # »»---------------► PRACTICE #reset the field clear() # Functions # [ i ] ➡️ Unlocks ➡️ Functions # [ i ] ➡ Programming ➡️ Name Scopes #simple function to find if a number is odd #input an intger and the function will return true or false def oddity(integer): # take arugment, interger return integer % 2 != 0 #invoke oddity function with an argument and print it print(oddity(5), "-- is odd" ) move(North) print(oddity(2), "-- is even" ) do_a_flip() #Scope #what happens when variables are delcared inside of a function #assign tip to 0.10 then reassign tip as 0.50 inside the function tip = 0.11 def tipper(number): tip = 0.55 return number * tip #invoke tipper function with an argument and print it, then print tip variable print(tipper(1000)) move(North) print(tip) do_a_flip() #observe that outside of function, variables tip is unchanged # Lists # [ i ] ➡️ Unlocks ➡️ Lists # create a list with three elements # access elements by position, index numbers 0, 1, 2 easyas = [1, 2, 3] move(North) print( easyas[0], "...", easyas[2] ) do_a_flip() # create an empty list warehouse = [] print(warehouse) move(North) # add Items.Hay, Items.Carrot, Items.Carrot, Items.Water then print warehouse # add the following to the end of the list (append): warehouse.append(Items.Hay) warehouse.append(Items.Carrot) warehouse.append(Items.Pumpkin) warehouse.append(Items.Carrot) warehouse.append(Items.Carrot) warehouse.append("multipass") warehouse.append(Items.Water) warehouse.append(Items.Water) #how many elements are in the array?? print(len(warehouse)) #print the array before we change it move(North) print(warehouse) # change the list and print each time: # remove the 5th element warehouse.pop(5) print(warehouse) move(North) # remove the last element warehouse.pop() print(warehouse) move(North) # remove the first occurance of Carrot warehouse.remove(Items.Carrot) print(warehouse) move(North) # remove the first occurance of Carrot, again warehouse.remove(Items.Carrot) print(warehouse) move(North) # add Items.Wood at index 2 warehouse.insert(2, Items.Wood) print(warehouse) move(North) # remove first instance of pumpkin warehouse.remove(Items.Pumpkin) # print final size and content of the array print(len(warehouse), "--", warehouse) #--- [||] PAUSE --- [|>] Run the program then proceed #,_,_, SOWING PHASE ,_,_,_,_,_,_, #Field prep map P-umpkin, T-ree, C-arrot, G-rass: # | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | # | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🥕C | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🌾G | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # Coordinates Table: # | 0,5 | 1,5 | 2,5 | 3,5 | 4,5 | 5,5 | # | 0,4 | 1,4 | 2,4 | 3,4 | 4,4 | 5,4 | # | 0,3 | 1,3 | 2,3 | 3,3 | 4,3 | 5,3 | # | 0,2 | 1,2 | 2,2 | 3,2 | 4,3 | 5,2 | # | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | # | 0,0 | 1,0 | 2,0 | 3,0 | 4,0 | 5,0 | # Sowing Locations: # 1 southwest - 0,0 to 3,3 - pumpkin patch # 2 southeast - 4,0 to 5,5 - trees, grass, and carrots # 3 north - 0,4 to 5,5 - trees and carrots # Pumpkins require retangualr space, see docs: # [ i ] ➡️ Unlocks ➡️ Pumpkins # [ i ] ➡️ Entities ➡️ Pumpkin 🎃 # create a nested for loop, an x-row outer loop an y-column inner loop # define 3 if/elif statments: # checks for odd or even numbers # then check the x,y pair against the SCoordinates Table above clear() farmside = get_world_size() # x + y, if x or y is odd, the sume is aslo odd thus use modulus of x+y to find odd numbers # define odditor function that modifies the oddity function to take in two numbers as arguments then add it. def odditor(num1, num2): return ( num1 + num2 ) % 2 != 0 # southwest - 0,0 to 3,3 - pumpkin patch # you ned to move North more than once to wrap around for x_counter in range(farmside - 2): for y_counter in range(farmside - 2): if get_ground_type() == Grounds.Grassland: till() plant(Entities.Pumpkin) harvest() plant(Entities.Pumpkin) move(North) move(East) move(North) move(North) # southeast - 4,0 to 5,5 - trees, grass, and carrots # you need to move North more than once to wrap around # exception -- carrot on plot 5,3 for x_counter in range(farmside - 4): for y_counter in range(farmside - 2): if odditor( get_pos_x(), get_pos_y() ) == True: plant(Entities.Tree) elif get_pos_x() == 5 and get_pos_y() == 3: till() plant(Entities.Carrot) move(North) move(East) if get_pos_x() == 0: break move(North) move(North) #north - 0,4 to 5,5 - trees and carrots for y_counter in range(farmside - 4): for x_counter in range(farmside): if odditor( get_pos_x(), get_pos_y() ) == True: plant(Entities.Tree) else: till() plant(Entities.Carrot) move(East) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 5 1000 Carrot # Grass 5 12500 Wood # Expand 5 1000 Pumpkin # Carrot 4 6250 Wood # Watering 3 800 Wood # Trees 3 1200 Hay # Fertilizer 2 1500 Wood # Dictionaries 2500 Pumpkin # Import 80 Carrot # Utilities 1000 Pumpkin #==================== # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #put on your work hat, the Straw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 1200 ) wood_goal = ( num_items(Items.Wood) + 22050 ) carrot_goal = ( num_items(Items.Wood) + 1080 ) pumpkin_goal = ( num_items(Items.Pumpkin) + 4500 ) print( "Reaping goals --", reap[0] , "Hay", reap[1] , "Wood", reap[2] , "Carrot", reap[3] , "Pumpkin" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed # Hay costs zero to produce and thus is not monitored # dead pumpkins -- sow pumpkin, cannot harvest # harvesting a pumpkin larger than one plot will leave multiple plots empty # Pumpkins are in x <4 and y<4 reap = [ hay_goal, wood_goal, carrot_goal, pumpkin_goal ] while ( num_items(Items.Wood) < reap[1] or num_items(Items.Carrot) < reap[2] or num_items(Items.Wood) < reap[3] ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping if get_entity_type() == Entities.Tree: #water here if get_water() < 0.21: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Tree) #Carrot reaping elif get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) #pumpkin reaping #deap pumpkin - sow elif ( get_pos_x() < 4 and get_pos_y() < 4 ): if get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) if get_water() < 0.41: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Pumpkin) #Hay reaping else: harvest() move(North) move(East)
本指南包含以下程序: 1) 我用来达到世界第11名的程序(7分36秒内获得2亿南瓜) 2) 用于完成1无人机成就的程序 3) 简化的游戏通关程序无法识别内容,已删除。
1) Программа с помощью которой я достиг топ 11 места в мире 7.36 The program I used to reach the top 11 in the world (200 million pumpkins in 7 minutes 36 seconds) https://images.steamusercontent.com/ugc/11271849466455372074/7A993263573E27C19ABE742FAD93CAF58ACB5F23/?imw=256&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false clear() def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def water_more(): if get_water() < 0.75: use_item(Items.Water) def water(): if get_water() < 0.5: use_item(Items.Water) elif get_water() < 0.75 and num_items(Items.Water) > 2: use_item(Items.Water) def ProTill(): if get_ground_type() != Grounds.Soil: till() def PumpkinIsReady(): while get_pos_x() != 31: move(East) NewMeasure=measure() move(East) MeasureEnd=measure() move(West) return NewMeasure == MeasureEnd def PlantPumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) def Plant_and_water_Pumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() use_item(Items.Fertilizer) def Plant_and_fertilize_Pumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() use_item(Items.Fertilizer) def mega_pumpkin_dead(): WorldSize = get_world_size() xmax = 4 ymax = 8 x0 = get_pos_x() - get_pos_x() % 4 y0 = (3 - get_pos_x() % 4) * 8 if y0 == 24: move(South) elif y0 == 16: for i in range(9): move(South) elif y0 == 8: for i in range(8): move(North) while num_items(Items.Pumpkin) < 200000000: #Plant all for i in range(WorldSize): ProTill() PlantPumpkin() move_like_snake(x0, y0, xmax, ymax) #check dead_pumpkin dead_pumpkins = [] all_pumpkins = True for i in range(WorldSize): ent = get_entity_type() if ent == Entities.Dead_Pumpkin: dead_pumpkins.append((get_pos_x(), get_pos_y())) PlantPumpkin() all_pumpkins = False elif ent == Entities.Pumpkin and not can_harvest(): dead_pumpkins.append((get_pos_x(), get_pos_y())) water() all_pumpkins = False move_like_snake(x0, y0, xmax, ymax) last_pos_x = 0 last_pos_y = 0 #go_to dead_pumpkins and plant while get_entity_type() != None: y = get_pos_y() x = get_pos_x() new_pos_x = 0 new_pos_y = 0 #find near dead_pumpkins but not 0 for (x_dead, y_dead) in dead_pumpkins: if (x, y) != (x_dead, y_dead): temporary_pos_x, temporary_pos_y = measure_pos(x_dead, y_dead, x, y) if (temporary_pos_x, temporary_pos_y) != (0, 0): if (temporary_pos_x, temporary_pos_y) != (last_pos_x, last_pos_y): if (new_pos_x, new_pos_y) == (0, 0) or abs(new_pos_x)+abs(new_pos_y) > abs(temporary_pos_x)+abs(temporary_pos_y): (new_pos_x, new_pos_y) = (temporary_pos_x, temporary_pos_y) #go_to new position last_pos_x = -new_pos_x last_pos_y = -new_pos_y if (new_pos_x, new_pos_y) != (0, 0): go_to_new_pos(new_pos_x, new_pos_y) #checking for dead pumpkins and replanting if dead_pumpkins != []: ent = get_entity_type() if ent == Entities.Dead_Pumpkin: Plant_and_fertilize_Pumpkin() elif not can_harvest() and ent == Entities.Pumpkin: water_more() elif can_harvest() and ent == Entities.Pumpkin and (get_pos_x(), get_pos_y()) in dead_pumpkins: dead_pumpkins.remove((get_pos_x(), get_pos_y())) elif ent == None: break else: water() move_like_snake(x0, y0, xmax, ymax) #go_to new position def go_to_new_pos(new_pos_x, new_pos_y): if new_pos_y >0: for i in range(new_pos_y): move(North) else: for i in range(abs(new_pos_y)): move(South) if new_pos_x >0: for i in range(new_pos_x): move(East) else: for i in range(abs(new_pos_x)): move(West) #measuring the difference between positions def measure_pos(x_dead, y_dead, x, y): ky = y_dead - y kx = x_dead - x return kx, ky #Spawn Drones for i in range(max_drones()-1): spawn_drone(mega_pumpkin_dead) move(East) #main drone x0 = 28 y0 = 0 xmax = 4 ymax = 8 WorldSize = get_world_size() while num_items(Items.Pumpkin) < 200000000: #Plant all for i in range(WorldSize): ProTill() PlantPumpkin() move_like_snake(x0, y0, xmax, ymax) #check dead_pumpkin dead_pumpkins = [] pumpkins_harvest = False for i in range(WorldSize): ent = get_entity_type() if ent == Entities.Dead_Pumpkin: dead_pumpkins.append((get_pos_x(), get_pos_y())) PlantPumpkin() all_pumpkins = False elif ent == Entities.Pumpkin and not can_harvest(): dead_pumpkins.append((get_pos_x(), get_pos_y())) water() all_pumpkins = False move_like_snake(x0, y0, xmax, ymax) last_pos_x = 0 last_pos_y = 0 #go_to dead_pumpkins and plant while get_entity_type() != None: y = get_pos_y() x = get_pos_x() new_pos_x = 0 new_pos_y = 0 #find near dead_pumpkins but not 0 for (x_dead, y_dead) in dead_pumpkins: if (x, y) != (x_dead, y_dead): temporary_pos_x, temporary_pos_y = measure_pos(x_dead, y_dead, x, y) if (temporary_pos_x, temporary_pos_y) != (0, 0): if (temporary_pos_x, temporary_pos_y) != (last_pos_x, last_pos_y): if (new_pos_x, new_pos_y) == (0, 0) or abs(new_pos_x)+abs(new_pos_y) > abs(temporary_pos_x)+abs(temporary_pos_y): (new_pos_x, new_pos_y) = (temporary_pos_x, temporary_pos_y) #go_to new position last_pos_x = -new_pos_x last_pos_y = -new_pos_y if (new_pos_x, new_pos_y) != (0, 0): go_to_new_pos(new_pos_x, new_pos_y) #checking for dead pumpkins and replanting if dead_pumpkins != []: ent = get_entity_type() if ent == Entities.Dead_Pumpkin: Plant_and_fertilize_Pumpkin() elif not can_harvest() and ent == Entities.Pumpkin: water_more() elif can_harvest() and ent == Entities.Pumpkin and (get_pos_x(), get_pos_y()) in dead_pumpkins: dead_pumpkins.remove((get_pos_x(), get_pos_y())) elif ent == None: break elif PumpkinIsReady(): harvest() pumpkins_harvest = True 2) Программа для достижений с 1 дроном 2) The program for achieving 1 drone achievement clear() def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def water(): if get_water() < 0.75: use_item(Items.Water) def ProTill(): if get_ground_type() != Grounds.Soil: till() def PumpkinIsReady(): NewMeasure=measure() move(East) MeasureEnd=measure() move(West) return NewMeasure == MeasureEnd def PlantPumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() def Plant_and_fertilize_Pumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() use_item(Items.Fertilizer) #go_to new position def go_to_new_pos(new_pos_x, new_pos_y): if new_pos_y >0: for i in range(new_pos_y): move(North) else: for i in range(abs(new_pos_y)): move(South) if new_pos_x >0: for i in range(new_pos_x): move(East) else: for i in range(abs(new_pos_x)): move(West) #measuring the difference between positions def measure_pos(x_dead, y_dead, x, y): ky = y_dead - y kx = x_dead - x if kx > 16: kx = kx - 32 elif kx < -16: kx = kx + 32 if ky > 16: ky = ky - 32 elif ky < -16: ky = ky + 32 return kx, ky WorldSize = get_world_size() while num_items(Items.Pumpkin) < 2000000000: for i in range(WorldSize*WorldSize): ProTill() PlantPumpkin() move_like_snake(0, 0, WorldSize, WorldSize) #check dead_pumpkin dead_pumpkins = [] all_pumpkins = True for i in range(WorldSize*WorldSize): ent = get_entity_type() if ent == Entities.Dead_Pumpkin: dead_pumpkins.append((get_pos_x(), get_pos_y())) PlantPumpkin() all_pumpkins = False elif ent == Entities.Pumpkin and not can_harvest(): dead_pumpkins.append((get_pos_x(), get_pos_y())) water() all_pumpkins = False move_like_snake(0, 0, WorldSize, WorldSize) last_pos_x = 0 last_pos_y = 0 #go_to dead_pumpkins and plant while get_entity_type() != None: y = get_pos_y() x = get_pos_x() new_pos_x = 0 new_pos_y = 0 #find near dead_pumpkins but not 0 for (x_dead, y_dead) in dead_pumpkins: if (x, y) != (x_dead, y_dead): temporary_pos_x, temporary_pos_y = measure_pos(x_dead, y_dead, x, y) if (temporary_pos_x, temporary_pos_y) != (0, 0): if (temporary_pos_x, temporary_pos_y) != (last_pos_x, last_pos_y): if (new_pos_x, new_pos_y) == (0, 0) or abs(new_pos_x)+abs(new_pos_y) > abs(temporary_pos_x)+abs(temporary_pos_y): (new_pos_x, new_pos_y) = (temporary_pos_x, temporary_pos_y) #go_to new position last_pos_x = -new_pos_x last_pos_y = -new_pos_y if (new_pos_x, new_pos_y) != (0, 0): go_to_new_pos(new_pos_x, new_pos_y) #checking for dead pumpkins and replanting if dead_pumpkins != []: ent = get_entity_type() if ent == Entities.Dead_Pumpkin: Plant_and_fertilize_Pumpkin() elif not can_harvest() and ent == Entities.Pumpkin: water_more() elif can_harvest() and ent == Entities.Pumpkin and (get_pos_x(), get_pos_y()) in dead_pumpkins: dead_pumpkins.remove((get_pos_x(), get_pos_y())) elif ent == None: break else: harvest() 3) Упрощенная программа для прохождения игры 3) A simplified program for completing the game clear() def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def water(): if get_water() < 0.75: use_item(Items.Water) def ProTill(): if get_ground_type() != Grounds.Soil: till() def PumpkinIsReady(): NewMeasure=measure() move(East) MeasureEnd=measure() move(West) return NewMeasure == MeasureEnd def PlantPumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() def Plant_and_water_Pumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() use_item(Items.Fertilizer) def Plant_and_fertilize_Pumpkin(): while get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) water() use_item(Items.Fertilizer) #go_to new position def go_to_new_pos(new_pos_x, new_pos_y): if new_pos_y >0: for i in range(new_pos_y): move(North) else: for i in range(abs(new_pos_y)): move(South) if new_pos_x >0: for i in range(new_pos_x): move(East) else: for i in range(abs(new_pos_x)): move(West) #measuring the difference between positions def measure_pos(x_dead, y_dead, x, y): ky = y_dead - y kx = x_dead - x if kx > 16: kx = kx - 32 elif kx < -16: kx = kx + 32 if ky > 16: ky = ky - 32 elif ky < -16: ky = ky + 32 return kx, ky WorldSize = get_world_size() while num_items(Items.Pumpkin) < 2000000000: for i in range(WorldSize*WorldSize): ProTill() PlantPumpkin() move_like_snake(0, 0, WorldSize, WorldSize) #check dead_pumpkin dead_pumpkins = [] all_pumpkins = True for i in range(WorldSize*WorldSize): ent = get_entity_type() if ent == Entities.Dead_Pumpkin: dead_pumpkins.append((get_pos_x(), get_pos_y())) PlantPumpkin() all_pumpkins = False elif ent == Entities.Pumpkin and not can_harvest(): dead_pumpkins.append((get_pos_x(), get_pos_y())) water() all_pumpkins = False move_like_snake(0, 0, WorldSize, WorldSize) #go_to dead_pumpkins and plant while get_entity_type() != None: y = get_pos_y() x = get_pos_x() #find near dead_pumpkins but not 0 for (x_dead, y_dead) in dead_pumpkins: if (x, y) != (x_dead, y_dead): new_pos_x, new_pos_y = measure_pos(x_dead, y_dead, x, y) break #go_to new position last_pos_x = -new_pos_x last_pos_y = -new_pos_y if (new_pos_x, new_pos_y) != (0, 0): go_to_new_pos(new_pos_x, new_pos_y) #checking for dead pumpkins and replanting if dead_pumpkins != []: ent = get_entity_type() if ent == Entities.Dead_Pumpkin: Plant_and_fertilize_Pumpkin() elif not can_harvest() and ent == Entities.Pumpkin: water_more() elif can_harvest() and ent == Entities.Pumpkin and (get_pos_x(), get_pos_y()) in dead_pumpkins: dead_pumpkins.remove((get_pos_x(), get_pos_y())) elif ent == None: break else: harvest()
Working code for sorting and harvesting cacti. Easy to understand even for coding beginners. Will of course contain spoilers. Introduction Here is a quick and working guide for sorting cacti and harvesting the whole field. I'm a junior-dev IRL though not with Python. This game was a little and fun learning experience for me. Meaning my code can surely be improved on and optimized. Though i don't care right now, it's working and doing it's thing. This guide will provide code, therefore it contains obviously spoilers for the cactus puzzle. It should be obvious, but we live in difficult times regarding common sense and thinking capability ;) Might also contain spelling errors, i wasn't to keen to double and triple check everything. If you find a spelling error: finders keepers :) Overview Important: i have the option in Options -> Errors -> Shadowing Errors disabled (as i'm a developer myself and know the basics about scopes). If you have that option enabled, you probably get errors. Either rename the loop variables inside the small helper functions to something unique (no variable used inside the main script) or also turn said option to disabled. The basic idea is just like the hint of the cactus introduction tells you: If we sort all columns and afterwards all rows (or vice-versa) in a grid, the whole grid will be sorted. I have some useful functions (also useful for other puzzles), so here is what we're going over: 1. Initial tilling 2. trade to bound 3. go to position 4. cactus script Initial Till A small function to till the whole farm area: def initial_till(): for i in range(get_world_size()): for i in range(get_world_size()): till() move(North) move(East) Really nothing fancy, and also ends at the field you're starting in. Trade to Bound I don't like buying more seeds than i need, so sometimes this function is helpful if you know exactly how much seeds you need. Because cacti always do grow (unlike pumpkins), we do know how much seeds we need. def tradeIfLower(item, number): nItem = num_items(item) if nItem < number: trade(item, number - nItem) For example, if you have 4 cactus seed, and want to buy up to 10 seeds, this will buy 6 seeds. Go to position Often, you can traverse the whole field with just moving north and east until you're back at the starting position. Sometimes though, we want to move to specific tiles. This function does exactly that: def goTo(xCoord, yCoord): if get_pos_x() > xCoord: goRight = xCoord + get_world_size() - get_pos_x() else: goRight = xCoord - get_pos_x() if get_pos_x() > xCoord: goLeft = get_pos_x() - xCoord else: goLeft = get_pos_x() + get_world_size() - xCoord if get_pos_y() > yCoord: goUp = yCoord + get_world_size() - get_pos_y() else: goUp = yCoord - get_pos_y() if get_pos_y() > yCoord: goDown = get_pos_y() - yCoord else: goDown = get_pos_y() + get_world_size() - yCoord # move left or right, whichever is faster if goLeft < goRight: for i in range(goLeft): move(West) else: for i in range(goRight): move(East) # move up or down, whichever is faster if goDown < goUp: for i in range(goDown): move(South) else: for i in range(goUp): move(North) I don't want to go too much in depth, as this guide is about cacti, but here is the gist: We are getting the x and y coordinate of our goal position. Then we calculate if it would be faster to go left or right and up or down. Then we move accordingly to the shortest path. Cactus Script Finally the main script for the cacti. You'll need the helper functions shown before, without them, you'll get errors. First the script, explanation is below. clear() cache = {} initial_till() while True: tradeIfLower(Items.Cactus_Seed, get_world_size()**2) for i in range(get_world_size()): for j in range(get_world_size()): plant(Entities.Cactus) cache[(i,j)] = measure() move(North) move(East) #sort columns for h in range(get_world_size()): count = 0 for i in range(get_world_size() - 1): #check if already sorted sorted = True for s in range(get_world_size() - 1): if cache[h,s] > cache[h,s + 1]: sorted = False break if sorted == True: break for j in range(get_world_size() - count - 1): if cache[h,j + 1] < cache[h,j]: swap(North) cache[(h,j)] = measure() cache[(h,j + 1)] = measure(North) move(North) goTo(h,0) count += 1 move(East) #sort rows for h in range(get_world_size()): count = 0 for i in range(get_world_size() - 1): #check if already sorted sorted = True for s in range(get_world_size() - 1): if cache[s,h] > cache[s + 1,h]: sorted = False break if sorted == True: break for j in range(get_world_size() - count - 1): if cache[j + 1,h] < cache[j,h]: swap(East) cache[(j,h)] = measure() cache[(j + 1,h)] = measure(East) move(East) goTo(0,h) count += 1 move(North) harvest() If you just want to copy the code, stop looking here. Anything below is just explanation of the main script. This is a little bigger, but let's break it down. First of all, we're do clear(), to reset to default. This also puts the drone at our starting position of 0 , 0. Then we're defining an empty dictionary. We will use that to keep track of the cactus values. Before entering the main loop, we also do an initial_till, because cacti need soil. Starting in the main loop, we have this block first: tradeIfLower(Items.Cactus_Seed, get_world_size()**2) for i in range(get_world_size()): for j in range(get_world_size()): plant(Entities.Cactus) cache[(i,j)] = measure() move(North) move(East) Basically, we buy seeds, if we don't have enough for the whole field. Then we traverse the whole field, plant a cactus on each field and save the size of the cactus in the dictionary with the current position as key. Next, we sort the cacti column wise. Let's start explaining from the inside. The most important loop is the j-loop: for j in range(get_world_size() - count - 1): if cache[h,j + 1] < cache[h,j]: swap(North) cache[(h,j)] = measure() cache[(h,j + 1)] = measure(North) move(North) Ignore the count for a second. This loop compares the cactus currently below the drone with the next one. If the next one is smaller, then we swap. Of course we then need to update our cache. We do these comparisons for the whole column. After this loop, the biggest number (or one of them if there are multiple identical numbers) is guaranteed to be at the far end. Of course we need the whole column sorted, meaning we need to sort as many times as the column has elements minus one. Because if you have 3 elements, you can only do 2 comparisons ( 1 with 2 and 2 with 3). Hence we wrap our loop with another loop: for i in range(get_world_size() - 1): #check if already sorted sorted = True for s in range(get_world_size() - 1): if cache[h,s] > cache[h,s + 1]: sorted = False break if sorted == True: break for j in range(get_world_size() - count - 1): if cache[h,j + 1] < cache[h,j]: swap(North) cache[(h,j)] = measure() cache[(h,j + 1)] = measure(North) move(North) goTo(h,0) count += 1 The i-loop is exactly doing that, making sure the whole column gets sorted, not only 1 number. Now we also see the count variable we use in the j-loop. Every time the j-loop sorts the biggest number to the end, we can compare 1 less field, because we already know that the biggest number got sorted to the end. You could run the code perfectly fine without the count, though it would be less optimized. I've also built another optimization: before we start sorting the biggest number, we check if the whole column is already sorted. In that case we just break the i-loop, and move on to the next column. Finally we wrap this in another loop to sort every column in the grid: #sort columns for h in range(get_world_size()): count = 0 for i in range(get_world_size() - 1): #check if already sorted sorted = True for s in range(get_world_size() - 1): if cache[h,s] > cache[h,s + 1]: sorted = False break if sorted == True: break for j in range(get_world_size() - count - 1): if cache[h,j + 1] < cache[h,j]: swap(North) cache[(h,j)] = measure() cache[(h,j + 1)] = measure(North) move(North) goTo(h,0) count += 1 move(East) After we have sorted every column, we now need to also sort all the rows. Basically it's the same code as for the rows, but simply switched some indices and movement directions to transform sorting of columns into sorting of rows. I won't go into detail here, as it is so similar. Finally, after all the rows have been sorted, we call harvest() and are happy about harvesting a full field of cacti. Afterwords Thanks for reading. If you found this guid helpful, consider a thumbs up, to also help out others looking for help. If you have any questions, feel free to ask inside the comments, i'll try to help as much as my free time allows it.













