Skip to content

Instantly share code, notes, and snippets.

@jonathanhood
Created October 10, 2015 01:15
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 jonathanhood/8cef6eeff3cd16ecc6f7 to your computer and use it in GitHub Desktop.
Save jonathanhood/8cef6eeff3cd16ecc6f7 to your computer and use it in GitHub Desktop.
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