logic q4
This commit is contained in:
@ -362,9 +362,30 @@ def positionLogicPlan(problem) -> List:
|
||||
actions = [ 'North', 'South', 'East', 'West' ]
|
||||
KB = []
|
||||
|
||||
"*** BEGIN YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
"*** END YOUR CODE HERE ***"
|
||||
# Initial position at time 0
|
||||
KB.append(PropSymbolExpr(pacman_str, x0, y0, time=0))
|
||||
|
||||
for t in range(50):
|
||||
# Pacman is at exactly one non-wall position at time t
|
||||
pacman_positions = [PropSymbolExpr(pacman_str, x, y, time=t) for x, y in non_wall_coords]
|
||||
KB.append(exactlyOne(pacman_positions))
|
||||
|
||||
# Pacman takes exactly one action at time t
|
||||
action_symbols = [PropSymbolExpr(action, time=t) for action in actions]
|
||||
KB.append(exactlyOne(action_symbols))
|
||||
|
||||
if t > 0:
|
||||
# Add transition models for each non-wall coordinate
|
||||
for x, y in non_wall_coords:
|
||||
KB.append(pacmanSuccessorAxiomSingle(x, y, t, walls_grid))
|
||||
|
||||
# Check if Pacman is at the goal position at time t
|
||||
goal_expr = PropSymbolExpr(pacman_str, xg, yg, time=t)
|
||||
model = findModel(conjoin(KB + [goal_expr]))
|
||||
if model:
|
||||
return extractActionSequence(model, actions)
|
||||
|
||||
return []
|
||||
|
||||
#______________________________________________________________________________
|
||||
# QUESTION 5
|
||||
|
Reference in New Issue
Block a user