From 55a06a32c4ddf0b2698897e892a24ac72702e02c Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Tue, 23 Apr 2024 15:26:24 +0800 Subject: [PATCH] feat: q5 --- logicPlan.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/logicPlan.py b/logicPlan.py index 9b3b795..62b3d9c 100644 --- a/logicPlan.py +++ b/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 ***"