def _dispatch_branch_change_event(self): level = [line.translate(ibm) for line in self.term.display] if 6 <= self.dlvl <= 10 and dungeon.looks_like_sokoban(level): # If the player arrived at a level that looks like sokoban, she's # definitely in sokoban. event.dispatch("branch-change", "sokoban") elif self.last_move == "down" and 3 <= self.dlvl <= 6 and \ dungeon.looks_like_mines(level): # The only entrace to the mines is between levels 3 and 5 and # the player has to have been traveling down to get there. Also # count it if the dlvl didn't change, because it *might* take # a couple turns to identify the mines. Sokoban, by it's nature # however is instantly identifiable. event.dispatch("branch-change", "mines")
def _branch_change_event(self, data): level = [line.translate(ibm) for line in self.term.display] if 6 <= self.dlvl <= 10 and dungeon.looks_like_sokoban(level): # If the player arrived at a level that looks like sokoban, she's # definitely in sokoban. self.events.dispatch("branch-changed", "sokoban") elif self.last_move == "down" and 3 <= self.dlvl <= 6 and \ dungeon.looks_like_mines(level): # The only entrace to the mines is between levels 3 and 5 and # the player has to have been traveling down to get there. Also # count it if the dlvl didn't change, because it *might* take # a couple turns to identify the mines. Sokoban, by it's nature # however is instantly identifiable. self.events.dispatch("branch-changed", "mines")
def test_sokoban_a(): display = [ "-------- ------", "|<|@..=---....|", "|^|-.00....0..|", "|^||..00|.0.0.|", "|^||....|.....|", "|^|------0----|", "|^| |......|", "|^------......|", "|..^^^^0000...|", "|..-----......|", "---- --------", ] assert looks_like_sokoban(display)
def test_sokoban_b(): display = [ "------ ----- ", "|....| |...| ", "|.0..----.0.| ", "|.0......0..| ", "|..--->---0.| ", "|---------.---", "|..^^^<|.....|", "|..----|0....|", "--^| |.0...|", " |^-----.0...|", " |..^^^^0.0..|", " |??----------", " ---- ", ] assert looks_like_sokoban(display)