Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2013 19:30
Show Gist options
  • Save anonymous/7551078 to your computer and use it in GitHub Desktop.
Save anonymous/7551078 to your computer and use it in GitHub Desktop.
Template for cooperative strategy in robotgames
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()
pass
# called in the beginning of each turn
def onNewTurn(self):
pass
# should return action for bot at given location
def act(self, loc):
return ['guard']
# useful info is stored in self.player_id, self.turn and self.robots preprties
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