diff --git a/main.py b/main.py index 2ebf78a..c611ff2 100755 --- a/main.py +++ b/main.py @@ -2,10 +2,8 @@ import argparse -from ai import train from loguru import logger -from path import BASE_PATH -from py2048 import Menu +from utils import BASE_PATH def pos_int(string: str) -> int: diff --git a/src/path.py b/src/path.py deleted file mode 100644 index 30bf284..0000000 --- a/src/path.py +++ /dev/null @@ -1,3 +0,0 @@ -from pathlib import Path - -BASE_PATH = Path(__file__).resolve().parent.parent diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..f2e9f7b --- /dev/null +++ b/src/utils/__init__.py @@ -0,0 +1,20 @@ +from pathlib import Path + +from .collections import Board, Font, Header, Position, Screen, Size, Tile +from .color import ColorScheme +from .enums import Direction + +BASE_PATH = Path(__file__).resolve().parent.parent.parent.parent + +__all__ = [ + "Board", + "ColorScheme", + "Direction", + "Font", + "Position", + "Size", + "Tile", + "Header", + "Screen", + "BASE_PATH", +] diff --git a/src/utils/collections.py b/src/utils/collections.py new file mode 100644 index 0000000..f317a98 --- /dev/null +++ b/src/utils/collections.py @@ -0,0 +1,52 @@ +from typing import NamedTuple + +from attr import Factory, define, field + + +class Position(NamedTuple): + x: int | float + y: int | float + + +class Size(NamedTuple): + width: int + height: int + + +@define +class Font: + family: str = "Roboto" + size: int = 32 + + +@define +class Border: + width: int + radius: int + + +@define +class Tile: + size: int = 75 + border: Border = Border(size // 20, size // 10) + initial_count: int = 2 + value_probability: float = 0.9 + + +@define +class Board: + len: int = 4 + size: Size = Size(len * Tile().size, len * Tile().size) + pos: Position = Position(Tile().size // 2, Tile().size + Tile().size // 2) + + +@define +class Header: + size: Size = Size(Board().size.width + Tile().size, Tile().size) + + +@define +class Screen: + size: Size = Size( + Header().size.width, Board().size.height + Tile().size + Header().size.height + ) diff --git a/src/utils/color.py b/src/utils/color.py new file mode 100644 index 0000000..646a050 --- /dev/null +++ b/src/utils/color.py @@ -0,0 +1,27 @@ +from enum import Enum + + +class Original: + TILE_0 = "#cdc1b4" + TILE_2 = "#eee4da" + TILE_4 = "#eee1c9" + TILE_8 = "#f3b27a" + TILE_16 = "#f69664" + TILE_32 = "#f77c5f" + TILE_64 = "#f75f3b" + TILE_128 = "#edcf72" + TILE_256 = "#edcc61" + TILE_512 = "#edc850" + TILE_1024 = "#edc53f" + TILE_2048 = "#edc22e" + TILE_ELSE = "#ff0000" + LIGHT_TEXT = "#f9f6f2" + DARK_TEXT = "#776e65" + OTHER = "#000000" + BG = "#faf8ef" + BOARD_BG = "#bbada0" + + +class ColorScheme(Enum): + ORIGINAL = Original + DARK = ... # TODO: Implement dark color scheme diff --git a/src/utils/enums.py b/src/utils/enums.py new file mode 100644 index 0000000..32dedf9 --- /dev/null +++ b/src/utils/enums.py @@ -0,0 +1,18 @@ +from enum import Enum + +from .collections import Position + + +class Direction(Enum): + UP = Position(0, -1) + DOWN = Position(0, 1) + LEFT = Position(-1, 0) + RIGHT = Position(1, 0) + + def __mul__(self, num: int) -> Position: + """Multiply the direction by a constant.""" + return Position(self.value.x * num, self.value.y * num) + + def __imul__(self, num: int) -> tuple[int, int]: + """Multiply the direction by a constant.""" + return Position(self.value.x * num, self.value.y * num)