Source code for enums

""" This module has the enumeration classes.
"""
from enum import Enum, Flag, IntEnum, auto
from typing import Any, Dict, Tuple

[docs]class Color(Flag): """Represents color as a boolean. ===== ===== Color Value ===== ===== WHITE True BLACK False ===== ===== """ BLACK = False WHITE = True
[docs]class Numbers(IntEnum): A, B, C, D, E, F, G, H = 97, 98, 99, 100, 101, 102, 103, 104 ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT = 1, 2, 3, 4, 5, 6, 7, 8
[docs]class Positions(Enum): """Represents the "magic" numbers of a chess board. ================= ================================================ Numbers ================= ================================================ ALGEBRIAC Dictionary of two-character notation string, ``'a1'``, to two-item tuple, ``(97, 1)``. CASTLING Dictionary of king end position (two-item tuple) and nearest rooks (tuple of two-item tuples). CASTLING_FILE_END File number for queen-side position of rook. FILE_NUMBERS List of unicode numbers of the file letters from 'a' through 'h'. FILE_RANK Dictionary of two-item tuple, ``(97, 1)``, to two-character notation string, ``'a1'``. POSITIONS List of two-item tuples for all positions. ================= ================================================ """ ALGEBRIAC = {chr(96 + file) + str(rank): (96 + file, rank) for file in range(1, 9) for rank in range(1, 9)} CASTLING: Dict[Any, Tuple[Any, Any]] = {(99, 1): ((100, 1), (97, 1)), (99, 8): ((100, 8), (97, 8)), (103, 1): ((102, 1), (104, 1)), (103, 8): ((102, 8), (104, 8))} FILE_NUMBERS = list(96 + file for file in range(1,9)) FILE_RANK: Dict[Any, str] = {(96 + file, rank): chr(96 + file) + str(rank) for file in range(1, 9) for rank in range(1, 9)} POSITIONS = [(96 + file, rank) for file in range(1, 9) for rank in range(1, 9)]
[docs]class PieceType(Enum): """Represents the names of the pieces. * BISHOP * KING * KNIGHT * PAWN * ROOK * QUEEN """ BISHOP = auto() KING = auto() KNIGHT = auto() PAWN = auto() ROOK = auto() QUEEN = auto()
[docs]class Rank(tuple, Enum): """Represents the starting ranks for specific pieces. ==== ====== Rank Value ==== ====== HIGH (1, 8) PAWN (2, 7) ==== ====== This class inherits from both ``tuple`` and ``Enum``. The ``tuple`` class allows access to the assigned value via the ``in`` statement without having to add ``.value`` statement to the end. >>> enums.Rank.HIGH <Rank.HIGH: (1, 8)> >>> enums.Rank.HIGH.value (1, 8) >>> 8 in enums.Rank.HIGH True >>> 7 in enums.Rank.HIGH False """ HIGH = (1, 8) PAWN = (2, 7)
[docs]class SetOrder(tuple, Enum): """Represents the set order for high and pawn pieces on the board. ==== ======================================================= Rank Value ==== ======================================================= HIGH Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook PAWN Pawn, Pawn, Pawn, Pawn, Pawn, Pawn, Pawn, Pawn ==== ======================================================= """ HIGH = (PieceType.ROOK, PieceType.KNIGHT, PieceType.BISHOP, PieceType.QUEEN, PieceType.KING, PieceType.BISHOP, PieceType.KNIGHT, PieceType.ROOK) PAWN = (PieceType.PAWN, PieceType.PAWN, PieceType.PAWN, PieceType.PAWN, PieceType.PAWN, PieceType.PAWN, PieceType.PAWN, PieceType.PAWN)
[docs]class Status(Enum): """Represents move status. * CAPTURE * CASTLING * CHECK * CHECKMATE * EN_PASSANT * INVALID * VALID """ CAPTURE = auto() CASTLING = auto() CHECK = auto() CHECKMATE = auto() EN_PASSANT = auto() INVALID = auto() VALID = auto()