Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
def opposite_direction(dir):
return {
North: South,
East: West,
West: East,
South: North
}[dir]
def rec(dir):
if get_entity_type() == Entities.Treasure:
harvest()
return True
for d in [North, East, West, South]:
if d != opposite_direction(dir) and move(d):
if rec(d):
return True
move(opposite_direction(dir))
return False
def one_maze():
i = 0
if get_entity_type() != Entities.Bush and get_entity_type() != Entities.Hedge:
harvest()
plant(Entities.Bush)
while get_entity_type() == Entities.Bush:
if num_items(Items.Fertilizer) == 0:
trade(Items.Fertilizer)
use_item(Items.Fertilizer)
if get_entity_type() == Entities.Treasure:
harvest()
return
for d in [North, East, West, South]:
if move(d):
if rec(d):
break
return True
It starts with some support functions, followed by the actual program
def Maze():
def expecting(ground):
if get_ground_type()!=ground:
till()
def fertilize():
if num_items(Items.Fertilizer)<=1 and num_items(Items.Pumpkin)>=10:
if not trade(Items.Fertilizer):
return False
elif num_items(Items.Pumpkin)<=10:
return False
if num_items(Items.Fertilizer)>1:
return use_item(Items.Fertilizer)
def plant_bush():
expecting(Grounds.Turf)
plant(Entities.Bush)
def plant_maze():
harvest()
plant_bush()
while get_entity_type() != Entities.Hedge:
fertilize()
return None
dirs = [North,West,South,East]
dir = 0
plant_maze()
while get_entity_type() != Entities.Treasure:
while not move(dirs[dir]):
dir = (dir + 1) % 4
dir = (dir - 1) % 4
harvest()
return True
And the modulo is a brilliant change. Well done!
Also (advanced) you can simnplify the calculation of the direction using modulo.
[code]
dirs = [North, East, South, West]
dir = 0
while get_entity_type() != Entities.Treasure:
while not move(dirs[dir]):
dir = (dir + 1) % 4
dir = (dir - 1) % 4
harvest()[/code]