Esempio n. 1
0
    def __init__(self):
        self.DEFAULT_PRIOR = 0.1
        self.MAP_WIDTH = 800
        self.MAP_HEIGHT = 800
        self.NUM_SPOTS = 5
        self.DIFF = 50

        self.potentials = []

        self.grid = np.zeros((self.MAP_WIDTH, self.MAP_HEIGHT))
        self.grid.fill(self.DEFAULT_PRIOR)

        self.draw_grid = Grid()
        self.draw_grid.init_window(800, 800)
Esempio n. 2
0
	def __init__(self):
		self.DEFAULT_PRIOR = 0.1
		self.MAP_WIDTH = 800
		self.MAP_HEIGHT = 800
		self.NUM_SPOTS = 5
		self.DIFF = 50
		
		self.potentials = []
		
		self.grid = np.zeros((self.MAP_WIDTH, self.MAP_HEIGHT))
		self.grid.fill(self.DEFAULT_PRIOR)
		
		self.draw_grid = Grid()
		self.draw_grid.init_window(800, 800)
Esempio n. 3
0
class WorldGrid:
    def __init__(self):
        self.DEFAULT_PRIOR = 0.1
        self.MAP_WIDTH = 800
        self.MAP_HEIGHT = 800
        self.NUM_SPOTS = 5
        self.DIFF = 50

        self.potentials = []

        self.grid = np.zeros((self.MAP_WIDTH, self.MAP_HEIGHT))
        self.grid.fill(self.DEFAULT_PRIOR)

        self.draw_grid = Grid()
        self.draw_grid.init_window(800, 800)

    def coordinates_to_indexes(self, x, y):
        i = x + (self.MAP_WIDTH / 2)
        j = y - (self.MAP_HEIGHT / 2)
        return i, j

    def grid_to_indexes(self, grid_x, grid_y, pos):
        origin_x, origin_y = pos
        offset_x = grid_x + origin_x
        offset_y = grid_y + origin_y
        x, y = self.coordinates_to_indexes(offset_x, offset_y)
        return y, x

    def get_world_value(self, grid_x, grid_y, pos):
        x, y = self.grid_to_indexes(grid_x, grid_y, pos)
        return self.grid[x, y]

    def set_world_value(self, grid_x, grid_y, pos, value):
        x, y = self.grid_to_indexes(grid_x, grid_y, pos)
        self.grid[x, y] = value

    def draw_obstacle_grid(self):
        self.draw_grid.update_grid(self.grid)
        self.draw_grid.draw_grid(self.potentials)

    def getPartialGrid(self):
        x = -self.MAP_WIDTH / 2
        y = -self.MAP_HEIGHT / 2
        result = []
        while x < self.MAP_WIDTH / 2:
            print "x: ", x
            while y < self.MAP_HEIGHT / 2:
                print "y: ", y
                pos = (x, y)
                if self.isUnvisited(pos):
                    print "adding ", pos
                    result.append(pos)
                y += self.DIFF
            y = -self.MAP_HEIGHT / 2
            x += self.DIFF
        print "Partial Grid: ", result
        return result

    def getNewUnvistedLocation(self):
        positions = self.getPartialGrid()
        i = random.randrange(len(positions))
        return positions[i]

    def isUnvisited(self, pos):
        x, y = pos
        i, j = self.coordinates_to_indexes(x, y)

        value = self.grid[x, y]
        value2 = self.grid[i, j]
        value3 = self.grid[j, i]
        value4 = self.grid[y, x]

        print "(", i, ",", abs(j), ") = ", value3
        #print "(", x, ",", y, ") = "
        #print "(", i, ",", j, ") = ", value2
        #print "(", x, ",", y, ") = ", value
        if value3 == self.DEFAULT_PRIOR:
            return True
        return False

    def getTargetLocations(self):
        print "Potentials: ", self.potentials
        while len(self.potentials) < self.NUM_SPOTS:
            self.potentials.append(self.getNewUnvistedLocation())

        for i in range(0, self.NUM_SPOTS):
            pos = self.potentials[i]
            if not self.isUnvisited(pos):
                self.potentials[i] = self.getNewUnvistedLocation()
        return self.potentials
Esempio n. 4
0
class WorldGrid:
	
	def __init__(self):
		self.DEFAULT_PRIOR = 0.1
		self.MAP_WIDTH = 800
		self.MAP_HEIGHT = 800
		self.NUM_SPOTS = 5
		self.DIFF = 50
		
		self.potentials = []
		
		self.grid = np.zeros((self.MAP_WIDTH, self.MAP_HEIGHT))
		self.grid.fill(self.DEFAULT_PRIOR)
		
		self.draw_grid = Grid()
		self.draw_grid.init_window(800, 800)

	def coordinates_to_indexes(self, x, y):
		i = x + (self.MAP_WIDTH / 2)
		j = y - (self.MAP_HEIGHT / 2)
		return i, j
		
	def grid_to_indexes(self, grid_x, grid_y, pos):
		origin_x, origin_y = pos
		offset_x = grid_x + origin_x
		offset_y = grid_y + origin_y
		x, y = self.coordinates_to_indexes(offset_x, offset_y)
		return y, x
		
	def get_world_value(self, grid_x, grid_y, pos):
		x,y = self.grid_to_indexes(grid_x, grid_y, pos)
		return self.grid[x,y]
		
	def set_world_value(self, grid_x, grid_y, pos, value):
		x,y = self.grid_to_indexes(grid_x, grid_y, pos)
		self.grid[x,y] = value
		
	def draw_obstacle_grid(self):
		self.draw_grid.update_grid(self.grid)
		self.draw_grid.draw_grid(self.potentials)
	
	def getPartialGrid(self):
		x = -self.MAP_WIDTH / 2
		y = -self.MAP_HEIGHT / 2
		result = []
		while x < self.MAP_WIDTH /2:
			print "x: ", x
			while y < self.MAP_HEIGHT /2:
				print "y: ", y
				pos = (x,y)
				if self.isUnvisited(pos):
					print "adding ", pos
					result.append(pos)
				y += self.DIFF
			y = -self.MAP_HEIGHT / 2
			x += self.DIFF
		print "Partial Grid: ", result
		return result
	
	def getNewUnvistedLocation(self):
		positions = self.getPartialGrid()
		i = random.randrange(len(positions))
		return positions[i]
		
	
	def isUnvisited(self, pos):
		x, y = pos
		i, j = self.coordinates_to_indexes(x, y)
		
		value = self.grid[x,y]
		value2 = self.grid[i,j]
		value3 = self.grid[j, i]
		value4 = self.grid[y,x]

		print "(", i, ",", abs(j), ") = ", value3
		#print "(", x, ",", y, ") = "
		#print "(", i, ",", j, ") = ", value2
		#print "(", x, ",", y, ") = ", value
		if value3 == self.DEFAULT_PRIOR:
			return True
		return False
		
	def getTargetLocations(self):
		print "Potentials: ", self.potentials
		while len(self.potentials) < self.NUM_SPOTS:
			self.potentials.append(self.getNewUnvistedLocation())
		
		for i in range(0, self.NUM_SPOTS):
			pos = self.potentials[i]
			if not self.isUnvisited(pos):
				self.potentials[i] = self.getNewUnvistedLocation() 
		return self.potentials