class ComputerDecision(threading.Thread): def __init__(self, window, gamestate, piece='X'): threading.Thread.__init__(self) problem = TicTacToeProblem(gamestate) self.agent = TicTacToeAgent(problem) self.window = window self.piece = piece self.gamestate = gamestate self.stopnow = False def stop(self, now=False): self.agent.keep_working = False self.stopnow = now def run(self): wx.CallAfter(self.window._agent_started) action = None if self.piece == 'X': action = self.agent.max_decision(self.gamestate) elif self.piece == 'O': action = self.agent.min_decision(self.gamestate) if self.stopnow: return if action: wx.CallAfter(self.window.game.do_action, *action) wx.CallAfter(self.window._agent_finished)
def __init__(self, window, gamestate, piece='X'): threading.Thread.__init__(self) problem = TicTacToeProblem(gamestate) self.agent = TicTacToeAgent(problem) self.window = window self.piece = piece self.gamestate = gamestate self.stopnow = False