This commit is contained in:
snsd0805 2024-04-23 03:02:25 +08:00
parent b396766976
commit a5c3673356
Signed by: snsd0805
GPG Key ID: 569349933C77A854

View File

@ -407,7 +407,24 @@ def positionLogicPlan(problem) -> List:
KB = []
"*** BEGIN YOUR CODE HERE ***"
util.raiseNotDefined()
KB.append(PropSymbolExpr(pacman_str, x0, y0, time=0))
for step in range(50):
print(f"step={step}")
# KB: Pacman can only be at exactlyOne of the locations in non_wall_coords at timestep t (from docs)
KB.append(exactlyOne([ PropSymbolExpr(pacman_str, loc[0], loc[1], time=step) for loc in non_wall_coords ]))
# goal
model = findModel( logic.conjoin(KB) & PropSymbolExpr(pacman_str, xg, yg, time=step) )
if model:
return extractActionSequence(model, actions)
# KB: Pacman takes exactly one action per timestep.
KB.append(exactlyOne([ PropSymbolExpr(action, time=step) for action in actions ]))
# KB: Transition Model sentences: call pacmanSuccessorAxiomSingle(...) for all possible pacman positions in non_wall_coords
KB += [ pacmanSuccessorAxiomSingle(loc[0], loc[1], step+1, walls_grid) for loc in non_wall_coords ]
"*** END YOUR CODE HERE ***"
#______________________________________________________________________________