def isEnded(self): dead = False won = False # Has Link met the Wumpus? for i in range(len(self.wLoc)): if utils.sameLocation(self.lLoc, self.wLoc[i]): print("Oops! Met the Wumpus :( ") dead = True self.status = State.LOST # Did Link fall in a Pit? for i in range(len(self.pLoc)): if utils.sameLocation(self.lLoc, self.pLoc[i]): print("Arghhhhh! Fell in a pit") dead = True self.status = State.LOST # Did Link loot all the gold? if len(self.gLoc) == 0: won = True self.status = State.WON if dead == True or won == True: print("Game Over!!!") return True
def isEnded(self): dead = False won = False # Has Link met the Wumpus? -iterates through every single wumpus then check if they're at the same location for i in range(len(self.wLoc)): if utils.sameLocation(self.lLoc, self.wLoc[i]): print("Oops! Met the Wumpus") dead = True self.status = State.LOST # Did Link fall in a Pit? for i in range(len(self.pLoc)): if utils.sameLocation(self.lLoc, self.pLoc[i]): print("Arghhhhh! Fell in a pit") dead = True self.status = State.LOST # Did Link loot all the gold? if len(self.gLoc) == 0: won = True self.status = State.WON if dead == True or won == True: print("Game Over!") return True
def updateLink(self, direction): # Set the looted flag to False self.looted = False # Implement non-determinism if appropriate direction = self.probabilisticMotion(direction) if direction == Directions.NORTH: if self.lLoc.y < self.maxY: self.lLoc.y = self.lLoc.y + 1 if direction == Directions.SOUTH: if self.lLoc.y > 0: self.lLoc.y = self.lLoc.y - 1 if direction == Directions.EAST: if self.lLoc.x < self.maxX: self.lLoc.x = self.lLoc.x + 1 if direction == Directions.WEST: if self.lLoc.x > 0: self.lLoc.x = self.lLoc.x - 1 # Did Link just loot some gold? match = False index = 0 for i in range(len(self.gLoc)): if utils.sameLocation(self.lLoc, self.gLoc[i]): match = True index = i self.looted = True print("Gold, yeah!") # Assumes that golds have different locations. Or, that only # one gold can be picked up in a given turn. if match: self.gLoc.pop(index)