下载客户端

解开迷宫

2026-02-20 01:00:16
发布在编程农场
转载

AI智能总结导读

这是《The Farmer Was Replaced》游戏的迷宫解谜指南,核心讲解用左手法则解决无环迷宫的方法,还附带了实现该解法的完整程序,包含迷宫创建、导航、找宝藏和收集宝藏的代码,同时说明迷宫由给灌木施肥生成,成功率较低需循环尝试。

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!

评论

共0条评论
face
inputImg
相关阅读
最新更新

走迷宫游戏 好玩的走迷宫游戏大全 2026有趣的迷宫手游排行榜

弯弯曲曲的通道和墙壁,很容易让人找不准方向、心里发慌。走迷宫游戏就是要在一次次摸不清头绪的时候,慢慢找到出去的正确路子。这里给大家推荐五款经得起反复玩的迷宫游戏…

2025-12-24 15:290赞 · 0评论

迷之觉悟攻略 异梦迷城全流程攻略图文

异梦迷城全流程攻略是什么?异梦迷城怎么玩?本作包含复杂的天赋加点、角色培养、机关解谜、武器装备等多种元素,还有将近一百个不同成就可以达成,很多小伙伴不知道异梦迷…

2025-09-26 04:160赞 · 0评论

The Thief Girl ~ 盗賊少女 ~-视频介绍

2026-03-31 01:300赞 · 0评论

家园2攻略 家园2攻略-家园2攻略秘籍

家园2攻略-家园2攻略秘籍 家园2是一款流行的手机游戏,以下是一些攻略秘籍,帮助你在游戏中取得更好的成绩。 1. 消除方块技巧 在家园2中,你需要通过消除相同的…

2025-08-11 11:590赞 · 0评论

Hidden Fears (Moonlight Edition)-视频介绍

2026-04-03 10:300赞 · 0评论

4 树篱迷宫指南

我正在发布一些我发现和探索到的片段内容,之后会整理成完整的指南。 四个树篱迷宫 在其中一座城堡里有四个树篱迷宫,它们就在那个包含故事传说的谜题旁边。 1. 绿色…

2026-03-20 22:000赞 · 0评论

第八关

转自B站玩家:De牧木

2025-04-14 03:290赞 · 0评论

【完整游戏】《生化危机4》全流程攻略+DLC,包含所有宝藏和所有商人任务

☣ 第一章和第二章 ☣ 第一章: 村庄宝藏1(丝绒红宝石)- 00:31:38 补充地图宝藏(别致项链)- 00:32:59 村庄宝藏2(红宝石)- 00:34…

2026-03-31 16:020赞 · 0评论

事件 - 以太矿工

✨ 踏上《以太矿工》的异世界采矿冒险吧!✨ 欢迎来到这片神秘的土地,这里有奇幻的风景和数不尽的财富等待你去发现。加入我们,在闪闪发光的洞穴中开启一段迷人的旅程,…

2026-01-26 05:000赞 · 0评论

神秘岛宝藏3攻略 神秘海域3攻略 神秘海域3墙上的图案攻略

本篇文章给大家谈谈神秘海域3攻略,以及神秘海域3墙上的图案攻略对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助…

2025-11-11 19:350赞 · 0评论
暂无更多

最新更新

  • Recycling Achievement — 轻松获取重复使用同一迷宫300次成就的提示与方法 获取【Recycling】成就的方法: 要获得【Recycling】成就,你需要重复使用同一个迷宫300次。 …
  • 使用嵌套函数解决迷宫问题 — 一个用于解决迷宫的极简嵌套函数方案。 其工作原理: 一个用于解决迷宫的极简嵌套函数方案。 定义执行分支(起点): 若获取实体类型()等于实体.宝藏: 收获() …
  • 俄语翻译 — 很遗憾,这款游戏没有被翻译成所有语言,因为像这种实用的、教授编程的游戏应该面向所有人,包括那些英语掌握不够熟练的人。有一种观点认为,如果从事编程工作,就应该懂英…
  • 解锁成本 — 自动化 farming 的终极挑战是尽可能快速地自动完成游戏流程。以下是游戏自动化相关的解锁内容概述: 解锁树 本指南包含游戏 1.0 版本前的解锁成本信息。
  • 《仙人掌农场》(2025) — It's the cactus farm, with explanations inside the code as comments. You can jus…
  • 编程初学者的代码 — *DUE TO STILL GOING THROUGH THE GAME, THIS IS A WIP. * I have never created, lea…
  • 成就解锁器.exe — # 奖杯自动化 解锁(成就) 循环导入和栈溢出 此成就需要2个脚本:f0和f1 循环导入f0: import f1 f1: import f0
  • 解开迷宫 — The maze levels are very different than the remainder of the game. It's possible…
  • 大多数成就代码 — Title is self explaining I want to say something First of all im not a native sp…
  • 《编程农场》全成就指南 — 这是一篇关于《编程农场》全成就达成思路的指南。 请注意:本篇内容并不包含实现代码,而只是成就达成思路的提示。 介绍与提示 首先需要注意的是:本篇内容并不包含实现…