def __showdown(self, state): winners, hand_info, prize_map = GameEvaluator.judge(state["table"]) self.__prize_to_winners(state["table"].seats.players, prize_map) result_message = MessageBuilder.build_round_result_message(state["round_count"], winners, hand_info, state) state["table"].reset() state["street"] += 1 return state, [(-1, result_message)]
def test_judge_without_allin(self): gen_player = lambda acc, _: acc + [self.__create_player_with_pay_info("", 5, PayInfo.PAY_TILL_END)] players = reduce(gen_player, range(3), []) table = self.__setup_table(players) mock_eval_hand_return = [0,1,0]*3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(1, len(winner)) self.true(players[1] in winner) self.eq(15, prize_map[1])
def test_judge_with_allin_when_allin_does_not_win(self): players = self.__setup_players_for_judge() table = self.__setup_table(players) mock_eval_hand_return = [2,1,0]*3 + [2,0] + [2] with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(2, hand_info[0]["hand"]["hole"]["low"]) self.eq(1, hand_info[1]["hand"]["hole"]["low"]) self.eq(0, hand_info[2]["hand"]["hole"]["low"]) self.eq(100, prize_map[0]) self.eq(0, prize_map[1]) self.eq(0, prize_map[2])
def test_judge_with_allin_when_allin_does_not_win(self): players = self.__setup_players_for_judge() table = self.__setup_table(players) mock_eval_hand_return = [2, 1, 0] * 3 + [2, 0] + [2] with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(2, hand_info[0]['hand']['hole']['low']) self.eq(1, hand_info[1]['hand']['hole']['low']) self.eq(0, hand_info[2]['hand']['hole']['low']) self.eq(100, prize_map[0]) self.eq(0, prize_map[1]) self.eq(0, prize_map[2])
def test_judge_without_allin(self): def gen_player(acc, _): return acc + [self.__create_player_with_pay_info('', 5, PayInfo.PLAY_TILL_END)] players = reduce(gen_player, range(3), []) table = self.__setup_table(players) mock_eval_hand_return = [0, 1, 0] * 3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(1, len(winner)) self.true(players[1] in winner) self.eq(15, prize_map[1])
def test_judge_without_allin_but_winner_folded(self): gen_player = lambda acc, _: acc + [self.__create_player_with_pay_info("", 5, PayInfo.PAY_TILL_END)] players = reduce(gen_player, range(3), []) players[1].pay_info.update_to_fold() table = self.__setup_table(players) mock_eval_hand_return = [0,0]*4 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(2, len(winner)) self.eq("HIGHCARD", hand_info[0]["hand"]["hand"]["strength"]) self.eq("HIGHCARD", hand_info[1]["hand"]["hand"]["strength"]) self.eq(7, prize_map[0]) self.eq(0, prize_map[1]) self.eq(7, prize_map[2])
def test_judge_with_allin_when_allin_wins_case2(self): players = self.__setup_players_for_judge() table = self.__setup_table(players) mock_eval_hand_return = [1, 2, 0] * 3 + [1, 0] + [0] with patch( 'pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(1, hand_info[0]["hand"]["hole"]["low"]) self.eq(2, hand_info[1]["hand"]["hole"]["low"]) self.eq(0, hand_info[2]["hand"]["hole"]["low"]) self.eq(40, prize_map[0]) self.eq(60, prize_map[1]) self.eq(0, prize_map[2])
def test_judge_without_allin_but_winner_folded(self): def gen_player(acc, _): return acc + [self.__create_player_with_pay_info('', 5, PayInfo.PLAY_TILL_END)] players = reduce(gen_player, range(3), []) players[1].pay_info.update_to_fold() table = self.__setup_table(players) mock_eval_hand_return = [0, 0] * 4 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_eval_hand_return): winner, hand_info, prize_map = GameEvaluator.judge(table) self.eq(2, len(winner)) self.eq('HIGHCARD', hand_info[0]['hand']['hand']['strength']) self.eq('HIGHCARD', hand_info[1]['hand']['hand']['strength']) self.eq(7.5, prize_map[0]) self.eq(0, prize_map[1]) self.eq(7.5, prize_map[2])