def DrawPath(self,console):
		for i in range(0,libtcod.dijkstra_size(self.currentpath)):
			if not i == libtcod.dijkstra_size(self.currentpath)-1:
				x,y = libtcod.dijkstra_get(self.currentpath,i)
				libtcod.console_set_default_background(console,libtcod.yellow)
				libtcod.console_put_char(console, x, y, '=', libtcod.BKGND_SET)
			else:
				x,y = libtcod.dijkstra_get(self.currentpath,i)
				libtcod.console_set_char_background(console, x, y, libtcod.blue,libtcod.BKGND_SET)
	def ReturnNextPointOnPath(self,offset):
		if self.currentlyonpath == True:
			if not libtcod.dijkstra_is_empty(self.currentpath):
				if offset == True:
					err = libtcod.dijkstra_get(self.currentpath, 1)
					if not err == None:
						x,y = libtcod.dijkstra_get(self.currentpath, 0)
						x = x - self.owner.x
						y = y - self.owner.y							
						return x,y
				else:
					x,y = libtcod.dijkstra_get(self.currentpath, 0)
					if not x == False:
						return x,y
				print('Unable to get next spot in path')
				return None, None
			else:
				print('Path is empty')
				#self.SetCurrentTarget(CreateRandomWalkableCoords())
				self.RecomputePath()
				return None, None
		else:
			print('Not on path')
			return None, None
Exemple #3
0
def test_dijkstra(map_):
    path = libtcodpy.dijkstra_new(map_)

    libtcodpy.dijkstra_compute(path, *POINT_A)

    assert not libtcodpy.dijkstra_path_set(path, *POINT_C)
    assert libtcodpy.dijkstra_get_distance(path, *POINT_C) == -1

    assert libtcodpy.dijkstra_path_set(path, *POINT_B)
    assert libtcodpy.dijkstra_size(path)
    assert not libtcodpy.dijkstra_is_empty(path)

    libtcodpy.dijkstra_reverse(path)

    for i in range(libtcodpy.dijkstra_size(path)):
        x, y = libtcodpy.dijkstra_get(path, i)

    while (x, y) != (None, None):
        x, y = libtcodpy.dijkstra_path_walk(path)

    libtcodpy.dijkstra_delete(path)