def test_dont_rate_threeway_team_matches(): p1, p2, p3 = MockPlayer(), MockPlayer(), MockPlayer() players_by_team = {2: [p1], 3: [p2], 4: [p3]} outcome_py_player = { p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT, p3: GameOutcome.DEFEAT, } rater = GameRater(players_by_team, outcome_py_player) with pytest.raises(GameRatingError): rater.compute_rating()
def test_dont_rate_pure_ffa_matches_with_more_than_two_players(): FFA_TEAM = 1 p1, p2, p3 = MockPlayer(), MockPlayer(), MockPlayer() players_by_team = {FFA_TEAM: [p1, p2, p3]} outcome_py_player = { p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT, p3: GameOutcome.DEFEAT, } rater = GameRater(players_by_team, outcome_py_player) with pytest.raises(GameRatingError): rater.compute_rating()
def test_dont_rate_partial_ffa_matches(): FFA_TEAM = 1 p1, p2, p3, p4 = MockPlayer(), MockPlayer(), MockPlayer(), MockPlayer() players_by_team = {FFA_TEAM: [p1, p3], 2: [p2, p4]} outcome_py_player = { p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT, p3: GameOutcome.DEFEAT, p4: GameOutcome.DEFEAT, } rater = GameRater(players_by_team, outcome_py_player) with pytest.raises(GameRatingError): rater.compute_rating()
def test_compute_rating(): p1, p2 = MockPlayer(), MockPlayer() players_by_team = {2: [p1], 3: [p2]} outcome_py_player = {p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT} rater = GameRater(players_by_team, outcome_py_player) result = rater.compute_rating() for team in result: for player, new_rating in team.items(): assert new_rating != Rating(*player.ratings[RatingType.GLOBAL])
def test_compute_rating_of_two_player_ffa_match_if_none_chose_a_team(): FFA_TEAM = 1 p1, p2 = MockPlayer(), MockPlayer() players_by_team = {FFA_TEAM: [p1, p2]} outcome_py_player = {p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT} rater = GameRater(players_by_team, outcome_py_player) result = rater.compute_rating() for team in result: for player, new_rating in team.items(): assert new_rating != Rating(*player.ratings[RatingType.GLOBAL])
def test_compute_rating_for_single_ffa_player_vs_a_team(): FFA_TEAM = 1 p1, p2, p3 = MockPlayer(), MockPlayer(), MockPlayer() players_by_team = {FFA_TEAM: [p1], 2: [p2, p3]} outcome_py_player = { p1: GameOutcome.VICTORY, p2: GameOutcome.DEFEAT, p3: GameOutcome.DEFEAT, } rater = GameRater(players_by_team, outcome_py_player) result = rater.compute_rating() for team in result: for player, new_rating in team.items(): assert new_rating != Rating(*player.ratings[RatingType.GLOBAL])
def compute_rating(self, rating=RatingType.GLOBAL) -> Dict[Player, Rating]: """ Compute new ratings :param rating: Rating type :return: rating groups of the form: >>> p1,p2,p3,p4 = Player() >>> [{p1: p1.rating, p2: p2.rating}, {p3: p3.rating, p4: p4.rating}] """ assert self.state is GameState.LIVE or self.state is GameState.ENDED if None in self.teams: raise GameError( "Missing team for at least one player. (player, team): {}". format([(player, self.get_player_option(player.id, 'Team')) for player in self.players])) outcome_by_player = { player: self.get_player_outcome(player) for player in self.players } rater = GameRater(self.players_by_team, outcome_by_player, rating) return rater.compute_rating()