Skip to content

Instantly share code, notes, and snippets.

@mpeterv
Created December 16, 2013 20:02
Show Gist options
  • Save mpeterv/7993372 to your computer and use it in GitHub Desktop.
Save mpeterv/7993372 to your computer and use it in GitHub Desktop.
Template for a robotgame bot
class Game:
def __init__(self, data, player_id):
self.player_id = player_id
self.update(data)
def update(self, data):
self.turn = data['turn']
self.robots = data['robots']
self.onNewTurn()
# called in the beginning of each turn
def onNewTurn(self):
# add here initialization for per-turn data
# then add some per-turn calculations
pass
# should return action for bot at given location
def act(self, loc):
return ['guard']
# you can refer to self.player_id, self.turn and self.robots properties in this class
class Robot:
game = None
def act(self, data):
if self.game == None:
self.game = Game(data, self.player_id)
elif self.game.turn != data['turn']:
self.game.update(data)
return self.game.act(self.location)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment