The Farmer Was Replaced

The Farmer Was Replaced

the maze
Hey everyone,
I’ve come up with an idea for solving the maze. It’s basically the "right-hand strategy," but it wasn’t obvious to me at first how to deal with the fact that in the game, you can only move North, East, South, or West, rather than “to the right” or “straight ahead.” So, I wrote this code. However, the game isn’t happy with the arguments I’m passing to move(). The way I set up the array and how I defined ahead, right, and back seems like it should work in Python, but it doesn’t seem to work in the game. Can someone help me figure this out? Thanks a lot!
x = 0
HR = ["North","East","South","West"]
i = 1

while(x == 0):
if get_entity_type() == Entities.Treasure:
harvest()
x = 1


ahead = HR
right = HR[i+1]
back = HR[i+2]


if move(right) == True:
move(right)
i = (i+1)%4
elif move(ahead) == True:
move(ahead)
elif move(ahead) == False:
move(back)
i = (i+2)%4
< >
Showing 1-8 of 8 comments
One major issue is that you haven't given us enough information; even with sharing your code, we still don't know what the problem is without copy/pasting it into the game... which is not really viable, because we would need to be at the same point in the game you are, with a maze spawned, etc, before we could even try to understand what your code is doing/not doing that you don't/do want it to.

Use [code]your code here[/code] to preserve formatting when sharing code; it's unreadable when it's all in one column, because we have no idea where your loops/conditionals end.

x = 0 HR = ["North","East","South","West"] i = 1 while(x == 0): if get_entity_type() == Entities.Treasure: harvest() x = 1 ahead = HR[ i ] # Steam still grabbed this tag :P right = HR[i+1] back = HR[i+2] if move(right) == True: move(right) i = (i+1)%4 elif move(ahead) == True: move(ahead) elif move(ahead) == False: move(back) i = (i+2)%4

All of that being said... I can see at least one issue with this code, which I'll guess is the problem you're having; you're moving to test if you can move, then moving again if you moved the first time.

To put that another way: move() tries to move, then returns whether it was successful at doing so.

try:
if move(right): i=(i + 1) % 4 ...

You may also want to move back to your original position if the move was successful, in case you want to try the other directions while you're there (for example, to map out the maze so you can run it multiple times by fertilizing the chest instead of harvesting it, and thus gain greater rewards).
I had the same idea with the right hand thing, my code is a little long, but it works.
f=0 #facing direction 0=East 1=South 2=West 3=North while True: if get_entity_type() == Entities.Grass: break while True: if get_entity_type() == Entities.Treasure: harvest() break if f == 0: #facing East if move(South): #try to go right f=1 break if move(East): #try to continue going straight f=0 break if move(North): #try to go left f=3 break if move(West): #turn around f=2 break if f == 1: #facing South if move(West): #try to go right f=2 break if move(South): #try to continue going straight f=1 break if move(East): #try to go left f=0 break if move(North): #turn around f=3 break if f == 2: #facing West if move(North): #try to go right f=3 break if move(West): #try to continue going straight f=2 break if move(South): #try to go left f=1 break if move(East): #turn around f=0 break if f == 3: #facing North if move(East): #try to go right f=0 break if move(North): #try to continue going straight f=3 break if move(West): #try to go left f=2 break if move(South): #turn around f=1 break
def MazeMove():
PosX=0
PosY=0
dir = [South,East,North,West]
curr0ir = 0
new0ir = 0
while get_entity_type()!=Entities.Treasure:
if get_pos_x()==PosX and get_pos_y()==PosY:
curr0ir += 1
if curr0ir == 4:
curr0ir = 0
PosX = get_pos_x()
PosY = get_pos_y()
move(dir[curr0ir])
else:
PosX = get_pos_x()
PosY = get_pos_y()
if curr0ir-1>=0:
new0ir = curr0ir-1
move(dir[new0ir])
else:
new0ir = 3
move(dir[new0ir])
if get_pos_x()!=PosX or get_pos_y()!=PosY:
curr0ir = new0ir
else:
move(dir[curr0ir])


feel short until you add in the creation of the maze itself

def Maze():
Number=0
on = False
while True:
clear()
if Number>=10:
Check()
Number=0
if num_items(Items.Weird_Substance)<=100:
on = True
while on:
if num_items(Items.Weird_Substance)<=5000:
plant(Entities.Bush)
use_item(Items.Water)
use_item(Items.Fertilizer)
harvest()
else:
on = False
plant(Entities.Bush)
use_item(Items.Water)
use_item(Items.Fertilizer)
use_item(Items.Weird_Substance, 50)
MazeMove()
harvest()
Number=Number+1

update to the lower code for newest item Weird_Substance
Been a long minute but the following still applies.

https://steamcommunity.com/app/2060160/discussions/0/4521136185566148104/

Originally posted by LustONE:
In case somebody find it useful

def complete_maze(): ix, dirs = 0, [East, South, West, North] while get_entity_type() != Entities.Treasure: ix += 1 - move(dirs[ix % 4])*2 harvest()


The above is a really simple solver but absolutely brilliant.
Now that is some compact code!
Originally posted by owenz:
Been a long minute but the following still applies.

https://steamcommunity.com/app/2060160/discussions/0/4521136185566148104/

Originally posted by LustONE:
In case somebody find it useful

def complete_maze(): ix, dirs = 0, [East, South, West, North] while get_entity_type() != Entities.Treasure: ix += 1 - move(dirs[ix % 4])*2 harvest()


The above is a really simple solver but absolutely brilliant.

It's so compact it may be hard to understand.

def complete_maze():
# Index 0:East, 1:North, 2:West, 3:South
dir_index = 0
directions = [East, North, West, South]

while get_entity_type() != Entities.Treasure:
# Get the direction we are currently facing
current_dir = directions[dir_index % 4]

if move(current_dir):
# SUCCESS: We moved forward.
# To hug the right wall, we must try to turn RIGHT.
dir_index -= 1
else:
# BLOCKED: We hit a wall.
# We must turn LEFT to find an opening.
dir_index += 1

harvest()
Originally posted by Mr Newbie:
...

It's so compact it may be hard to understand.

def complete_maze():
# Index 0:East, 1:North, 2:West, 3:South
dir_index = 0
directions = [East, North, West, South]

while get_entity_type() != Entities.Treasure:
# Get the direction we are currently facing
current_dir = directions[dir_index % 4]

if move(current_dir):
# SUCCESS: We moved forward.
# To hug the right wall, we must try to turn RIGHT.
dir_index -= 1
else:
# BLOCKED: We hit a wall.
# We must turn LEFT to find an opening.
dir_index += 1

harvest()

This is brilliant, still need to adjust it for re-using mazes but very simple and working excellently

Here, written a bit nicer

dir_index = 0 directions = [East, North, West, South] while get_entity_type() != Entities.Treasure: # Get the direction we are currently facing current_dir = directions[dir_index % 4] if move(current_dir): # SUCCESS: We moved forward. # To hug the right wall, we must try to turn RIGHT. dir_index -= 1 else: # BLOCKED: We hit a wall. # We must turn LEFT to find an opening. dir_index += 1 harvest()
Hope this could help
It will just like flooding to all direction
World Size 32
Tested 250 times.
Average time is 13.9 --> 141.4 kGold/min
_____________________________________
clear()
n_substancve = 180*num_unlocked(Unlocks.Mazes)
Time_Temp = get_time()
Counting = 0
Old_Average = 0
import Lib_Wait
def Harvest_Maze():
if get_entity_type() == Entities.Treasure:
harvest()

def Restart_Maze():
plant(Entities.Bush)
use_item(Items.Weird_Substance,n_substancve)

def North_Maze():
move(North)
Harvest_Maze()
if measure()!=None:
if can_move(West):
spawn_drone(West_Maze)
if can_move(North):
spawn_drone(North_Maze)
if can_move(East):
spawn_drone(East_Maze)

def East_Maze(): #if going to any direction spawn_drone to any direction it could(Exept backward)
move(East)
Harvest_Maze()
if measure()!=None:
if can_move(North):
spawn_drone(North_Maze)
if can_move(East):
spawn_drone(East_Maze)
if can_move(South):
spawn_drone(South_Maze)

def South_Maze():
move(South)
Harvest_Maze()
if measure()!=None:
if can_move(East):
spawn_drone(East_Maze)
if can_move(South):
spawn_drone(South_Maze)
if can_move(West):
spawn_drone(West_Maze)

def West_Maze():
move(West)
Harvest_Maze()
if measure()!=None:
if can_move(South):
spawn_drone(South_Maze)
if can_move(West):
spawn_drone(West_Maze)
if can_move(North):
spawn_drone(North_Maze)
Restart_Maze()
spawn_drone(North_Maze)
spawn_drone(East_Maze)
Time_Temp = get_time()

while(True):
do_a_flip()
if (measure()==None):
Restart_Maze()
Counting +=1
spawn_drone(North_Maze)
spawn_drone(East_Maze)
Old_Average = Old_Average+(((get_time()-Time_Temp)-Old_Average)/Counting)
print("Count time(s) :",get_time()-Time_Temp," Average time(s) :",Old_Average,"/",Counting,"Ratio : ",1962/Old_Average,"kGold/Min")
Time_Temp = get_time()

if (num_drones() == 1):
spawn_drone(North_Maze)
spawn_drone(East_Maze)




< >
Showing 1-8 of 8 comments
Per page: 1530 50