<commit_before>import random
import pdb

from defines import *

class OpeningsMover(object):
    def __init__(self, o_mgr, game):
        self.o_mgr = o_mgr
        self.game = game

    def get_a_good_move(self):
        wins = 0
        losses = 0
        totals = []

        colour = self.game.to_move_colour()
        max_rating_factor = 1

        move_games = self.o_mgr.get_move_games(self.game)
        
        for mg in move_games:
            move, games = mg
            for g in games:
                win_colour = g.get_won_by()

                if win_colour == colour:
                    wins += 1
                else:
                    assert(win_colour == opposite_colour(colour))
                    losses += 1

                # Calc & save the maximum rating of the players
                # who made this move
                move_player = g.get_player(colour)

                if move_player:
                    max_rating_factor = \
                        max(max_rating_factor, move_player.rating_factor())

            totals.append((move, wins, losses, max_rating_factor))

        total_score = 1 # For fall through to inner filter
<commit_msg>Use preserved games for opening move selection<commit_after>import random
import pdb

from defines import *

class OpeningsMover(object):
    def __init__(self, o_mgr, game):
        self.o_mgr = o_mgr
        self.game = game

    def get_a_good_move(self):
        wins = 0
        losses = 0
        totals = []

        colour = self.game.to_move_colour()
        max_rating_factor = 1

        move_games = self.o_mgr.get_move_games(self.game)
        
        for mg in move_games:
            move, games = mg
            for pg in games:
                win_colour = pg.won_by

                if win_colour == colour:
                    wins += 1
                elif win_colour == opposite_colour(colour):
                    losses += 1
                # else ignore draws and unfinished games (latter shouldn't get here)

                move_rating = pg.get_rating(colour)

                # TODO: More smarts here
                max_rating_factor = \
                    max(max_rating_factor, move_rating)


            totals.append((move, wins, losses, max_rating_factor))

        total_score = 1 # For fall through to inner filter

{'fraction_non_alphanumeric': 0.06989708404802744, 'fraction_numerical': 0.005145797598627788, 'mean_word_length': 1.5358695652173913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693554', 'n_tokens_mistral': 695, 'n_tokens_neox': 637, 'n_words': 174}