# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_tiles.ipynb.

# %% auto 0
__all__ = ['Tiles']

# %% ../nbs/01_tiles.ipynb 3
import numpy as np

# %% ../nbs/01_tiles.ipynb 4
class Tiles():

    '''Class to store all tiles and whether they have been drawn or not.
    Also manages the drawing mechanism.'''

    def __init__(self,
                 random_seed = 0, # random seed for the drawing mechanism
                 mode = "play" # "play" or "input": "play" mode draws a random tile, "input" mode if the user inputs the tile that has been drawn
                 ):

        digits = np.array([[1, 5, 9], [3, 4, 8], [2, 6, 7]])
        self.chips =np.zeros((27, 3), dtype=int)

        for i in range(27):
            self.chips[i] = [digits[0][i//9], digits[1][(i//3)%3], digits[2][i%3]]

        # Initialize boolean array to all False
        self.chosen = np.zeros(27, dtype=bool)
        self.mode = mode

    def __str__(self):
        return "Tiles object"
    
    __repr__ = __str__

    def draw_tile(self):
        assert self.mode == "play", "You are in input mode, you need to input the tile that has been drawn."
        '''Draw a random tile from the remaining tiles.'''
        # Get the indices of the remaining tiles
        remaining = np.where(self.chosen == False)[0]
        # Draw a random tile
        draw = np.random.choice(remaining)
        # Mark the tile as drawn
        self.chosen[draw] = True
        return self.chips[draw]

    def input_tile(self, tile):
        assert self.mode == "input", "You are in play mode, you need to draw a tile."
        '''Input the tile that has been drawn.'''
        # Find the index of the drawn tile
        draw = np.where((self.chips == tile).all(axis=1))[0][0]
        # Mark the tile as drawn
        self.chosen[draw] = True
        return self.chips[draw]
    
    def reset(self):
        '''Reset the chosen array to all False.'''
        self.chosen = np.zeros(27, dtype=bool)
