def record_stats(self, players, winners): # This method may be overridden to implement other scoring systems. win_points = (len(players) / len(winners)) - 1 loss_points = -1 scores = self.read_scores() self.log.debug("Initial scores: %r", dict(scores)) # Scoring loop for power, name, version, factor in players: key = (name, version) if power in winners: diff = win_points else: diff = loss_points diff *= factor scores[key] = scores.get(key, 0) + diff if diff < 0: gain = 'loses' else: gain = 'gains' change = abs(diff) self.log.info("%s (%s) %s %g point%s, for a total of %g." % (name, version, gain, change, s(change), scores[key])) self.store_scores(scores)
def generate(self): "Generate a move for the computer player." msg = sum(x << (n*2) for n, x in enumerate(self.game.board)) msg |= self.player << 18 message = msg for n in count(1): action = self.agent.process(message) pos = action % 9 if self.game.board[pos]: self.game.output("%d round%s", n, s(n)) self.game.goto(*self.game.square[pos]) self.game.win.refresh() # Keep part of the failure around. message = ((action << 20) & 0xFFFF0000) | msg else: break return pos