Implement condition functions
parent
70456794a4
commit
cf311ae3fa
51
lambdaV.py
51
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():
|
||||
|
|
Loading…
Reference in New Issue