From 12dd5f50d6cb120bfaad7c868df3c89269352d10 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sun, 6 Nov 2022 03:30:58 +0100 Subject: [PATCH] Implement motion and take commands --- lambdaV.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/lambdaV.py b/lambdaV.py index 08ababb..33c7703 100644 --- a/lambdaV.py +++ b/lambdaV.py @@ -122,13 +122,54 @@ def condition_on_apple(inverted): # return value: "" or error message 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 "" 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 "" 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 "" def command_repeat(number, parsed_code): @@ -137,9 +178,6 @@ def command_repeat(number, parsed_code): def command_while(parsed_condition, parsed_code): return "" -def command_take(): - return "" - def command_if(parsed_condition, parsed_then_code, parsed_else_code): return ""