Example #1
0
 def test_delete(self):
     for m in range(rlfl.MAX_MAPS):
         rlfl.create_map(20, 20)
     rlfl.delete_all_maps()
     self.assertEqual(0, rlfl.create_map(20, 20))
     self.assertTrue(rlfl.delete_map(0))
     self.assertEqual(0, rlfl.create_map(20, 20))
     self.assertTrue(rlfl.delete_map(0))
     self.assertFalse(rlfl.delete_map(0))
     self.assertFalse(rlfl.delete_map(-1))
Example #2
0
 def test_delete(self):
     for m in range(rlfl.MAX_MAPS):
         rlfl.create_map(20, 20)
     rlfl.delete_all_maps()
     self.assertEqual(0, rlfl.create_map(20, 20))
     self.assertTrue(rlfl.delete_map(0))
     self.assertEqual(0, rlfl.create_map(20, 20))
     self.assertTrue(rlfl.delete_map(0))
     self.assertFalse(rlfl.delete_map(0))
     self.assertFalse(rlfl.delete_map(-1))
Example #3
0
    def init_fov(self):
        if self.current.fov_map0 is None:
            self.current.fov_map0 = rlfl.create_map(self.current.width, self.current.height)
#        self.current.fov_map = libtcod.map_new(self.current.width, self.current.height)
        for y in xrange(self.current.height):
            for x in xrange(self.current.width):
                self.update_fov_for(x, y)
Example #4
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)
Example #5
0
    def init_fov(self):
        if self.current.fov_map0 is None:
            self.current.fov_map0 = rlfl.create_map(self.current.width,
                                                    self.current.height)
#        self.current.fov_map = libtcod.map_new(self.current.width, self.current.height)
        for y in xrange(self.current.height):
            for x in xrange(self.current.width):
                self.update_fov_for(x, y)
Example #6
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)
Example #7
0
 def setUp(self):
     rlfl.delete_all_maps()
     self.map = rlfl.create_map(len(TMAP), len(TMAP[0]))
     for row in range(len(TMAP)):
         for col in range(len(TMAP[row])):
             if TMAP[row][col] != '#':
                 p = (row, col)
                 rlfl.set_flag(self.map, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(self.map, p, rlfl.CELL_OPEN) 
Example #8
0
 def setUp(self):
     rlfl.delete_all_maps()
     self.map = rlfl.create_map(len(MAP), len(MAP[0]))
     for row in range(len(MAP)):
         for col in range(len(MAP[row])):
             if MAP[row][col] != '#':
                 p = (row, col)
                 rlfl.set_flag(self.map, p, rlfl.CELL_SEEN)
                 rlfl.set_flag(self.map, p, rlfl.CELL_OPEN)
Example #9
0
 def test_create(self):
     for m in range(rlfl.MAX_MAPS):
         self.assertEqual(m, rlfl.create_map(20, 20))
     try:
         m = rlfl.create_map(20, 20)
     except Exception as e:
         self.assertEqual(str(e), 'Too many maps')
         self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
     else:
         self.fail('Expected Exception')
     rlfl.delete_all_maps()
     try:
         rlfl.create_map(-1, -1)
     except Exception as e:
         self.assertEqual(str(e), 'Invalid map size')
         self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
     else:
         self.fail('Expected Exception')
Example #10
0
 def test_create(self):
     for m in range(rlfl.MAX_MAPS):
         self.assertEqual(m, rlfl.create_map(20, 20))
     try:
         m = rlfl.create_map(20, 20)
     except Exception as e:
         self.assertEqual(str(e), 'Too many maps')
         self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
     else:
         self.fail('Expected Exception')
     rlfl.delete_all_maps()
     try:
         rlfl.create_map(-1, -1)
     except Exception as e:
         self.assertEqual(str(e), 'Invalid map size')
         self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
     else:
         self.fail('Expected Exception')
Example #11
0
 def create_map(self, m):
     # Import the map
     imap = __import__(m)
     self.map, self.origos = imap.MAP
     
     # Create the RLFL internal map
     self.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
                 rlfl.set_flag(self.mapnum, p, rlfl.CELL_OPEN)
Example #12
0
    def create_map(self, m):
        # Import the map
        imap = __import__(m)
        self.map, self.origos = imap.MAP

        # Create the RLFL internal map
        self.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
                    rlfl.set_flag(self.mapnum, p, rlfl.CELL_OPEN)
Example #13
0
 def test_gf(self):
     m = rlfl.create_map(20, 20)
     rlfl.set_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN))
     rlfl.set_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertFalse(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     for i in range(0, 20):
         self.assertTrue(rlfl.has_flag(m, (0, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (19, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 0), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 19), rlfl.CELL_PERM))
Example #14
0
 def test_gf(self):
     m = rlfl.create_map(20, 20)
     rlfl.set_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN))
     rlfl.set_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertFalse(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     for i in range(0, 20):
         self.assertTrue(rlfl.has_flag(m, (0, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (19, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 0), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 19), rlfl.CELL_PERM))
Example #15
0
 def test_flags(self):
     m = rlfl.create_map(20, 20)
     test = (
         {
             'p': (10, 10),
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'p': (-1, -1),
             'm': m,
             's': 'Location out of bounds',
             'f': rlfl.CELL_OPEN
         },
         {
             'p': (1, 1),
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['has_flag', 'set_flag', 'clear_flag']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['p'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' %
                           (func, i['s']))
     for i in test[0:2]:
         try:
             f = rlfl.get_flags(i['m'], i['p'])
             self.assertEqual(f, 0)
         except Exception as e:
             self.assertEqual(str(e), i['s'])
             self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
         else:
             self.fail('Expected Exception: func: %s, %s' %
                       ('get_flags', i['s']))
Example #16
0
 def test_flags(self):
     m = rlfl.create_map(20, 20)
     test = (
         {
             'p': (10, 10),
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'p': (-1, -1),
             'm': m,
             's': 'Location out of bounds',
             'f': rlfl.CELL_OPEN
         },
         {
             'p': (1, 1),
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['has_flag', 'set_flag', 'clear_flag']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['p'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' % (func, i['s']))
     for i in test[0:2]:
         try:
             f = rlfl.get_flags(i['m'], i['p'])
             self.assertEqual(f, 0)
         except Exception as e:
             self.assertEqual(str(e), i['s'])
             self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
         else:
             self.fail('Expected Exception: func: %s, %s' % ('get_flags', i['s']))
Example #17
0
 def show_path_away(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_away(mapnum, p1, p2, type, r, flags, diagonal)
     
     # Print the path
     self.print_map(path, p1, p2) 
Example #18
0
    def show_path_away(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_away(mapnum, p1, p2, type, r, flags, diagonal)

        # Print the path
        self.print_map(path, p1, p2)
Example #19
0
 def test_map(self):
     m = rlfl.create_map(20, 20)
     rlfl.fill_map(m, rlfl.CELL_SEEN)
     for i in range(20):
         for j in range(20):
             self.assertTrue(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     rlfl.clear_map(m)
     for i in range(20):
         for j in range(20):
             self.assertFalse(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     test = (
         {
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': 3,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['fill_map', 'clear_map']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' %
                           (func, i['s']))
Example #20
0
 def test_map(self):
     m = rlfl.create_map(20, 20)
     rlfl.fill_map(m, rlfl.CELL_SEEN)
     for i in range(20):
         for j in range(20):
             self.assertTrue(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     rlfl.clear_map(m)
     for i in range(20):
         for j in range(20):
             self.assertFalse(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     test = (
         {
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': 3,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['fill_map', 'clear_map']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' % (func, i['s']))