基础代码:收获

0 点赞
编程农场
转载

本指南提供了《农夫被替换了》的经过测试且可正常运行的代码脚本,能帮助你高效推进游戏进程。非常适合想要了解自动化概念并查看实际应用示例的玩家。 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.这里没什么好说的——如果你有需要,请留言。