Skip to content

Instantly share code, notes, and snippets.

@sne11ius
Created November 21, 2013 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sne11ius/7591030 to your computer and use it in GitHub Desktop.
Save sne11ius/7591030 to your computer and use it in GitHub Desktop.
Some bot for http://robotgame.org/
import rg
'''
snoflake.py
current elo: 1484
current ranking: 77
Actually, this was one of my first bots and I don't like it.
'''
class Robot:
def num_enemies(self, game):
enemies = 0
for location, bot in game.get('robots').items():
if bot.get('player_id') != self.player_id:
if 1 == rg.wdist(self.location, location):
enemies += 1
return enemies
def num_frieds(self, game):
friends = 0
for location, bot in game.get('robots').items():
if bot.get('player_id') == self.player_id:
if 1 == rg.wdist(self.location, location):
friends += 1
return friends
def act(self, game):
num_enemies = self.num_enemies(game)
if num_enemies * 9 > self.hp:
return ['suicide']
min_distance = float("inf")
move_to = rg.CENTER_POINT
for location, bot in game.get('robots').items():
if bot.get('player_id') != self.player_id:
if rg.dist(location, self.location) <= 1:
return ['attack', location]
if bot.get('player_id') == self.player_id:
if rg.wdist(location, self.location) < min_distance:
min_distance = rg.wdist(location, self.location)
move_to = location
if min_distance < 2:
move_to = rg.CENTER_POINT
if self.location == rg.CENTER_POINT:
return ['guard']
if self.num_frieds(game) > 1:
return ['guard']
return ['move', rg.toward(self.location, move_to)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment