Created
December 16, 2013 20:02
-
-
Save mpeterv/7993372 to your computer and use it in GitHub Desktop.
Template for a robotgame bot
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
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