ChessWithQuests

Player (model.game.player)

model.game.player

Player representation tracking game side, user association, and Elo ratings.

Player

Represents a chess participant associated with a side and an optional user profile.

Source code in src/model/game/player.py
class Player:
    """Represents a chess participant associated with a side and an optional user profile."""

    def __init__(self, color: int, user: Optional[Any] = None):
        """Initialize a Player.

        Args:
            color: Side color (1 for White, -1 for Black).
            user: Optional User profile instance.
        """
        self.color = color
        self.user = user

    def getColor(self) -> int:
        """Get the player's color identifier.

        Returns:
            Color identifier (1 for White, -1 for Black).
        """
        return self.color

    def getUser(self) -> Optional[Any]:
        """Get the associated user profile.

        Returns:
            User profile object or None if not linked.
        """
        return self.user

    def setUser(self, user: Any) -> None:
        """Associate a user profile with this player.

        Args:
            user: User profile instance.
        """
        self.user = user

    def getEloRating(self) -> int:
        """Get the Elo rating of the player from their user profile.

        Returns:
            Integer Elo rating, defaulting to 1200 if unrated.
        """
        if self.user is not None:
            if hasattr(self.user, "elo"):
                return int(self.user.elo)
            if hasattr(self.user, "getEloRating"):
                return int(self.user.getEloRating())
        return 1200

    # Aliases
    get_elo_rating = getEloRating
    get_color = getColor
    get_user = getUser
__init__(color, user=None)

Initialize a Player.

Parameters:

Name Type Description Default
color int

Side color (1 for White, -1 for Black).

required
user Optional[Any]

Optional User profile instance.

None
Source code in src/model/game/player.py
def __init__(self, color: int, user: Optional[Any] = None):
    """Initialize a Player.

    Args:
        color: Side color (1 for White, -1 for Black).
        user: Optional User profile instance.
    """
    self.color = color
    self.user = user
getColor()

Get the player's color identifier.

Returns:

Type Description
int

Color identifier (1 for White, -1 for Black).

Source code in src/model/game/player.py
def getColor(self) -> int:
    """Get the player's color identifier.

    Returns:
        Color identifier (1 for White, -1 for Black).
    """
    return self.color
getEloRating()

Get the Elo rating of the player from their user profile.

Returns:

Type Description
int

Integer Elo rating, defaulting to 1200 if unrated.

Source code in src/model/game/player.py
def getEloRating(self) -> int:
    """Get the Elo rating of the player from their user profile.

    Returns:
        Integer Elo rating, defaulting to 1200 if unrated.
    """
    if self.user is not None:
        if hasattr(self.user, "elo"):
            return int(self.user.elo)
        if hasattr(self.user, "getEloRating"):
            return int(self.user.getEloRating())
    return 1200
getUser()

Get the associated user profile.

Returns:

Type Description
Optional[Any]

User profile object or None if not linked.

Source code in src/model/game/player.py
def getUser(self) -> Optional[Any]:
    """Get the associated user profile.

    Returns:
        User profile object or None if not linked.
    """
    return self.user
setUser(user)

Associate a user profile with this player.

Parameters:

Name Type Description Default
user Any

User profile instance.

required
Source code in src/model/game/player.py
def setUser(self, user: Any) -> None:
    """Associate a user profile with this player.

    Args:
        user: User profile instance.
    """
    self.user = user
ChessWithQuests