movement_planning #2

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

15
bfs.py Normal file
View File

@ -0,0 +1,15 @@
from succ import succ as successors
def bfs(istate, goalstate):
fringe = [istate]
explored = []
while(fringe):
state = fringe.pop(0)
if state == goalstate :
return
element = successors(state)
explored.append(state)
for value in element :
if value not in explored :
fringe.append(value)
return False

View File

@ -1,6 +1,7 @@
class State:
def __init__(self, parent, xpos, ypos, orientation):
def __init__(self, parent, action, xpos, ypos, orientation):
self.parent = parent
self.xpos = xpos
self.ypos = ypos
self.orientation = orientation
self.action = action

24
succ.py
View File

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