Skip to content

Commit

Permalink
DOC: Reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
lunathanael committed Aug 19, 2024
1 parent 03d528b commit 631f14d
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/botris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/botris/bots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
...
>>> bot = LeftBot()
"""

from .bot import Bot
from .randombot import RandomBot

Expand Down
2 changes: 1 addition & 1 deletion src/botris/bots/randombot/randombot.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/botris/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,15 +32,13 @@
"cmode",
"cmovegen_traditional",
"cmovegen_smeared",

"CBoard",
"CColorType",
"CPieceType",
"CGame",
"CBotris",

"sky_piece_movegen",
"convex_movegen",
"movegen",
"god_movegen",
]
]
14 changes: 7 additions & 7 deletions src/botris/core/cboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import TYPE_CHECKING

from botris._core import Board

from .cpiece import CPiece


Expand Down Expand Up @@ -111,7 +112,7 @@ def get(self, x: int, y: int) -> int:
The x-coordinate.
y : int (size_t)
The y-coordinate.
Returns:
--------
int
Expand All @@ -127,7 +128,7 @@ def get_column(self, x: int) -> int:
-----------
x : int (size_t)
The x-coordinate.
Returns:
--------
int (u32)
Expand Down Expand Up @@ -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.
Expand All @@ -246,7 +247,7 @@ def full(self, height: int) -> int:
-----------
height : int
The height to check.
Returns:
--------
int (u32)
Expand Down Expand Up @@ -330,9 +331,8 @@ def copy(self) -> CBoard:
"""
pass


if not TYPE_CHECKING:
CBoard = Board

__all__ = [
"CBoard"
]
__all__ = ["CBoard"]
38 changes: 33 additions & 5 deletions src/botris/core/cconstants.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,6 +30,7 @@ class CCoord:
y : int (i8)
The y-coordinate.
"""

def __init__(self, x: int, y: int):
"""
Initialize the coordinate.
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -126,31 +140,45 @@ 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
piece_spawn_height: int = piece_spawn_height


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
Expand All @@ -170,5 +198,5 @@ class CMovement(IntEnum):
"n_minos",
"piece_definitions",
"rot_piece_def",
"piece_spawn_height"
]
"piece_spawn_height",
]
19 changes: 10 additions & 9 deletions src/botris/core/cgame.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -33,7 +35,7 @@ class CGame:
The queue.
mode : CBotris
The Botris mode instance.
Methods:
--------
__init__(self)
Expand Down Expand Up @@ -356,9 +358,8 @@ def copy(self) -> CGame:
"""
pass


if not TYPE_CHECKING:
CGame = Game

__all__ = [
"CGame"
]
__all__ = ["CGame"]
15 changes: 9 additions & 6 deletions src/botris/core/cmode.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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"
]
__all__ = ["CBotris"]
10 changes: 7 additions & 3 deletions src/botris/core/cmovegen_smeared.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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",
]
]
Loading

0 comments on commit 631f14d

Please sign in to comment.