示例#1
0
文件: testpath.py 项目: agrue/rlfl
 def test_path_basic(self):
     p, p1, p2, p3, p4, p5, p6, p7, p8, p9 = TORIGOS
     path = rlfl.path(self.map, p1, p4)
     self.assertEqual(len(path), 2)
     path = rlfl.path(self.map, p1, p4, rlfl.PATH_BASIC, -1,
                      rlfl.PROJECT_THRU)
     self.assertEqual(len(path), 20)
示例#2
0
    def show(self):
        # Start by creating a map on which to work
        # We shall import a dummy map to use

        # Import the map
        import tmap
        self.map, self.origos = tmap.MAP
        p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 = self.origos

        # Create the RLFL internal map
        width = len(self.map)
        height = len(self.map[0])
        self.map_number = rlfl.create_map(width, height)

        # We now have a map number representing the
        # internal map in rlfl

        # initialize the map
        for row in range(len(self.map)):
            for col in range(len(self.map[row])):
                if self.map[row][col] != '#':
                    p = (row, col)

                    # Set non-wall grids as open and seen
                    rlfl.set_flag(self.map_number, p, rlfl.CELL_SEEN)
                    rlfl.set_flag(self.map_number, p, rlfl.CELL_OPEN)

        # we now have a map to work on
        # LOS between 1 and 4 on the map above
        have_los = rlfl.los(self.map_number, p1, p2)
        assert (have_los == False)
        # LOS between 2 and 3
        have_los = rlfl.los(self.map_number, p2, p3)
        assert (have_los == True)

        # Measure distance
        dist = rlfl.distance(p1, p4)

        # Plot simple paths
        flags = 0
        # range (-1 for max range)
        r = -1
        path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_BASIC, r, flags,
                         0.0)

        # Or real path A*
        path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_ASTAR, r, flags,
                         7.0)

        # Lets calculate FOV from 3 using recursive shadowcasting
        # with a light source radius of 6
        rlfl.fov(self.map_number, p3, rlfl.FOV_SHADOW, 6)
        self.print_map(p3)

        # Use the scatter function to find a random spot (summon, teleport)
        # Here we want an open cell within range 16 from p
        require_los = False
        ps = rlfl.scatter(self.map_number, p0, 16, rlfl.CELL_OPEN, require_los)
        super(Full_example, self).print_map([], p0, ps)
示例#3
0
 def show(self):
     # Start by creating a map on which to work
     # We shall import a dummy map to use
     
     # Import the map
     import tmap
     self.map, self.origos = tmap.MAP
     p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 = self.origos
     
     # Create the RLFL internal map
     width = len(self.map)
     height = len(self.map[0])
     self.map_number = rlfl.create_map(width, height)
     
     # We now have a map number representing the 
     # internal map in rlfl
     
     # initialize the map
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if self.map[row][col] != '#':
                 p = (row, col)
                 
                 # Set non-wall grids as open and seen
                 rlfl.set_flag(self.map_number, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(self.map_number, p, rlfl.CELL_OPEN)
                 
     # we now have a map to work on
     # LOS between 1 and 4 on the map above
     have_los = rlfl.los(self.map_number, p1, p2)
     assert(have_los == False)
     # LOS between 2 and 3
     have_los = rlfl.los(self.map_number, p2, p3)
     assert(have_los == True)
     
     # Measure distance
     dist = rlfl.distance(p1, p4)
     
     # Plot simple paths
     flags = 0
     # range (-1 for max range)
     r = -1 
     path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_BASIC, r, flags, 0.0)
     
     # Or real path A*
     path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_ASTAR, r, flags, 7.0)
     
     # Lets calculate FOV from 3 using recursive shadowcasting
     # with a light source radius of 6
     rlfl.fov(self.map_number, p3, rlfl.FOV_SHADOW, 6)
     self.print_map(p3) 
     
     # Use the scatter function to find a random spot (summon, teleport)
     # Here we want an open cell within range 16 from p
     require_los = False
     ps = rlfl.scatter(self.map_number, p0, 16, rlfl.CELL_OPEN, require_los)
     super(Full_example, self).print_map([], p0, ps)
示例#4
0
 def test_input(self):
     test = (
         {"p": (10, 10), "p1": (10, 10), "m": -1, "s": "Map not initialized"},
         {"p": (-1, -1), "p1": (10, 10), "m": self.map, "s": "Location out of bounds"},
         {"p1": (-1, -1), "p": (10, 10), "m": self.map, "s": "Location out of bounds"},
         {"p1": (-1, -1), "p": (-1, -1), "m": self.map, "s": "Location out of bounds"},
     )
     for a in [rlfl.PATH_BASIC, rlfl.PATH_ASTAR]:
         for i in test:
             try:
                 rlfl.path(i["m"], i["p"], i["p1"], a, i["m"], 0, 0.0)
             except Exception as e:
                 self.assertEqual(str(e), i["s"])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail("Expected Exception: %s" % (i["s"]))
示例#5
0
文件: testpath.py 项目: agrue/rlfl
 def test_input(self):
     test = (
         {
             'p': (10, 10),
             'p1': (10, 10),
             'm': -1,
             's': 'Map not initialized',
         },
         {
             'p': (-1, -1),
             'p1': (10, 10),
             'm': self.map,
             's': 'Location out of bounds',
         },
         {
             'p1': (-1, -1),
             'p': (10, 10),
             'm': self.map,
             's': 'Location out of bounds',
         },
         {
             'p1': (-1, -1),
             'p': (-1, -1),
             'm': self.map,
             's': 'Location out of bounds',
         },
     )
     for a in [rlfl.PATH_BASIC, rlfl.PATH_ASTAR]:
         for i in test:
             try:
                 rlfl.path(i['m'], i['p'], i['p1'], a, i['m'], 0, 0.0)
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: %s' % (i['s']))
示例#6
0
文件: testpath.py 项目: agrue/rlfl
 def test_input(self):
     test = (
         {
             'p': (10, 10),
             'p1': (10, 10),
             'm': -1,
             's': 'Map not initialized',
         },
         {
             'p': (-1, -1),
             'p1': (10, 10),
             'm': self.map,
             's': 'Location out of bounds',
         },
         {
             'p1': (-1, -1),
             'p': (10, 10),
             'm': self.map,
             's': 'Location out of bounds',
         },
         {
             'p1': (-1, -1),
             'p': (-1, -1),
             'm': self.map,
             's': 'Location out of bounds',
         },
     )
     for a in [rlfl.PATH_BASIC, rlfl.PATH_ASTAR]:
         for i in test:
             try:
                 rlfl.path(i['m'], i['p'], i['p1'], a, i['m'], 0, 0.0)
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: %s' % (i['s']))
示例#7
0
 def test_path_astar(self):
     p, p1, p2, p3, p4, p5, p6, p7, p8, p9 = TORIGOS
     path = rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertEqual(len(path), 16)
     diagonal_path = rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0, 0.0)
     self.assertEqual(len(path), 16)
     self.assertEqual(path, diagonal_path)
     path = rlfl.path(self.map, p2, p4, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertFalse(path)
     path = rlfl.path(self.map, p2, p3, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertEqual(len(path), 6)
     diagonal_path = rlfl.path(self.map, p2, p3, rlfl.PATH_ASTAR, -1, 0, 0.0)
     self.assertEqual(diagonal_path, ((15, 11), (15, 10), (14, 9), (15, 8), (14, 7), (15, 6)))
     self.assertNotEqual(path, diagonal_path)
     rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0, -100.0)
示例#8
0
文件: testpath.py 项目: agrue/rlfl
 def test_path_astar(self):
     p, p1, p2, p3, p4, p5, p6, p7, p8, p9 = TORIGOS
     path = rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertEqual(len(path), 16)
     diagonal_path = rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0,
                               0.0)
     self.assertEqual(len(path), 16)
     self.assertEqual(path, diagonal_path)
     path = rlfl.path(self.map, p2, p4, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertFalse(path)
     path = rlfl.path(self.map, p2, p3, rlfl.PATH_ASTAR, -1, 0, 10.0)
     self.assertEqual(len(path), 6)
     diagonal_path = rlfl.path(self.map, p2, p3, rlfl.PATH_ASTAR, -1, 0,
                               0.0)
     self.assertEqual(diagonal_path, ((15, 11), (15, 10), (14, 9), (15, 8),
                                      (14, 7), (15, 6)))
     self.assertNotEqual(path, diagonal_path)
     rlfl.path(self.map, p1, p4, rlfl.PATH_ASTAR, -1, 0, -100.0)
示例#9
0
    def show_path(self, p1, p2, type, m, r=30, flags=0, diagonal=1.0):
        # Import the map
        imap = __import__(m)
        self.map, origos = imap.MAP

        # Create the RLFL internal map
        mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
        for row in range(len(self.map)):
            for col in range(len(self.map[row])):
                if self.map[row][col] != '#':
                    p = (row, col)
                    # Set non-wall grids as open and seen
                    rlfl.set_flag(mapnum, p, rlfl.CELL_SEEN)
                    rlfl.set_flag(mapnum, p, rlfl.CELL_OPEN)

        # Fetch points to path
        p1, p2 = (origos[p1], origos[p2])

        # Create the path
        path = rlfl.path(mapnum, p1, p2, type, r, flags, diagonal)

        # Print the path
        self.print_map(path, p1, p2)
示例#10
0
 def show_path(self, p1, p2, type, m, r=30, flags=0, diagonal=1.0):
     # Import the map
     imap = __import__(m)
     self.map, origos = imap.MAP
     
     # Create the RLFL internal map
     mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if self.map[row][col] != '#':
                 p = (row, col)
                 # Set non-wall grids as open and seen
                 rlfl.set_flag(mapnum, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(mapnum, p, rlfl.CELL_OPEN)
                 
     # Fetch points to path
     p1, p2 = (origos[p1], origos[p2])    
     
     # Create the path
     path = rlfl.path(mapnum, p1, p2, type, r, flags, diagonal)
     
     # Print the path
     self.print_map(path, p1, p2) 
示例#11
0
文件: testpath.py 项目: agrue/rlfl
 def test_path_basic(self):
     p, p1, p2, p3, p4, p5, p6, p7, p8, p9 = TORIGOS
     path = rlfl.path(self.map, p1, p4)
     self.assertEqual(len(path), 2)
     path = rlfl.path(self.map, p1, p4, rlfl.PATH_BASIC, -1, rlfl.PROJECT_THRU)
     self.assertEqual(len(path), 20)
示例#12
0
def create_path(fov_map, x, y, tx, ty):
    return rlfl.path(fov_map, (x, y), (tx, ty), rlfl.PATH_BASIC)