2023-04-19 21:40:40 +02:00
|
|
|
from state import State
|
2023-04-21 14:31:17 +02:00
|
|
|
FIELDWIDTH, FIELDCOUNT = 50, 16
|
2023-04-19 21:40:40 +02:00
|
|
|
|
|
|
|
def succ(st: State):
|
2023-04-19 21:16:40 +02:00
|
|
|
successors = []
|
|
|
|
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.orientation == 'N':
|
2023-04-19 22:12:02 +02:00
|
|
|
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'W'))
|
|
|
|
successors.append(State(st, 'RIGHT', st.xpos, st.ypos, 'E'))
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.ypos > 0:
|
2023-04-21 14:31:17 +02:00
|
|
|
successors.append(State(st, 'FORWARD', st.xpos, st.ypos - FIELDWIDTH , 'N'))
|
2023-04-19 21:16:40 +02:00
|
|
|
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.orientation == 'S':
|
2023-04-19 22:12:02 +02:00
|
|
|
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'E'))
|
|
|
|
successors.append(State(st,'RIGHT', st.xpos, st.ypos, 'W'))
|
2023-04-21 14:31:17 +02:00
|
|
|
if st.ypos < FIELDWIDTH * (FIELDCOUNT - 1):
|
|
|
|
successors.append(State(st, 'FORWARD', st.xpos, st.ypos + FIELDWIDTH , 'S'))
|
2023-04-19 21:16:40 +02:00
|
|
|
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.orientation == 'W':
|
2023-04-19 22:12:02 +02:00
|
|
|
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'S'))
|
|
|
|
successors.append(State(st,'RIGHT', st.xpos, st.ypos, 'N'))
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.xpos > 0:
|
2023-04-21 14:31:17 +02:00
|
|
|
successors.append(State(st, 'FORWARD', st.xpos - FIELDWIDTH , st.ypos, 'W'))
|
2023-04-19 21:16:40 +02:00
|
|
|
|
2023-04-19 21:40:40 +02:00
|
|
|
if st.orientation == 'E':
|
2023-04-19 22:12:02 +02:00
|
|
|
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'N'))
|
|
|
|
successors.append(State(st, 'RIGHT', st.xpos, st.ypos, 'S'))
|
2023-04-21 14:31:17 +02:00
|
|
|
if st.xpos < FIELDWIDTH * (FIELDCOUNT - 1):
|
|
|
|
successors.append(State(st, 'FORWARD', st.xpos + FIELDWIDTH , st.ypos, 'E'))
|
2023-04-19 21:16:40 +02:00
|
|
|
return successors
|