def __call__(self, p1, p2): self.temp = self.minTemperature if self.useNetworks: p1 = ModuleDecidingPlayer(p1, self.task.env, temperature = self.temp) p2 = ModuleDecidingPlayer(p2, self.task.env, temperature = self.temp) else: assert isinstance(p1, CapturePlayer) assert isinstance(p2, CapturePlayer) p1.game = self.task.env p2.game = self.task.env p1.color = CaptureGame.BLACK p2.color = -p1.color self.player = p1 self.opponent = p2 # the games with increasing temperatures and lower coefficients coeffSum = 0. score = 0. np = int(self.cases * (1-self.presetGamesProportion)) for i in range(self.maxGames): coeff = 1/(10*self.temp+1) preset = None if self.cases > 1: if i % self.cases >= np: preset = self.sPos[(i-np) % self.cases] elif i < self.cases: # greedy, no need to repeat, just increase the coefficient if i == 0: coeff *= np else: continue res = self._oneGame(preset) score += coeff * res coeffSum += coeff if self.cases == 1 or (i % self.cases == 0 and i > 0): self._globalWarming() return score / coeffSum
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, CapturePlayer): 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 x = EpisodicTask.__call__(self, agent) res += x 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, CapturePlayer): 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 x = EpisodicTask.__call__(self, agent) res += x return res / float(self.averageOverGames)