Exemple #1
0
 def __init__(self):
     self.game = Game()
     # self.game_actions={
     # "Add player": self.add_player,
     # "Get players": self.get_players,
     # "Get player": self.get_player,
     # "Start game": self.start_game,
     # "Player action": self.player_action,
     # "Get state": self.get_game_state
     # }
     self.game_state = None
     self.my_player = None
    def test_check_two_players_left_one_folded(self):

        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))
        game.add_player(Player("Tyna"))

        game.players[1].folded = True

        result = game.check_number_of_players_left()
        self.assertEqual(result, 2)
Exemple #3
0
    def test_check_betting_fished_true_players_inactive(self):
        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))
        game.add_player(Player("Tyna"))
        game.players[0].bet = 220
        game.players[1].bet = 220
        game.players[2].bet = 0
        game.players[0].bet_placed = True
        game.players[1].bet_placed = True
        game.players[2].active = False

        result = game.check_betting_fished()

        self.assertEqual(result, True)
    def test_check_one_player_left_one_inactive(self):

        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))

        game.players[1].active = False

        result = game.check_number_of_players_left()
        self.assertEqual(result, 1)
Exemple #5
0
 def test_game(self):
     game = Game()
     player = Player("tyna")
     player2 = Player("pawel")
     game.players = [player, player2]
     game.current_player = player
     game.player_action({'Action name': 'Bet', 'Amount': 200})
Exemple #6
0
    def test_check_betting_fished_true_player_all_in(self):
        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))
        game.players[0].bet = 0
        game.players[1].bet = 0
        game.players[0].all_in_state = True

        result = game.check_betting_fished()

        self.assertEqual(result, True)
Exemple #7
0
    def test_check_betting_fished_false_betting_not_ended(self):
        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))
        game.players[0].bet = 0
        game.players[1].bet = 0
        game.players[0].bet_placed = True
        game.players[1].bet_placed = False

        result = game.check_betting_fished()

        self.assertEqual(result, False)
Exemple #8
0
    def test_check_betting_fished_all_200_true(self):
        # Arrange
        game = Game()
        game.add_player(Player("Pawel"))
        game.add_player(Player("Karolina"))
        game.players[0].bet = 200
        game.players[1].bet = 200
        game.players[0].bet_placed = True
        game.players[1].bet_placed = True

        # Act(?)
        result = game.check_betting_fished()

        # Assert
        self.assertEqual(result, True)
Exemple #9
0
class GameServiceLocal:
    def __init__(self):
        self.game = Game()
        # self.game_actions={
        # "Add player": self.add_player,
        # "Get players": self.get_players,
        # "Get player": self.get_player,
        # "Start game": self.start_game,
        # "Player action": self.player_action,
        # "Get state": self.get_game_state
        # }
        self.game_state = None
        self.my_player = None

    def setup_api(self):
        from pokerthegame.api import utils as game_server
        game_server.game_service = self

    def get_players(self, params):
        return self.game.players

    def add_player(self, params):
        # self.game.add_player(params["player name"])
        self.my_player = self.game.add_player(params)
        return self.my_player

    def start_game(self, params):
        self.game.initialize_round()

    def get_player(self, params):
        self.game.get_player(params["player name"])

    def set_player_ready(self, params):
        return self.game.set_player_ready(params)

    def player_action(self, cmd, player):
        command_parser = command.CommandParser(
            self.game.get_current_available_actions(player))
        return command_parser.parse_and_execute(cmd, self.game.player_action,
                                                player)

    def get_game_results(self):
        result = self.game.game_results_rich
        return result

    def get_available_actions(self, player):
        return self.game.get_current_available_actions(player)

    def get_game_state(self, params):
        if self.game.current_player:
            current_player_name = self.game.current_player.name
        else:
            current_player_name = ""

        my_player = params["player"]

        if self.game.started:
            self.game_state = GameState(
                "Started", self.game.table, self.game.get_players(my_player),
                current_player_name,
                self.game.get_current_available_actions(my_player),
                self.game.round_no, self.game.pot, None)
        elif not self.game.finished:
            self.game_state = GameState(
                state="Waiting",
                table=self.game.table,
                players=self.game.players,
                current_player=current_player_name,
                available_actions=self.game.get_current_available_actions(
                    my_player),
                round_no=self.game.round_no,
                pot=self.game.pot,
                game_results=self.get_game_results())
        else:
            self.game_state = GameState(state="Finished",
                                        table=self.game.table,
                                        players=self.game.players,
                                        current_player=current_player_name,
                                        available_actions=[],
                                        round_no=self.game.round_no,
                                        pot=self.game.pot,
                                        game_results=self.get_game_results())

        return self.game_state
Exemple #10
0
    def test_bypass_player_all_in(self):
        game = Game()
        game.add_player("Pawel")
        game.add_player("Karolina")
        game.add_player("Tyna")
        game.check_game_state()
        game.players[1].all_in_state = True

        game.check_game_state()

        self.assertEqual(game.current_player, game.players[2])
Exemple #11
0
    def test_bypass_next_player(self):
        game = Game()
        game.add_player("Pawel")
        game.add_player("Karolina")
        game.add_player("Tyna")

        game.check_game_state()

        game.check_game_state()

        self.assertEqual(game.current_player.name, game.players[1].name)