movement_planning #2

Merged
s473585 merged 13 commits from movement_planning into master 2023-05-24 14:28:17 +02:00
2 changed files with 29 additions and 21 deletions
Showing only changes of commit c91e016294 - Show all commits

6
state.py Normal file
View File

@ -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

44
succ.py
View File

@ -1,28 +1,30 @@
def succ(xpos, ypos, orientation): from state import State
def succ(st: State):
successors = [] successors = []
if orientation == 'N': if st.orientation == 'N':
successors.append(['LEFT', xpos, ypos, 'W']) successors.append(['LEFT', State(st, st.xpos, st.ypos, 'W')])
successors.append(['RIGHT', xpos, ypos, 'E']) successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'E')])
if ypos > 0: if st.ypos > 0:
successors.append(['FORWARD', xpos, ypos - 50, 'N']) successors.append(['FORWARD', State(st, st.xpos, st.ypos - 50, 'N')])
if orientation == 'S': if st.orientation == 'S':
successors.append(['LEFT', xpos, ypos, 'E']) successors.append(['LEFT', State(st, st.xpos, st.ypos, 'E')])
successors.append(['RIGHT', xpos, ypos, 'W']) successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'W')])
if ypos < 750: if st.ypos < 750:
successors.append(['FORWARD', xpos, ypos + 50, 'S']) successors.append(['FORWARD', State(st, st.xpos, st.ypos + 50, 'S')])
if orientation == 'W': if st.orientation == 'W':
successors.append(['LEFT', xpos, ypos, 'S']) successors.append(['LEFT', State(st, st.xpos, st.ypos, 'S')])
successors.append(['RIGHT', xpos, ypos, 'N']) successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'N')])
if xpos > 0: if st.xpos > 0:
successors.append(['FORWARD', xpos - 50, ypos, 'W']) successors.append(['FORWARD', State(st, st.xpos - 50, st.ypos, 'W')])
if orientation == 'E': if st.orientation == 'E':
successors.append(['LEFT',xpos, ypos, 'N']) successors.append(['LEFT', State(st, st.xpos, st.ypos, 'N')])
successors.append(['RIGHT', xpos, ypos, 'S']) successors.append(['RIGHT', State(st, st.xpos, st.ypos, 'S')])
if xpos < 750: if st.xpos < 750:
successors.append(['FORWARD', xpos + 50, ypos, 'E']) successors.append(['FORWARD', State(st, st.xpos + 50, st.ypos, 'E')])
return successors return successors