added state class
This commit is contained in:
parent
1e88149789
commit
c91e016294
6
state.py
Normal file
6
state.py
Normal 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
44
succ.py
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user