def __init__(self, size, opponent=None, **args): EpisodicTask.__init__(self, GomokuGame((size, size))) self.setArgs(**args) if opponent == None: opponent = RandomGomokuPlayer(self.env) elif isclass(opponent): # assume the agent can be initialized without arguments then. opponent = opponent(self.env) if not self.opponentStart: opponent.color = GomokuGame.WHITE self.opponent = opponent self.minmoves = 9 self.maxmoves = self.env.size[0] * self.env.size[1] self.reset()
def __init__(self, size, opponent = None, **args): EpisodicTask.__init__(self, GomokuGame((size, size))) self.setArgs(**args) if opponent == None: opponent = RandomGomokuPlayer(self.env) elif isclass(opponent): # assume the agent can be initialized without arguments then. opponent = opponent(self.env) if not self.opponentStart: opponent.color = GomokuGame.WHITE self.opponent = opponent self.minmoves = 9 self.maxmoves = self.env.size[0] * self.env.size[1] self.reset()
def __init__(self, size, opponent=None, **args): EpisodicTask.__init__(self, CaptureGame(size)) self.setArgs(**args) if opponent == None: opponent = RandomCapturePlayer(self.env) elif isclass(opponent): # assume the agent can be initialized without arguments then. opponent = opponent(self.env) else: opponent.game = self.env if not self.opponentStart: opponent.color = CaptureGame.WHITE self.opponent = opponent self.maxmoves = self.env.size * self.env.size self.minmoves = 3 self.reset()
def __call__(self, x): """ If a module is given, wrap it into a ModuleDecidingAgent before evaluating it. Also, if applicable, average the result over multiple games. """ if isinstance(x, Module): agent = ModuleDecidingPlayer(x, self.env, greedySelection = True) elif isinstance(x, GomokuPlayer): agent = x else: raise NotImplementedError('Missing implementation for '+x.__class__.__name__+' evaluation') res = 0 agent.game = self.env self.opponent.game = self.env for dummy in range(self.averageOverGames): agent.color = -self.opponent.color res += EpisodicTask.__call__(self, agent) return res / float(self.averageOverGames)
def __call__(self, x): """ If a module is given, wrap it into a ModuleDecidingAgent before evaluating it. Also, if applicable, average the result over multiple games. """ if isinstance(x, Module): agent = ModuleDecidingPlayer(x, self.env, greedySelection=True) elif isinstance(x, GomokuPlayer): agent = x else: raise NotImplementedError('Missing implementation for ' + x.__class__.__name__ + ' evaluation') res = 0 agent.game = self.env self.opponent.game = self.env for dummy in range(self.averageOverGames): agent.color = -self.opponent.color res += EpisodicTask.__call__(self, agent) return res / float(self.averageOverGames)
def performAction(self, action): EpisodicTask.performAction(self, action) if not self.isFinished(): EpisodicTask.performAction(self, self.opponent.getAction())
def reset(self): self.switched = False EpisodicTask.reset(self) if self.opponent.color == GomokuGame.BLACK: # first move by opponent EpisodicTask.performAction(self, self.opponent.getAction())
def reset(self): self.switched = False EpisodicTask.reset(self) if self.opponent.color == CaptureGame.BLACK: # first move by opponent EpisodicTask.performAction(self, self.opponent.getAction())