<commit_before>import sys

import acpc_python_client as acpc
from tqdm import tqdm  # TODO make import optional

from cfr.cfr import Cfr
from cfr.game_tree import HoleCardsNode, ActionNode


def _action_to_str(action):
    if action == 0:
        return 'f'
    elif action == 1:
        return 'c'
    else:
        return 'r'


def _get_strategy_lines(lines, node, prefix=''):
    if type(node) == HoleCardsNode:
        for card, child_node in node.children.items():
            new_prefix = prefix
            if new_prefix and not new_prefix.endswith(':'):
                new_prefix += ':'
            new_prefix += '%s:' % card
            _get_strategy_lines(lines, child_node, new_prefix)
    elif type(node) == ActionNode:
        node_strategy_str = ' '.join([str(prob) for prob in node.average_strategy])
        lines.append('%s %s\n' % (prefix, node_strategy_str))

        for action, child_node in node.children.items():
            _get_strategy_lines(lines, child_node, prefix + _action_to_str(action))


def write_strategy(game_tree, output_path):
    with tqdm(total=1) as progress:
        progress.set_description('Obtaining strategy entries')
        strategy_file_lines = []
        _get_strategy_lines(strategy_file_lines, game_tree)
        progress.update(1)
<commit_msg>Fix strategy file writing to include board cards<commit_after>import sys

import acpc_python_client as acpc
from tqdm import tqdm  # TODO make import optional

from cfr.cfr import Cfr
from cfr.game_tree import HoleCardsNode, ActionNode, BoardCardsNode


def _action_to_str(action):
    if action == 0:
        return 'f'
    elif action == 1:
        return 'c'
    else:
        return 'r'


def _get_strategy_lines(lines, node, prefix=''):
    node_type = type(node)
    if node_type == HoleCardsNode or node_type == BoardCardsNode:
        for key, child_node in node.children.items():
            new_prefix = prefix
            if new_prefix and not new_prefix.endswith(':'):
                new_prefix += ':'
            new_prefix += ':'.join([str(card) for card in key]) + ':'
            _get_strategy_lines(lines, child_node, new_prefix)
    elif node_type == ActionNode:
        node_strategy_str = ' '.join([str(prob) for prob in node.average_strategy])
        lines.append('%s %s\n' % (prefix, node_strategy_str))

        for action, child_node in node.children.items():
            _get_strategy_lines(lines, child_node, prefix + _action_to_str(action))


def write_strategy(game_tree, output_path):
    with tqdm(total=1) as progress:
        progress.set_description('Obtaining strategy entries')
        strategy_file_lines = []
        _get_strategy_lines(strategy_file_lines, game_tree)
        progress.update(1)

{'fraction_non_alphanumeric': 0.09842663739480424, 'fraction_numerical': 0.0029271862422246614, 'mean_word_length': 3.0265095729013254, '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': '2153865', 'n_tokens_mistral': 880, 'n_tokens_neox': 858, 'n_words': 216}