From b39676697627be718e16c089e96420ade66d8d63 Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Tue, 23 Apr 2024 02:04:28 +0800 Subject: [PATCH] feat: q3 --- logicPlan.py | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/logicPlan.py b/logicPlan.py index 4e5552d..68083ee 100644 --- a/logicPlan.py +++ b/logicPlan.py @@ -235,7 +235,7 @@ def pacmanSuccessorAxiomSingle(x: int, y: int, time: int, walls_grid: List[List[ return None "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() + return PropSymbolExpr(pacman_str, x, y, time=now) % logic.disjoin(possible_causes) "*** END YOUR CODE HERE ***" @@ -306,7 +306,37 @@ def pacphysicsAxioms(t: int, all_coords: List[Tuple], non_outer_wall_coords: Lis pacphysics_sentences = [] "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() + # condition 1: + # if a wall is at (x, y) --> pacman is not at (x, y) + pacphysics_sentences = [ + PropSymbolExpr(wall_str, loc[0], loc[1]) >> ~logic.PropSymbolExpr(pacman_str, loc[0], loc[1], time=t) # time=t ? + for loc in all_coords + ] + + # condition 2: + # pacman is at exatly one of the squares at timestamp t. + condition2 = exactlyOne([ logic.PropSymbolExpr(pacman_str, loc[0], loc[1], time=t) for loc in non_outer_wall_coords ]) + pacphysics_sentences.append(condition2) + + + # condition 3: + # pacman takes exactly one action at timestep t. + condition3 = exactlyOne([ logic.PropSymbolExpr(action, time=t) for action in DIRECTIONS]) + pacphysics_sentences.append(condition3) + + + ## condition 4 + # results of calling sensorModel(...), unless None + if sensorModel: + pacphysics_sentences.append(sensorModel(t, non_outer_wall_coords)) + + # condition 5 + # result of calling successorAxioms(...), describing how pacman can end in various locations on this time step. consider edge case. dont call if None + if successorAxioms and walls_grid and t>0: + pacphysics_sentences.append(successorAxioms(t, walls_grid, non_outer_wall_coords)) + + + "*** END YOUR CODE HERE ***" return conjoin(pacphysics_sentences) @@ -340,7 +370,17 @@ def checkLocationSatisfiability(x1_y1: Tuple[int, int], x0_y0: Tuple[int, int], KB.append(conjoin(map_sent)) "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() + KB.append(pacphysicsAxioms(0, all_coords, non_outer_wall_coords, walls_grid, None, allLegalSuccessorAxioms)) + KB.append(pacphysicsAxioms(1, all_coords, non_outer_wall_coords, walls_grid, None, allLegalSuccessorAxioms)) + + KB.append(PropSymbolExpr(pacman_str, x0, y0, time=0)) + KB.append(PropSymbolExpr(action0, time=0)) + KB.append(PropSymbolExpr(action1, time=1)) + + model1 = findModel( logic.conjoin(KB) & PropSymbolExpr(pacman_str, x1, y1, time=1) ) + model2 = findModel( logic.conjoin(KB) & ~PropSymbolExpr(pacman_str, x1, y1, time=1) ) + return (model1, model2) + "*** END YOUR CODE HERE ***" #______________________________________________________________________________