From cf311ae3fa9a8b782e6a2aacb5c23099ea725e98 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sun, 6 Nov 2022 02:24:21 +0100 Subject: [PATCH] Implement condition functions --- lambdaV.py | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/lambdaV.py b/lambdaV.py index 4e43b36..e40eeed 100644 --- a/lambdaV.py +++ b/lambdaV.py @@ -74,30 +74,51 @@ def draw_field(): print(field[row][column], end="") print("") -def condition_in_front_of_wall(inverted): - return False - -def condition_goal_reached(inverted): - return False - -def condition_on_apple(inverted): - return False def condition_facing_north(inverted): - return False + if inverted: + return not cursor_current == cursor_north + return cursor_current == cursor_north def condition_facing_south(inverted): - return False + if inverted: + return not cursor_current == cursor_south + return cursor_current == cursor_south def condition_facing_east(inverted): - return False + if inverted: + return not cursor_current == cursor_east + return cursor_current == cursor_east def condition_facing_west(inverted): - return False + if inverted: + return not cursor_current == cursor_west + return cursor_current == cursor_west -# condition prefixed with ! -def modifier_not(condition): - return condition(true) +def condition_in_front_of_wall(inverted): + if condition_facing_north(False): + result = field[cursor_position[1]-1][cursor_position[0]]==wall or field[cursor_position[1]-1][cursor_position[0]]=='_' + elif condition_facing_south(False): + result = field[cursor_position[1]+1][cursor_position[0]]==wall or field[cursor_position[1]+1][cursor_position[0]]=='¯' + elif condition_facing_east(False): + result = field[cursor_position[1]][cursor_position[0]+1]==wall or field[cursor_position[1]][cursor_position[0]+1]=='|' + elif condition_facing_west(False): + result = field[cursor_position[1]][cursor_position[0]-1]==wall or field[cursor_position[1]][cursor_position[0]-1]=='|' + else: + result = False + if inverted: + return not result + return result + +def condition_goal_reached(inverted): + if inverted: + return not field[cursor_position[1]][cursor_position[2]]==goal + return field[cursor_position[1]][cursor_position[2]]==goal + +def condition_on_apple(inverted): + if inverted: + return not field[cursor_position[1]][cursor_position[2]]==apple + return field[cursor_position[1]][cursor_position[2]]==apple # return value: "" or error message def command_step():