Skip to content

Commit

Permalink
Revert callback implementation (#14)
Browse files Browse the repository at this point in the history
This callback implementation is too complicated and not flexible. Will
create a state change event for client to react on.
  • Loading branch information
ZengLawrence authored Dec 15, 2024
1 parent 1b402ec commit f58a067
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,13 @@ def tie(state):
"""Return true if game ends in a tie"""
return all(val in 'xo' for row in state for val in row)

def no_ops(_game):
"""Place holder function that take one argument 'game'"""

class Game:
"""Class representing game"""

def __init__(self):
self.state = init_state()
self.side = 'x'
self.result = None
self.per_move = no_ops
self.done = no_ops

def __running(self):
"""Return true if game is running. Game ends if there is a winner or a tie."""
Expand All @@ -84,19 +79,9 @@ def start(self, per_move, done):
Both per_move and done function takes game instance as input.
"""
if per_move:
self.per_move = per_move
if done:
self.done = done
self.__per_move()

def __per_move(self):
if self.per_move:
self.per_move(self)
if self.__running():
self.__per_move()
else:
self.done(self)
while self.__running():
per_move(self)
done(self)

def make(self, move):
"""
Expand Down

0 comments on commit f58a067

Please sign in to comment.