[Python] Python Uno Card Game methods next_game() & skip_next_player() not working correctly...

Discussão em 'Python' iniciado por Stack, Abril 2, 2025.

  1. Stack

    Stack Membro Participativo

    So I am building a uno card game in python I've got 4 files player.py, card.py, gameboard.py & game.py (the main one) & I facing a problem in game.py as its not able to pass all my test cases, so in test case there is an arraylist of 4 players [Alice, Bob, Charlie, David] now what i want is that when initially current_player is None & current_player_index is also None, now when next_player is called when current_player is none then it returns, just returns dosen't update current_player_index & just returns the [0] means very first player Alice from the array list, & if not none then it should return the next player.

    def next_player(self) -> Player:
    """
    Method to get the next player

    Args:
    None

    Returns:
    Player: The next player

    Complexity:
    Best Case Complexity:
    Worst Case Complexity:
    """
    print(self.current_player_index)

    if self.current_player_index == None:
    return self.players[0]
    return self.players[(self.current_player_index + 1) % len(self.players)]


    then similarly for skip_next_player , if current_player_index is None, then it should skip alice & make current_player_index = Bob the [1] in array & if not none then it should modify current_player_index as the next to next player. (this time we have to modify current_player_index not just return)

    def skip_next_player(self) -> None:
    """
    Method to skip the next player in the game

    Args:
    None

    Returns:
    None

    Complexity:
    Best Case Complexity:
    Worst Case Complexity:
    """
    if self.current_player_index == None:
    self.current_player = self.players[1]
    else:
    self.current_player = (self.current_player_index + 2) % len(self.players)


    But the problem is if it's none then it's working good but if it's none then it's not! where am i making the mistake?

    Have a look at my __init__ as well:

    class Game:
    """
    Game class to play the game
    """

    def __init__(self) -> None:
    """
    Constructor for the Game class

    Args:
    None

    Returns:
    None

    Complexity:
    Best Case Complexity:
    Worst Case Complexity:
    """

    self.players = ArrayList()
    self.current_player_index = None
    self.turn_direction = 1
    self.current_player = None
    self.current_color = None
    self.current_label = None
    self.game_board = GameBoard(ArrayList())

    Continue reading...

Compartilhe esta Página