def test_score_bull_winning_hand(self): """Score using BULL as a wildcard is correct""" commodity = 'oats' cards = [commodity] * (config.COMMODITIES_PER_HAND - 1) cards.append(config.BULL) score = util.score_hand(cards) self.assertEqual(score, config.COMMODITY_VALUES[commodity])
def test_score_bonus_winning_hand(self): """Score with a double bonus for BULL is correct""" commodity = 'coffee' cards = [commodity] * config.COMMODITIES_PER_HAND cards.append(config.BULL) score = util.score_hand(cards) self.assertEqual(score, config.COMMODITY_VALUES[commodity] * 2)
def update_scores(self): """Updates player scores at end of a round, sets winner if any.""" for player in self.players: score = util.score_hand(self.player_info[player]['cards']) self.player_info[player]['score'] += score if self.player_info[player]['score'] >= config.WINNING_SCORE: self.winner = player
def update_scores(self): """Updates player scores, checks if there is a game winner. """ for uid, data in self.player_data.iteritems(): data['score'] += util.score_hand(data['cards']) if data['score'] >= config.WINNING_SCORE: self.game_winner = self.round_winner print 'ROUND WINNER IS {0}'.format(self.player_data[self.round_winner]['name']) self.debug()
def update_scores(self): """Updates player scores, checks if there is a game winner. """ for uid, data in self.player_data.iteritems(): data['score'] += util.score_hand(data['cards']) if data['score'] >= config.WINNING_SCORE: self.game_winner = self.round_winner print 'ROUND WINNER IS {0}'.format( self.player_data[self.round_winner]['name']) self.debug()
def test_score_dual_penalty(self): """A non-winning hand with both bull and bear is super penalized""" cards = ['barley'] * 4 + ['oranges'] * 3 + [config.BULL, config.BEAR] score = util.score_hand(cards) self.assertEqual(score, -(config.BEAR_PENALTY + config.BULL_PENALTY))
def test_score_bear_penalty(self): """A non-winning hand with a bear has a negative score""" cards = ['barley'] * 4 + ['oranges'] * 3 + ['soybeans', config.BEAR] score = util.score_hand(cards) self.assertEqual(score, -config.BEAR_PENALTY)
def test_score_neutral_hand(self): """A neutral hand has a score of 0""" cards = ['barley'] * 4 + ['oranges'] * 3 + ['soybeans', 'oats'] score = util.score_hand(cards) self.assertEqual(score, 0)
def test_score_regular_winning_hand(self): """Score for a regular winning hand is correct""" commodity = 'wheat' cards = [commodity] * config.COMMODITIES_PER_HAND score = util.score_hand(cards) self.assertEqual(score, config.COMMODITY_VALUES[commodity])
def test_score_dual_penalty(self): """A non-winning hand with both bull and bear is super penalized""" cards = ['barley'] * 4 + ['oranges'] * 3 + [config.BULL, config.BEAR] score = util.score_hand(cards) self.assertEqual(score, -(config.BEAR_PENALTY+config.BULL_PENALTY))