import numpy as np
from random import shuffle

lands = {'C': 'Castle', 'F': 'Forrest', 'G': 'Grass', 'L': 'Lake', 'M': 'Mountain', 'S': 'Swamp', 'W': 'Wheat'}


class card:
    def __init__(self, tile_a, crown_a, tile_b, crown_b, rotation, inverse=None):
        self.tile_a = tile_a
        self.crown_a = crown_a
        self.tile_b = tile_b
        self.crown_b = crown_b
        self.rotation = rotation
        if inverse is None:
            self.inverse = card(self.tile_b, self.crown_b, self.tile_a, self.crown_a, (self.rotation + 2) % 4, self)
        else:
            self.inverse = inverse

    def rotate(self):
        self.rotation = (self.rotation + 1) % 4

    def offset(self):
        rot = [(0, 1), (1, 0), (0, -1), (-1, 0)]
        return rot[self.rotation]

    def __eq__(self, other):
        return self.tile_a == other.tile_a

    def __repr__(self):
        rot = [(' ', '='), ('.', '.'), ('=', ' '), ('`', 'ยด')]
        a, b = rot[self.rotation]
        if self.tile_a == 'C':
            a, b = ('<', '>')
        return a + self.tile_a + str(self.crown_a) + b


class board:
    _board = []

    def __init__(self):
        self._board = np.empty(shape=(13, 13), dtype=card)
        # self._board.fill()
        self._board[6][6] = card('C', 0, '', 0, 1)

    def place(self, new_card, coords):
        x1, y1 = coords
        dx2, dy2 = new_card.offset()
        x2 = x1 + dx2
        y2 = y1 + dy2

        if self._board[x1][y1] is not None:
            print('geht nicht')
            return
        if self._board[x2][y2] is not None:
            print('geht auch nicht')
            return
        self._board[x1][y1] = new_card
        self._board[x2][y2] = new_card.inverse

    def available_slots(self, new_card):
        b = new_card == self._board
        return b

    def __repr__(self):
        return str(self._board)


deck = list(range(1, 49))
shuffle(deck)
deck = np.reshape(deck, (12, 4))
for row in deck:
    row.sort()


if __name__ == '__main__':
    b = board()
    c1 = card('F', 0, 'W', 0, 0)
    b.place(c1, (5, 6))
    c2 = card('F', 0, 'S', 0, 0)
    print(b.available_slots(c2))
    # print(b)
    # print(deck)
    # print(c)
    # print(c.inverse)