Implement motion and take commands
parent
5f6990050b
commit
12dd5f50d6
46
lambdaV.py
46
lambdaV.py
|
@ -122,13 +122,54 @@ def condition_on_apple(inverted):
|
||||||
|
|
||||||
# return value: "" or error message
|
# return value: "" or error message
|
||||||
def command_step():
|
def command_step():
|
||||||
#TODO
|
if condition_in_front_of_wall(False):
|
||||||
|
return "You walked into a wall."
|
||||||
|
|
||||||
|
if condition_facing_north(False):
|
||||||
|
cursor_position[1] = cursor_position[1]-1
|
||||||
|
elif condition_facing_south(False):
|
||||||
|
cursor_position[1] = cursor_position[1]+1
|
||||||
|
elif condition_facing_east(False):
|
||||||
|
cursor_position[0] = cursor_position[0]+1
|
||||||
|
elif condition_facing_west(False):
|
||||||
|
cursor_position[0] = cursor_position[0]-1
|
||||||
|
else:
|
||||||
|
return "Cannot step because direction is unknown."
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def command_left():
|
def command_left():
|
||||||
|
global cursor_current
|
||||||
|
if condition_facing_north(False):
|
||||||
|
cursor_current = cursor_west
|
||||||
|
elif condition_facing_south(False):
|
||||||
|
cursor_current = cursor_east
|
||||||
|
elif condition_facing_east(False):
|
||||||
|
cursor_current = cursor_north
|
||||||
|
elif condition_facing_west(False):
|
||||||
|
cursor_current = cursor_south
|
||||||
|
else:
|
||||||
|
return "Cannot turn left because direction is unknown."
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def command_right():
|
def command_right():
|
||||||
|
global cursor_current
|
||||||
|
if condition_facing_north(False):
|
||||||
|
cursor_current = cursor_east
|
||||||
|
elif condition_facing_south(False):
|
||||||
|
cursor_current = cursor_west
|
||||||
|
elif condition_facing_east(False):
|
||||||
|
cursor_current = cursor_south
|
||||||
|
elif condition_facing_west(False):
|
||||||
|
cursor_current = cursor_north
|
||||||
|
else:
|
||||||
|
return "Cannot turn right because direction is unknown."
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def command_take():
|
||||||
|
if condition_on_apple(True):
|
||||||
|
# Note: condition is inverted
|
||||||
|
return "Cannot take apple, there is no apple here."
|
||||||
|
field[cursor_position[1]] = field[cursor_position[1]][:cursor_position[0]]+" "+field[cursor_position[1]][cursor_position[0]+1:]
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def command_repeat(number, parsed_code):
|
def command_repeat(number, parsed_code):
|
||||||
|
@ -137,9 +178,6 @@ def command_repeat(number, parsed_code):
|
||||||
def command_while(parsed_condition, parsed_code):
|
def command_while(parsed_condition, parsed_code):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def command_take():
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def command_if(parsed_condition, parsed_then_code, parsed_else_code):
|
def command_if(parsed_condition, parsed_then_code, parsed_else_code):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue