import random


class Board():

    def __init__(self):
        self._piles = []
        self._prepare()


    def apply(self, move):
        rand_piles = move.get_pile()
        rand_stones = move.get_stones()
        self._piles[rand_piles] = max(0, self._piles[rand_piles] - rand_stones)
    
    def is_empty(self):
        empty = [0] * len(self._piles)
        return self._piles == empty


    def to_string(self):
        text =  "\n--------------------"
        for rand_piles, rand_stones in enumerate(self._piles):
            text += (f"\n{rand_piles}: " + "O " * rand_stones)
        text += "\n--------------------"
        return text

    def _prepare(self):
        rand_piles = random.randint(2, 5)
        for i in range(rand_piles):
            rand_stones = random.randint(1, 9)
            self._piles.append(rand_stones)
