# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_play.ipynb.

# %% auto 0
__all__ = ['Game', 'play_random_game']

# %% ../nbs/03_play.ipynb 2
import numpy as np

# %% ../nbs/03_play.ipynb 4
class Game():
    """
    Game class for playing the game.
    """
    def __init__(self, board, tiles):
        self.board = board
        self.tiles = tiles
        self.finished = False

    def step(self, tile, action):
        
        """
        Do one step.
        """
        score_beginning = self.board.get_score()
        score_potential_beginning = self.board.get_score_potential()

        self.board.put_tile(tile, action)

        next_tile = self.tiles.draw_tile()

        indices, coordinates = self.board.get_potential_moves()

        score_change = self.board.get_score() - score_beginning
        score_potential_change = self.board.get_score_potential() - score_potential_beginning

        if self.board.is_full():
            self.finished = True

        return indices, coordinates, score_change, score_potential_change, next_tile

    def reset(self):
        self.board.reset()
        self.tiles.reset()
        self.finished = False

def play_random_game(board, tiles):
    """
    Play the game board.
    """
    game = Game(board, tiles)
    indices, coordinates = game.board.get_potential_moves()
    tile = game.tiles.draw_tile()

    while not game.finished:
        action = np.random.choice(np.array(len(coordinates[:, 0])))
        action = coordinates[action, :]
        indices, coordinates, score_change, score_potential_change, tile = game.step(tile, action)
        print(f"Score impact: {score_change}, potential score impact: {score_potential_change}")
    print("finished game with score: ", game.board.get_score())
