I'm trying to create a heatmap for a planetwars bot which indicates which influence a planet is under. The initial map looks like: http://imgur.com/a/rPVnl#0
Ideally the Red planet should have a value of -1, the Blue planet should have a value of 1, and the planet marked 1 should have a value of 0. (Or 0 to 1, mean of 0.5 would work)
My initial analysis code is below, but the results it outputs are between 0.13 and 7.23.
for p in gameinfo.planets: #gameinfo.planets returns {pid:planet_object}
planet = gameinfo.planets[p]
own_value = 1
for q in gameinfo.my_planets.values():
if q != planet:
q_value = q.num_ships / planet.distance_to(q)
own_value = own_value + q_value
enemy_value = 1
for q in gameinfo.enemy_planets.values():
if q != planet:
q_value = q.num_ships / planet.distance_to(q)
enemy_value = enemy_value + q_value
self.heatmap[p] = own_value/enemy_value
I've also tried to add some code to curb the range from 0 to 1
highest = self.heatmap.keys()[0]
lowest = self.heatmap.keys()[0]
for p in gameinfo.planets.keys():
if self.heatmap[p] > highest:
highest = self.heatmap[p]
elif self.heatmap[p] < lowest:
lowest = self.heatmap[p]
map_range = highest-lowest
for p in gameinfo.planets.keys():
self.heatmap[p] = self.heatmap[p]/map_range
self.heatmap_mean = sum(self.heatmap.values(), 0.0) / len(self.heatmap)
The values ended up between 0 and 1, but the mean was 0.245? (Also the values actually ranged from 0.019 to 1.019).