Inteligentna_smieciarka/succ.py

32 lines
2.4 KiB
Python
Raw Normal View History

2023-04-19 21:40:40 +02:00
from state import State
from heuristicfn import heuristicfn
2023-04-21 14:31:17 +02:00
FIELDWIDTH, FIELDCOUNT = 50, 16
2023-04-19 21:40:40 +02:00
def succ(st: State, passedPriorities, goalx, goaly):
successors = []
2023-05-26 19:08:22 +02:00
if st.orientation == 3:
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 2, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
successors.append(State(st, 'RIGHT', st.xpos, st.ypos, 0, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
2023-04-19 21:40:40 +02:00
if st.ypos > 0:
2023-05-26 19:08:22 +02:00
successors.append(State(st, 'FORWARD', st.xpos, st.ypos - FIELDWIDTH , 3, passedPriorities[st.xpos//50][st.ypos//50 - 1], heuristicfn(st.xpos, st.ypos - 50, goalx, goaly)))
2023-05-26 19:08:22 +02:00
if st.orientation == 1:
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 0, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
successors.append(State(st,'RIGHT', st.xpos, st.ypos, 2, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
2023-04-21 14:31:17 +02:00
if st.ypos < FIELDWIDTH * (FIELDCOUNT - 1):
2023-05-26 19:08:22 +02:00
successors.append(State(st, 'FORWARD', st.xpos, st.ypos + FIELDWIDTH , 1, passedPriorities[st.xpos//50][st.ypos//50 + 1], heuristicfn(st.xpos, st.ypos + 50, goalx, goaly)))
2023-05-26 19:08:22 +02:00
if st.orientation == 2:
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 1, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
successors.append(State(st,'RIGHT', st.xpos, st.ypos, 3, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
2023-04-19 21:40:40 +02:00
if st.xpos > 0:
2023-05-26 19:08:22 +02:00
successors.append(State(st, 'FORWARD', st.xpos - FIELDWIDTH , st.ypos, 2, passedPriorities[st.xpos//50 - 1][st.ypos//50], heuristicfn(st.xpos - 50, st.ypos, goalx, goaly)))
2023-05-26 19:08:22 +02:00
if st.orientation == 0:
successors.append(State(st, 'LEFT', st.xpos, st.ypos, 3, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
successors.append(State(st, 'RIGHT', st.xpos, st.ypos, 1, passedPriorities[st.xpos//50][st.ypos//50], heuristicfn(st.xpos, st.ypos, goalx, goaly)))
2023-04-21 14:31:17 +02:00
if st.xpos < FIELDWIDTH * (FIELDCOUNT - 1):
2023-05-26 19:08:22 +02:00
successors.append(State(st, 'FORWARD', st.xpos + FIELDWIDTH , st.ypos, 0, passedPriorities[st.xpos//50 + 1][st.ypos//50], heuristicfn(st.xpos + 50, st.ypos, goalx, goaly)))
return successors