def nxtState(act): #return the next position model = findModel(act) #print(model) for st in model: if model[st] and logic.parseExpr(st)[0] == 'P': return (logic.parseExpr(st)[1]) return None
def extractActionSequence(model, actions): """ Convert a model in to an ordered list of actions. model: Propositional logic model stored as a dictionary with keys being the symbol strings and values being Boolean: True or False Example: >>> model = {"North[2]":True, "P[3,4,0]":True, "P[3,3,0]":False, "West[0]":True, "GhostScary":True, "West[2]":False, "South[1]":True, "East[0]":False} >>> actions = ['North', 'South', 'East', 'West'] >>> plan = extractActionSequence(model, actions) >>> print(plan) ['West', 'South', 'North'] """ plan = [None for _ in range(len(model))] for sym, val in model.items(): parsed = parseExpr(sym) if type(parsed) == tuple and parsed[0] in actions and val: action, time = parsed plan[int(time)] = action #return list(filter(lambda x: x is not None, plan)) return [x for x in plan if x is not None]
def extractActionSequence(model, actions): """ Convert a model in to an ordered list of actions. model: Propositional logic model stored as a dictionary with keys being the symbol strings and values being Boolean: True or False Example: >>> model = {"North[2]":True, "P[3,4,0]":True, "P[3,3,0]":False, "West[0]":True, "GhostScary":True, "West[2]":False, "South[1]":True, "East[0]":False} >>> actions = ['North', 'South', 'East', 'West'] >>> plan = extractActionSequence(model, actions) >>> print(plan) ['West', 'South', 'North'] """ "*** YOUR CODE HERE ***" final = dict() for k in model: str, idx = logic.parseExpr(k) if model[k] and str in actions: final.update({idx: str}) res = [] for key in sorted(final.keys()): res.append(final[key]) return res