Exemple #1
0
def check(game: Game, message: discord.Message) -> List[str]:
    if game.state == GameState.NO_GAME:
        return [
            "No game has been started yet. Message `.p newgame` to start one."
        ]
    elif game.state == GameState.WAITING:
        return ["You can't check because the game hasn't started yet."]
    elif not game.is_player(message.author):
        return [
            "You can't check, because you're not playing, "
            f"{message.author.name}."
        ]
    elif game.state == GameState.NO_HANDS:
        return ["You can't check because the hands haven't been dealt yet."]
    elif game.current_player.user != message.author:
        return [
            f"You can't check, {message.author.name}, because it's "
            f"{game.current_player.user.name}'s turn."
        ]
    elif game.current_player.cur_bet != game.cur_bet:
        return [
            f"You can't check, {message.author.name} because you need to "
            f"put in ${game.cur_bet - game.current_player.cur_bet} to "
            "call."
        ]
    else:
        return game.check()
Exemple #2
0
def raise_bet(game: Game, message: discord.Message) -> List[str]:
    if game.state == GameState.NO_GAME:
        return ["No game has been started yet. Message `.p newgame` to start one."]
    elif game.state == GameState.WAITING:
        return ["You can't raise because the game hasn't started yet."]
    elif not game.is_player(message.author):
        return ["You can't raise, because you're not playing, " f"{message.author.name}."]
    elif game.state == GameState.NO_HANDS:
        return ["You can't raise because the hands haven't been dealt yet."]
    elif game.current_player.user != message.author:
        return [f"You can't raise, {message.author.name}, because it's " f"{game.current_player.name}'s turn."]

    tokens = message.content.split()
    if len(tokens) < 3:
        return ["Please follow `.p raise` with the amount that you would like to raise it by."]
    try:
        amount = int(tokens[2])
        if amount < 0:
            return ["You cannot raise by a negative amount."]
        elif game.cur_bet >= game.current_player.max_bet:
            return ["You don't have enough money to raise the current bet " f"of ${game.cur_bet}."]
        elif game.cur_bet + amount > game.current_player.max_bet:
            return [
                f"You don't have enough money to raise by ${amount}.",
                "The most you can raise it by is " f"${game.current_player.max_bet - game.cur_bet}.",
            ]
        return game.raise_bet(amount)
    except ValueError:
        return ["Please follow `.p raise` with an integer. " f"'{tokens[2]}' is not an integer."]
Exemple #3
0
def call_bet(game: Game, message: discord.Message) -> List[str]:
    if game.state == GameState.NO_GAME:
        return ["No game has been started yet. Message `.p newgame` to start one."]
    elif game.state == GameState.WAITING:
        return ["You can't call any bets because the game hasn't started yet."]
    elif not game.is_player(message.author):
        return ["You can't call, because you're not playing, " f"{message.author.name}."]
    elif game.state == GameState.NO_HANDS:
        return ["You can't call any bets because the hands haven't been " "dealt yet."]
    elif game.current_player.user != message.author:
        return [f"You can't call {message.author.name}, because it's " f"{game.current_player.user.name}'s turn."]
    else:
        return game.call()
Exemple #4
0
def start_game(game: Game, message: discord.Message) -> List[str]:
    if game.state == GameState.NO_GAME:
        return ["Message `.p newgame` if you would like to start a new game."]
    elif game.state != GameState.WAITING:
        return [f"The game has already started, {message.author.name}.", "It can't be started twice."]
    elif not game.is_player(message.author):
        return [
            f"You are not a part of that game yet, {message.author.name}.",
            "Please message join if you are interested in playing.",
        ]
    elif len(game.players) < 2:
        return ["The game must have at least two players before " "it can be started."]
    else:
        return game.start()