def test_basic(self): cards = Stack(cards=[Card("3", "Diamonds"), Card("3", "Clubs")]) self.assertEqual(get_money_lost(cards, 5, 20), 10) cards = Stack(cards=[ Card("3", "Diamonds"), Card("3", "Clubs"), Card("3", "Hearts") ]) self.assertEqual(get_money_lost(cards, 5, 20), 15)
def test_four_of_a_kind(self): cards = Stack(cards=[ Card("3", "Diamonds"), Card("3", "Clubs"), Card("3", "Hearts"), Card("3", "Spades"), Card("4", "Diamonds") ]) self.assertEqual(get_money_lost(cards, 5, 20), 50) cards = Stack(cards=[ Card("3", "Diamonds"), Card("3", "Clubs"), Card("3", "Hearts"), Card("3", "Spades"), Card("4", "Diamonds"), Card("5", "Spades") ]) self.assertEqual(get_money_lost(cards, 5, 20), 60)
def test_straight_flush(self): cards = Stack(cards=[ Card("3", "Diamonds"), Card("4", "Diamonds"), Card("5", "Diamonds"), Card("6", "Diamonds"), Card("7", "Diamonds") ]) self.assertEqual(get_money_lost(cards, 5, 20), 50) cards = Stack(cards=[ Card("3", "Diamonds"), Card("4", "Diamonds"), Card("5", "Diamonds"), Card("6", "Diamonds"), Card("7", "Diamonds"), Card("7", "Clubs") ]) self.assertEqual(get_money_lost(cards, 5, 20), 60)
def test_ten_cards(self): cards = Stack(cards=[ Card("3", "Diamonds"), Card("4", "Clubs"), Card("5", "Diamonds"), Card("6", "Clubs"), Card("7", "Diamonds"), Card("8", "Clubs"), Card("9", "Diamonds"), Card("10", "Clubs"), Card("Jack", "Diamonds"), Card("Queen", "Clubs") ]) self.assertEqual(get_money_lost(cards, 5, 20), 100)
def test_all_thirteen_cards(self): cards = Stack(cards=[ Card("3", "Diamonds"), Card("4", "Clubs"), Card("5", "Diamonds"), Card("6", "Clubs"), Card("7", "Diamonds"), Card("8", "Clubs"), Card("9", "Diamonds"), Card("10", "Clubs"), Card("Jack", "Diamonds"), Card("Queen", "Clubs"), Card("King", "Diamonds"), Card("Ace", "Clubs"), Card("3", "Hearts") ]) self.assertEqual(get_money_lost(cards, 5, 39), 520)
def test_has_two(self): cards = Stack(cards=[Card("2", "Diamonds")]) self.assertEqual(get_money_lost(cards, 5, 20), 10) cards = Stack(cards=[Card("2", "Diamonds"), Card("2", "Clubs")]) self.assertEqual(get_money_lost(cards, 5, 20), 40)
def update_stats(group_tele_id, won_player, job_queue): session = scoped_session(session_factory) s = session() money_mode = s.query(GroupSetting.money_mode).filter(GroupSetting.tele_id == group_tele_id).first()[0] players = s.query(Player).filter(Player.group_tele_id == group_tele_id).all() group_stat = s.query(GroupStat).filter(GroupStat.tele_id == group_tele_id).first() num_cards_left = sum([player.cards.size for player in players]) money_earned = 0 if group_stat: group_stat.num_games += 1 else: try: group_stat = GroupStat(tele_id=group_tele_id, num_games=1, best_win_rate=0, most_money_earned=0) s.add(group_stat) except: s.rollback() session.remove() return for player in players: player_stat = s.query(PlayerStat).filter(PlayerStat.tele_id == player.player_tele_id).first() if player_stat: player_stat.num_games += 1 player_stat.num_cards += 13 - player.cards.size player_stat.num_games_won += 1 if player.player_id == won_player else 0 player_stat.win_rate = player_stat.num_games_won / player_stat.num_games * 100 else: try: player_stat = PlayerStat(tele_id=player.player_tele_id, player_name=player.player_name, num_games=1, num_cards=13 - player.cards.size, money=init_money, money_earned=0) player_stat.num_games_won = 1 if player.player_id == won_player else 0 player_stat.win_rate = player_stat.num_games_won / player_stat.num_games * 100 s.add(player_stat) except: s.rollback() session.remove() return if money_mode and player.player_id != won_player: money_lost = get_money_lost(player.cards, card_money, num_cards_left) player_stat.money -= money_lost player_stat.money = 0 if player_stat.money < 0 else player_stat.money player_stat.money_earned -= money_lost money_earned += money_lost if player_stat.money == 0: job = job_queue.run_once(recharge_money, recharge_delay, context=player.player_tele_id) queued_jobs[player.player_tele_id] = job recharge_times[player.player_tele_id] = arrow.now() if player_stat.win_rate > group_stat.best_win_rate: group_stat.best_win_rate = player_stat.win_rate group_stat.best_win_rate_player = player.player_name if player_stat.money_earned > group_stat.most_money_earned: group_stat.most_money_earned = player_stat.money_earned group_stat.most_money_earned_player = player.player_name if money_mode: player_stat = s.query(PlayerStat).\ filter(PlayerStat.tele_id == Player.player_tele_id, Player.group_tele_id == group_tele_id, Player.player_id == won_player).first() player_stat.money += money_earned player_stat.money_earned += money_earned s.commit() session.remove()