From c91e01629443559f3a8c502d6ccf2886dd5c4615 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Wed, 19 Apr 2023 21:40:40 +0200 Subject: [PATCH] added state class --- state.py | 6 ++++++ succ.py | 44 +++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 state.py diff --git a/state.py b/state.py new file mode 100644 index 0000000..40a3133 --- /dev/null +++ b/state.py @@ -0,0 +1,6 @@ +class State: + def __init__(self, parent, xpos, ypos, orientation): + self.parent = parent + self.xpos = xpos + self.ypos = ypos + self.orientation = orientation \ No newline at end of file diff --git a/succ.py b/succ.py index 600471e..69a8df0 100644 --- a/succ.py +++ b/succ.py @@ -1,28 +1,30 @@ -def succ(xpos, ypos, orientation): +from state import State + +def succ(st: State): successors = [] - if orientation == 'N': - successors.append(['LEFT', xpos, ypos, 'W']) - successors.append(['RIGHT', xpos, ypos, 'E']) - if ypos > 0: - successors.append(['FORWARD', xpos, ypos - 50, 'N']) + if st.orientation == 'N': + successors.append(['LEFT', State(st, st.xpos, st.ypos, 'W')]) + successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'E')]) + if st.ypos > 0: + successors.append(['FORWARD', State(st, st.xpos, st.ypos - 50, 'N')]) - if orientation == 'S': - successors.append(['LEFT', xpos, ypos, 'E']) - successors.append(['RIGHT', xpos, ypos, 'W']) - if ypos < 750: - successors.append(['FORWARD', xpos, ypos + 50, 'S']) + if st.orientation == 'S': + successors.append(['LEFT', State(st, st.xpos, st.ypos, 'E')]) + successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'W')]) + if st.ypos < 750: + successors.append(['FORWARD', State(st, st.xpos, st.ypos + 50, 'S')]) - if orientation == 'W': - successors.append(['LEFT', xpos, ypos, 'S']) - successors.append(['RIGHT', xpos, ypos, 'N']) - if xpos > 0: - successors.append(['FORWARD', xpos - 50, ypos, 'W']) + if st.orientation == 'W': + successors.append(['LEFT', State(st, st.xpos, st.ypos, 'S')]) + successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'N')]) + if st.xpos > 0: + successors.append(['FORWARD', State(st, st.xpos - 50, st.ypos, 'W')]) - if orientation == 'E': - successors.append(['LEFT',xpos, ypos, 'N']) - successors.append(['RIGHT', xpos, ypos, 'S']) - if xpos < 750: - successors.append(['FORWARD', xpos + 50, ypos, 'E']) + if st.orientation == 'E': + successors.append(['LEFT', State(st, st.xpos, st.ypos, 'N')]) + successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'S')]) + if st.xpos < 750: + successors.append(['FORWARD', State(st, st.xpos + 50, st.ypos, 'E')]) return successors