added state class

This commit is contained in:
Mateusz 2023-04-19 21:40:40 +02:00
parent 1e88149789
commit c91e016294
2 changed files with 29 additions and 21 deletions

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 = []
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