Example #1
0
	def calculateNewRatings(self, gameInfo, teams, teamRanks):
		'''Implementation for a 2 player game. returns a list of tuples of (player, newRating)'''
		argumentNotNone(gameInfo, "gameInfo")
		self._validateTeamCountAndPlayersCountPerTeam(teams)
		teams, teamRanks = sortByRank(teams, teamRanks)

		winningTeamPlayers = teams[0].asListOfTuples
		#since we know each team has one player, we know the player is the first one
		winningPlayer = winningTeamPlayers[0][0]
		winningPlayerOldRating = winningTeamPlayers[0][1]
		
		losingTeamPlayers = teams[1].asListOfTuples
		losingPlayer = losingTeamPlayers[0][0]
		losingPlayerOldRating = losingTeamPlayers[0][1]
		
		wasDraw = (teamRanks[0] == teamRanks[1])
		results = list()
		results.append(
			(winningPlayer, 
			self._calculateNewRating(
				gameInfo, winningPlayerOldRating, losingPlayerOldRating, PairwiseComparison.DRAW if wasDraw else PairwiseComparison.WIN)
		))
		results.append(
			(losingPlayer,
			self._calculateNewRating(
				gameInfo, losingPlayerOldRating, winningPlayerOldRating, PairwiseComparison.DRAW if wasDraw else PairwiseComparison.LOSE)
		))
		return results
Example #2
0
	def calculateNewRatings(self, gameInfo, teams, teamRanks):
		argumentNotNone(gameInfo, "gameInfo")
		self._validateTeamCountAndPlayersCountPerTeam(teams)
		teams, teamRanks = sortByRank(teams, teamRanks)
		
		factorGraph = TrueSkillFactorGraph(gameInfo, teams, teamRanks)
		factorGraph.buildGraph()
		factorGraph.runSchedule()	
		
		return factorGraph.getUpdatedRatings()
Example #3
0
	def calculateNewRatings(self, gameInfo, teams, teamRanks):
		'''Implementation for a 2 team game. Returns a list of tuples of (player, rating)'''
		argumentNotNone(gameInfo, "gameInfo")
		self._validateTeamCountAndPlayersCountPerTeam(teams)
		teams, teamRanks = sortByRank(teams, teamRanks)
		
		team1 = teams[0]
		team2 = teams[1]
		
		wasDraw = (teamRanks[0] == teamRanks[1])
		
		results = list()
		self._updatePlayerRatings(gameInfo, results, team1, team2, PairwiseComparison.DRAW if wasDraw else PairwiseComparison.WIN)
		self._updatePlayerRatings(gameInfo, results, team2, team1, PairwiseComparison.DRAW if wasDraw else PairwiseComparison.LOSE)
		return results
Example #4
0
	def test_sortUnsortedTest(self):
		people = ['five', 'two1', 'two2', 'one', 'four']
		ranks = [5, 2, 2, 1, 4]
		people = sortByRank(people, ranks)
		self.assertEqual(people, (['one', 'two1', 'two2', 'four', 'five'], [1, 2, 2, 4, 5]))
Example #5
0
	def test_sortAlreadySortedTest(self):
		people = ['one', 'two', 'three']
		ranks = [1, 2, 3]
		people = sortByRank(people, ranks)
		self.assertEqual(people, (['one', 'two', 'three'], [1, 2, 3]))