feat: q5
This commit is contained in:
parent
a5c3673356
commit
55a06a32c4
37
logicPlan.py
37
logicPlan.py
@ -407,7 +407,9 @@ def positionLogicPlan(problem) -> List:
|
||||
KB = []
|
||||
|
||||
"*** BEGIN YOUR CODE HERE ***"
|
||||
# Initialize pacman loc
|
||||
KB.append(PropSymbolExpr(pacman_str, x0, y0, time=0))
|
||||
|
||||
for step in range(50):
|
||||
print(f"step={step}")
|
||||
|
||||
@ -453,7 +455,40 @@ def foodLogicPlan(problem) -> List:
|
||||
KB = []
|
||||
|
||||
"*** BEGIN YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
# Initialize pacman loc
|
||||
KB.append(PropSymbolExpr(pacman_str, x0, y0, time=0))
|
||||
|
||||
# Initialize Food[x,y]_t variables
|
||||
KB += [ PropSymbolExpr(food_str, loc[0], loc[1], time=0) for loc in food ]
|
||||
|
||||
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
|
||||
# Q5: your goal assertion sentence must be true if and only if all of the food have been eaten
|
||||
model = findModel( logic.conjoin(KB + [ ~PropSymbolExpr(food_str, loc[0], loc[1], time=step) for loc in food ]) )
|
||||
if model:
|
||||
print("HERE")
|
||||
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) for loc in non_wall_coords ]
|
||||
|
||||
# KB: food successor axiom
|
||||
for loc in food:
|
||||
x, y = loc
|
||||
|
||||
# if pacman eat food (pacman's location == food's location) => food disapear (~food)
|
||||
KB.append( (PropSymbolExpr(pacman_str, x, y, time=step) & PropSymbolExpr(food_str, x, y, time=step)) >> ~PropSymbolExpr(food_str, x, y, time=step+1) )
|
||||
|
||||
# if pacman doesn't eat food (pacman's location != food's location) => food no any change
|
||||
KB.append( (~PropSymbolExpr(pacman_str, x, y, time=step) & PropSymbolExpr(food_str, x, y, time=step)) >> PropSymbolExpr(food_str, x, y, time=step+1))
|
||||
"*** END YOUR CODE HERE ***"
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user