Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nate
committed
Nov 27, 2010
1 parent
9274756
commit cff8e6c
Showing
8 changed files
with
16,488 additions
and
3,440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,47 @@ | ||
from graph import mark | ||
from itertools import chain | ||
from logging import getLogger | ||
log = getLogger('nate') | ||
from planetwars import BaseBot | ||
from planetwars.player import ENEMIES | ||
|
||
|
||
class Bot(BaseBot): | ||
def update(self): | ||
planets = self.universe.my_planets | ||
enemies = self.universe.enemy_planets | ||
|
||
for planet in planets: | ||
enemy = planet.find_nearest_neighbor(owner=ENEMIES) | ||
planet.proximity = planet.distance(enemy) | ||
planet.contracts = {} | ||
for planet in self.universe.nobodies_planets: | ||
enemy = planet.find_nearest_neighbor(owner=ENEMIES) | ||
if enemy: planet.proximity = planet.distance(enemy) | ||
for planet in enemies: | ||
planet.proximity = 0 | ||
planet.safety = 0 | ||
|
||
current = set(enemies) | ||
mine = set(self.universe.my_planets | self.universe.nobodies_planets) | ||
while mine: | ||
safer = set() | ||
for unsafe in current: | ||
planet = sorted(mine, key=lambda p: p.distance(unsafe))[0] | ||
planet.safety = unsafe.safety + 1 | ||
safer.add(planet) | ||
mine -= safer | ||
current = safer | ||
|
||
|
||
def do_turn(self): | ||
mark(self.universe.enemy_planets) | ||
actions = sorted(p.action() for p in self.universe.planets) | ||
self.update() | ||
actions = sorted(chain(*(p.actions() for p in self.universe.planets))) | ||
log.debug('ORDERING ACTIONS =====================================') | ||
for action in actions: | ||
log.debug(action) | ||
actions = filter(lambda a: a.priority > 0, actions) | ||
log.debug('TAKING ACTIONS =====================================') | ||
for contract in chain(*(action.engage() for action in actions)): | ||
log.debug('\t%s' % contract) | ||
contract.execute() | ||
for planet in self.universe.my_planets: | ||
planet.fortify() |
Oops, something went wrong.