Created
October 10, 2015 01:15
-
-
Save jonathanhood/8cef6eeff3cd16ecc6f7 to your computer and use it in GitHub Desktop.
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 SubprocessPlayer(object): | |
def __init__(self,command): | |
.... launch subprocess and setup stdin/stdout | |
def new_game(initial_state): | |
... | |
return None | |
def take_turn(game_state): | |
... | |
return <action taken> | |
def game_finished(): | |
... tear down subprocess | |
class DemoPlayer(object): | |
def __init__(self): | |
.... launch subprocess and setup stdin/stdout | |
def new_game(initial_state): | |
... | |
return None | |
def take_turn(game_state): | |
... | |
return <action taken> | |
def game_finished(): | |
... tear down subprocess | |
class Engine(object): | |
def __init__(self,player1,player2): | |
... | |
def play(self): | |
while self.play_round(): | |
print "Playing!" | |
def play_round(self): | |
player1.take_turn(self.state) | |
player2.take_turn(self.state) | |
self.check_if_done() | |
eng = Engine(SubprocessPlayer("/usr/bin/python my_player"),DemoPlayer()) | |
eng.play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment