from enum import Enum
from typing import NamedTuple


class Color(Enum):
    RED = "red"
    BLACK = "black"

    @property
    def opponent(self):
        return Color.BLACK if self == Color.RED else Color.RED


class PieceType(Enum):
    GENERAL = "general"
    ADVISOR = "advisor"
    ELEPHANT = "elephant"
    HORSE = "horse"
    CHARIOT = "chariot"
    CANNON = "cannon"
    SOLDIER = "soldier"


class Position(NamedTuple):
    col: int  # 0-8
    row: int  # 0-9


PIECE_SYMBOLS = {
    (PieceType.GENERAL, Color.RED): "帥",
    (PieceType.GENERAL, Color.BLACK): "將",
    (PieceType.ADVISOR, Color.RED): "仕",
    (PieceType.ADVISOR, Color.BLACK): "士",
    (PieceType.ELEPHANT, Color.RED): "相",
    (PieceType.ELEPHANT, Color.BLACK): "象",
    (PieceType.HORSE, Color.RED): "馬",
    (PieceType.HORSE, Color.BLACK): "馬",
    (PieceType.CHARIOT, Color.RED): "車",
    (PieceType.CHARIOT, Color.BLACK): "車",
    (PieceType.CANNON, Color.RED): "炮",
    (PieceType.CANNON, Color.BLACK): "砲",
    (PieceType.SOLDIER, Color.RED): "兵",
    (PieceType.SOLDIER, Color.BLACK): "卒",
}


class Piece:
    __slots__ = ("piece_type", "color", "position")

    def __init__(self, piece_type: PieceType, color: Color, position: Position):
        self.piece_type = piece_type
        self.color = color
        self.position = position

    @property
    def symbol(self) -> str:
        return PIECE_SYMBOLS[(self.piece_type, self.color)]

    def __repr__(self):
        col_letter = chr(self.position.col + ord("a"))
        return f"{self.color.value[0].upper()}{self.symbol}@{col_letter}{self.position.row}"
