Inteligentna_smieciarka/succ.py
2023-04-21 14:31:17 +02:00

31 lines
1.3 KiB
Python

from state import State
FIELDWIDTH, FIELDCOUNT = 50, 16
def succ(st: State):
successors = []
if st.orientation == 'N':
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(State(st, 'FORWARD', st.xpos, st.ypos - FIELDWIDTH , 'N'))
if st.orientation == 'S':
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'E'))
successors.append(State(st,'RIGHT', st.xpos, st.ypos, 'W'))
if st.ypos < FIELDWIDTH * (FIELDCOUNT - 1):
successors.append(State(st, 'FORWARD', st.xpos, st.ypos + FIELDWIDTH , 'S'))
if st.orientation == 'W':
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(State(st, 'FORWARD', st.xpos - FIELDWIDTH , st.ypos, 'W'))
if st.orientation == 'E':
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 'N'))
successors.append(State(st, 'RIGHT', st.xpos, st.ypos, 'S'))
if st.xpos < FIELDWIDTH * (FIELDCOUNT - 1):
successors.append(State(st, 'FORWARD', st.xpos + FIELDWIDTH , st.ypos, 'E'))
return successors