<commit_before>'''
Players are Python objects with a __call__ method defined
to accept a Game instance as the sole argument. Players
return None, and leave the input Game unmodified, except
for its valid_moves attribute. This value may be replaced
with another tuple containing the same moves, but sorted
in decreasing order of preference. Players may be applied
one after another for easy composability.

.. code-block:: python

    >>> import dominoes
    >>> g = dominoes.Game.new()
    >>> g.valid_moves
    (([0|0], True), ([3|4], True), ([1|3], True), ([2|2], True), ([3|3], True), ([2|3], True), ([5|6], True))
    >>> dominoes.players.random(g)
    >>> g.valid_moves
    (([5|6], True), ([1|3], True), ([3|3], True), ([2|2], True), ([0|0], True), ([2|3], True), ([3|4], True))
'''
import random as rand

def random(game):
    '''
    Prefers moves randomly.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda _: rand.random()))

def reverse(game):
    '''
    Reverses move preferences.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(reversed(game.valid_moves))

def bota_gorda(game):
    '''
    Prefers to play dominoes with higher point values.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda m: -(m[0].first + m[0].second)))

def double(game):
    '''
    Prefers to play doubles.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda m: m[0].first != m[0].second))
<commit_msg>adding example player to player documentation<commit_after>'''
Players are Python objects with a __call__ method defined
to accept a Game instance as the sole argument. Players
return None, and leave the input Game unmodified, except
for its valid_moves attribute. This value may be replaced
with another tuple containing the same moves, but sorted
in decreasing order of preference. Players may be applied
one after another for easy composability.

.. code-block:: python

    >>> import dominoes
    >>> g = dominoes.Game.new()
    >>> g.valid_moves
    (([0|0], True), ([3|4], True), ([1|3], True), ([2|2], True), ([3|3], True), ([2|3], True), ([5|6], True))
    >>> dominoes.players.random(g)
    >>> g.valid_moves
    (([5|6], True), ([1|3], True), ([3|3], True), ([2|2], True), ([0|0], True), ([2|3], True), ([3|4], True))

.. code-block:: python

    def double(game):
        \'\'\'
        Prefers to play doubles.

        :param Game game: game to play
        :return: None
        \'\'\'
        game.valid_moves = tuple(sorted(game.valid_moves, key=lambda m: m[0].first != m[0].second))
'''
import random as rand

def random(game):
    '''
    Prefers moves randomly.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda _: rand.random()))

def reverse(game):
    '''
    Reverses move preferences.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(reversed(game.valid_moves))

def bota_gorda(game):
    '''
    Prefers to play dominoes with higher point values.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda m: -(m[0].first + m[0].second)))

def double(game):
    '''
    Prefers to play doubles.

    :param Game game: game to play
    :return: None
    '''
    game.valid_moves = tuple(sorted(game.valid_moves, key=lambda m: m[0].first != m[0].second))

{'fraction_non_alphanumeric': 0.15573318632855568, 'fraction_numerical': 0.018191841234840134, 'mean_word_length': 3.340909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2927958', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1190, 'n_words': 385}