Exemple #1
0
    def test_walk_north_into_new_room(self):

        maze = Maze()
        start_room = Room((1, 2), EXITS[SOUTH])
        maze.add_room(start_room)
        end_room = Room((0, 2), EXITS[SOUTH])
        walker = Walker(start_room, NORTH)

        walk = Walk(walker, maze)
        walk.move()

        self.assertEqual(walker.direction, NORTH)
        self.assertEqual(walker.room, end_room)
        self.assertEqual(maze.has_room(end_room.vector), True)
        self.assertEqual(maze.rooms[end_room.vector], end_room)
        self.assertEqual(maze.rooms[start_room.vector].exits, 3)
Exemple #2
0
    def test_walk_west_into_new_room(self):

        maze = Maze()
        start_room = Room((0, 0), EXITS[NORTH])
        maze.add_room(start_room)
        end_room = Room((0, 1), EXITS[EAST])
        walker = Walker(start_room, WEST)

        walk = Walk(walker, maze)
        walk.move()

        self.assertEqual(walker.direction, WEST)
        self.assertEqual(walker.room, end_room)
        self.assertEqual(maze.has_room(end_room.vector), True)
        self.assertEqual(maze.rooms[end_room.vector], end_room)
        self.assertEqual(maze.rooms[start_room.vector].exits, 5)
Exemple #3
0
    def test_walk_back_west_into_known_room_through_known_entrance(self):
        known_exits = 12
        start_room = Room((1, 1), EXITS[WEST])
        end_room = Room((1, 2), known_exits)
        maze = Maze()
        maze.add_room(start_room)
        maze.add_room(end_room)
        walker = Walker(start_room, WEST)

        walk = Walk(walker, maze)
        walk.move()

        self.assertEqual(walker.direction, WEST)
        self.assertEqual(walker.room, end_room)
        self.assertEqual(maze.rooms[start_room.vector].exits, EXITS[WEST])
        self.assertEqual(maze.rooms[end_room.vector].exits, known_exits)
Exemple #4
0
    def test_walk_back_north_into_known_room_through_known_entrance(self):
        known_exits = 3
        start_room = Room((1, 0), EXITS[NORTH])
        end_room = Room((0, 0), known_exits)
        maze = Maze()
        maze.add_room(start_room)
        maze.add_room(end_room)
        walker = Walker(start_room, NORTH)

        walk = Walk(walker, maze)
        walk.move()

        self.assertEqual(walker.direction, NORTH)
        self.assertEqual(walker.room, end_room)
        self.assertEqual(maze.rooms[start_room.vector].exits, EXITS[NORTH])
        self.assertEqual(maze.rooms[end_room.vector].exits, known_exits)
Exemple #5
0
    def test_walk_back_east_into_known_room_through_new_entrance(self):
        previously_known_exits = EXITS[EAST]
        now_known_exits = 12
        start_room = Room((1, 1), EXITS[EAST])
        end_room = Room((1, 0), previously_known_exits)
        maze = Maze()
        maze.add_room(start_room)
        maze.add_room(end_room)
        walker = Walker(start_room, EAST)

        walk = Walk(walker, maze)
        walk.move()

        self.assertEqual(walker.direction, EAST)
        self.assertEqual(walker.room, end_room)
        self.assertEqual(maze.rooms[start_room.vector].exits, EXITS[EAST])
        self.assertEqual(maze.rooms[end_room.vector].exits, now_known_exits)
 def __walk_path(self, path, is_reentering = False):
     
     char_index = 0
     path_length = len(path)
     commands = MazeBuilder.command
             
     for character in list(path):
         movement = None
         if char_index == 0 and character == commands['FORWARD']:
             movement = Reenter(self.walker, self.maze) if is_reentering else Enter(self.walker, self.maze)
         elif char_index == (path_length - 1) and character == commands['FORWARD']:
             movement = Exit(self.walker, self.maze)
         elif character == commands['LEFT']:
             movement = TurnLeft(self.walker)
         elif character == commands['RIGHT']:
             movement = TurnRight(self.walker)
         elif character == commands['FORWARD']:
             movement = Walk(self.walker, self.maze)
         else:
             raise RuntimeError("Unexpected character found in path. Value is '{0}'.".format(character))
         movement.move()
         char_index += 1