diff --git a/src/botris/__init__.py b/src/botris/__init__.py index 1f6d155..eb40b8f 100644 --- a/src/botris/__init__.py +++ b/src/botris/__init__.py @@ -69,10 +69,11 @@ ... >>> asyncio.run(main()) """ + from . import bots, core, engine, interface +from ._version import __version__ from .engine import TetrisGame from .interface import Interface, connect -from ._version import __version__ __all__ = [ "bots", diff --git a/src/botris/bots/__init__.py b/src/botris/bots/__init__.py index 77266ae..855ccce 100644 --- a/src/botris/bots/__init__.py +++ b/src/botris/bots/__init__.py @@ -18,6 +18,7 @@ ... >>> bot = LeftBot() """ + from .bot import Bot from .randombot import RandomBot diff --git a/src/botris/bots/randombot/randombot.py b/src/botris/bots/randombot/randombot.py index 9230397..a633d64 100644 --- a/src/botris/bots/randombot/randombot.py +++ b/src/botris/bots/randombot/randombot.py @@ -1,5 +1,5 @@ import random -from typing import Awaitable, Dict, List +from typing import Awaitable from botris.bots.bot import Bot from botris.engine import Move, PieceData, TetrisGame diff --git a/src/botris/core/__init__.py b/src/botris/core/__init__.py index 3826b4d..b03f19b 100644 --- a/src/botris/core/__init__.py +++ b/src/botris/core/__init__.py @@ -16,14 +16,14 @@ cmovegen_smeared Contains the move generation functions for smeared movegen. """ -from . import cboard, cconstants, cgame, cmode, cmovegen_traditional, cmovegen_smeared + +from . import cboard, cconstants, cgame, cmode, cmovegen_smeared, cmovegen_traditional from .cboard import CBoard from .cconstants import CColorType, CPieceType from .cgame import CGame from .cmode import CBotris -from .cmovegen_traditional import sky_piece_movegen, convex_movegen -from .cmovegen_smeared import movegen, god_movegen - +from .cmovegen_smeared import god_movegen, movegen +from .cmovegen_traditional import convex_movegen, sky_piece_movegen __all__ = [ "cboard", @@ -32,15 +32,13 @@ "cmode", "cmovegen_traditional", "cmovegen_smeared", - "CBoard", "CColorType", "CPieceType", "CGame", "CBotris", - "sky_piece_movegen", "convex_movegen", "movegen", "god_movegen", -] \ No newline at end of file +] diff --git a/src/botris/core/cboard.py b/src/botris/core/cboard.py index a21ef70..9ba38dc 100644 --- a/src/botris/core/cboard.py +++ b/src/botris/core/cboard.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING from botris._core import Board + from .cpiece import CPiece @@ -111,7 +112,7 @@ def get(self, x: int, y: int) -> int: The x-coordinate. y : int (size_t) The y-coordinate. - + Returns: -------- int @@ -127,7 +128,7 @@ def get_column(self, x: int) -> int: ----------- x : int (size_t) The x-coordinate. - + Returns: -------- int (u32) @@ -237,7 +238,7 @@ def not_empty(self, height: int) -> int: int (u32) A mask of non-empty rows. """ - + def full(self, height: int) -> int: """ Get the number of rows that are matching the height. @@ -246,7 +247,7 @@ def full(self, height: int) -> int: ----------- height : int The height to check. - + Returns: -------- int (u32) @@ -330,9 +331,8 @@ def copy(self) -> CBoard: """ pass + if not TYPE_CHECKING: CBoard = Board -__all__ = [ - "CBoard" -] \ No newline at end of file +__all__ = ["CBoard"] diff --git a/src/botris/core/cconstants.py b/src/botris/core/cconstants.py index 32b66b4..aa48e9e 100644 --- a/src/botris/core/cconstants.py +++ b/src/botris/core/cconstants.py @@ -1,17 +1,24 @@ +from enum import IntEnum, auto from typing import TYPE_CHECKING -from botris._core.constants import n_minos, piece_definitions, rot_piece_def, piece_spawn_height -from enum import IntEnum, auto +from botris._core.constants import ( + n_minos, + piece_definitions, + piece_spawn_height, + rot_piece_def, +) class CspinType(IntEnum): """ An enumeration of the spin types. """ + null = auto() mini = auto() normal = auto() + class CCoord: """ An interface class representing a coordinate on the board. @@ -23,6 +30,7 @@ class CCoord: y : int (i8) The y-coordinate. """ + def __init__(self, x: int, y: int): """ Initialize the coordinate. @@ -84,20 +92,24 @@ def y(self, value: int) -> None: """ pass + class CRotateDirection(IntEnum): """ An enumeration of the rotation directions. """ + North = auto() East = auto() South = auto() West = auto() RotateDirections_N = auto() + class CColorType(IntEnum): """ An enumeration of the color types of pieces. """ + S = auto() Z = auto() J = auto() @@ -111,10 +123,12 @@ class CColorType(IntEnum): Garbage = auto() ColorTypes_N = auto() + class CPieceType(IntEnum): """ An enumeration of the types of pieces. """ + S = CColorType.S Z = CColorType.Z J = CColorType.J @@ -126,23 +140,28 @@ class CPieceType(IntEnum): Empty = CColorType.Empty PieceTypes_N = auto() + class CTurnDirection(IntEnum): """ An enumeration of the turn directions. """ + Left = auto() Right = auto() + class CMovement(IntEnum): """ An enumeration of the movement directions. """ + Left = auto() Right = auto() RotateClockwise = auto() RotateCounterClockwise = auto() SonicDrop = auto() + n_minos: int = n_minos piece_definitions: list[list[CCoord]] = piece_definitions rot_piece_def: list[list[list[CCoord]]] = rot_piece_def @@ -150,7 +169,16 @@ class CMovement(IntEnum): if not TYPE_CHECKING: - from botris._core.constants import spinType, RotationDirection, ColorType, PieceType, TurnDirection, Movement, Coord + from botris._core.constants import ( + ColorType, + Coord, + Movement, + PieceType, + RotationDirection, + TurnDirection, + spinType, + ) + CspinType = spinType CRotateDirection = RotationDirection CColorType = ColorType @@ -170,5 +198,5 @@ class CMovement(IntEnum): "n_minos", "piece_definitions", "rot_piece_def", - "piece_spawn_height" -] \ No newline at end of file + "piece_spawn_height", +] diff --git a/src/botris/core/cgame.py b/src/botris/core/cgame.py index fca4249..9c23a93 100644 --- a/src/botris/core/cgame.py +++ b/src/botris/core/cgame.py @@ -1,16 +1,18 @@ from __future__ import annotations -from typing import Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Optional +from botris._core import Game + +from .cboard import CBoard +from .cconstants import CMovement, CPieceType, CspinType from .cmode import CBotris from .cpiece import CPiece -from .cconstants import CspinType, CMovement, CPieceType -from .cboard import CBoard -from botris._core import Game + class CGame: """ - A Python wrapper for the C++ Game class, where each method calls the corresponding + A Python wrapper for the C++ Game class, where each method calls the corresponding method in the base class. Attributes: @@ -33,7 +35,7 @@ class CGame: The queue. mode : CBotris The Botris mode instance. - + Methods: -------- __init__(self) @@ -356,9 +358,8 @@ def copy(self) -> CGame: """ pass + if not TYPE_CHECKING: CGame = Game -__all__ = [ - "CGame" -] \ No newline at end of file +__all__ = ["CGame"] diff --git a/src/botris/core/cmode.py b/src/botris/core/cmode.py index f3eb334..e198918 100644 --- a/src/botris/core/cmode.py +++ b/src/botris/core/cmode.py @@ -1,8 +1,10 @@ from typing import TYPE_CHECKING -from .cconstants import CspinType from botris._core import Botris +from .cconstants import CspinType + + class CBotris: """ A Python interface for the C++ Botris class, a class holding @@ -41,8 +43,10 @@ def __init__(self): Initialize the Botris class. """ pass - - def points(self, lines: int, spin: CspinType, pc: bool, combo: int, b2b: int) -> int: + + def points( + self, lines: int, spin: CspinType, pc: bool, combo: int, b2b: int + ) -> int: """ Calculate the points based on the number of lines cleared, spin type, and other factors. @@ -66,9 +70,8 @@ def points(self, lines: int, spin: CspinType, pc: bool, combo: int, b2b: int) -> """ pass + if not TYPE_CHECKING: CBotris = Botris -__all__ = [ - "CBotris" -] \ No newline at end of file +__all__ = ["CBotris"] diff --git a/src/botris/core/cmovegen_smeared.py b/src/botris/core/cmovegen_smeared.py index 0220f77..b30a2fb 100644 --- a/src/botris/core/cmovegen_smeared.py +++ b/src/botris/core/cmovegen_smeared.py @@ -1,9 +1,10 @@ from typing import TYPE_CHECKING -from .cconstants import CPieceType from .cboard import CBoard +from .cconstants import CPieceType from .cpiece import CPiece + def movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ Generate the moves for a piece. @@ -23,6 +24,7 @@ def movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ pass + def god_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ Generate the moves for a piece. @@ -42,12 +44,14 @@ def god_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ pass + if not TYPE_CHECKING: - from botris._core.smeared_movegen import movegen, god_movegen + from botris._core.smeared_movegen import god_movegen, movegen + movegen = movegen god_movegen = god_movegen __all__ = [ "movegen", "god_movegen", -] \ No newline at end of file +] diff --git a/src/botris/core/cmovegen_traditional.py b/src/botris/core/cmovegen_traditional.py index 239c2c4..8c3dd58 100644 --- a/src/botris/core/cmovegen_traditional.py +++ b/src/botris/core/cmovegen_traditional.py @@ -1,9 +1,10 @@ from typing import TYPE_CHECKING -from .cconstants import CPieceType from .cboard import CBoard +from .cconstants import CPieceType from .cpiece import CPiece + def sky_piece_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ Generate the moves for a sky piece. @@ -24,6 +25,7 @@ def sky_piece_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ pass + def convex_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ Generate the moves for a convex piece. @@ -44,12 +46,14 @@ def convex_movegen(board: CBoard, piece_type: CPieceType) -> list[CPiece]: """ pass + if not TYPE_CHECKING: - from botris._core.traditional_movegen import sky_piece_movegen, convex_movegen + from botris._core.traditional_movegen import convex_movegen, sky_piece_movegen + sky_piece_movegen = sky_piece_movegen convex_movegen = convex_movegen __all__ = [ "sky_piece_movegen", "convex_movegen", -] \ No newline at end of file +] diff --git a/src/botris/core/cpiece.py b/src/botris/core/cpiece.py index f243920..373473a 100644 --- a/src/botris/core/cpiece.py +++ b/src/botris/core/cpiece.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .cconstants import CPieceType, CRotateDirection, CCoord, CspinType, CTurnDirection - from typing import TYPE_CHECKING +from .cconstants import CCoord, CPieceType, CRotateDirection, CspinType, CTurnDirection + class CPiece: """ @@ -207,7 +207,9 @@ def __init__(self, type: CPieceType, dir: CRotateDirection, pos: CCoord): """ pass - def __init__(self, type: CPieceType, dir: CRotateDirection, pos: CCoord, spn: CspinType): + def __init__( + self, type: CPieceType, dir: CRotateDirection, pos: CCoord, spn: CspinType + ): """ Initialize the piece. @@ -279,10 +281,12 @@ def copy(self) -> CPiece: """ pass + if not TYPE_CHECKING: from botris._core import Piece + CPiece = Piece __all__ = [ "CPiece", -] \ No newline at end of file +] diff --git a/src/botris/engine/__init__.py b/src/botris/engine/__init__.py index 9b39a59..c84f390 100644 --- a/src/botris/engine/__init__.py +++ b/src/botris/engine/__init__.py @@ -11,6 +11,7 @@ Contains utility functions used by the engine. """ + from . import models, pieces, utils from .models import ( MOVES, diff --git a/src/botris/engine/tetris.py b/src/botris/engine/tetris.py index f35e899..40f4df2 100644 --- a/src/botris/engine/tetris.py +++ b/src/botris/engine/tetris.py @@ -723,8 +723,7 @@ def queue_attack(self, attack: int) -> None: The number of garbage lines to send to the player. """ public_garbage_lines: List[PublicGarbageLine] = [ - PublicGarbageLine(delay=self.options.garbage_delay) - for _ in range(attack) + PublicGarbageLine(delay=self.options.garbage_delay) for _ in range(attack) ] garbage_lines: List[GarbageLine] = generate_garbage( public_garbage_lines, diff --git a/src/botris/interface/__init__.py b/src/botris/interface/__init__.py index 1cadc27..06554ea 100644 --- a/src/botris/interface/__init__.py +++ b/src/botris/interface/__init__.py @@ -36,6 +36,7 @@ ... ) ... """ + from . import models from .handlers import construct_message_handler from .interface import Interface, connect