Exemple #1
0
// Calculates new ratings based on the prior ratings and team ranks use 1 for first place, repeat the number for a tie (e.g. 1, 2, 2).
func (calc *TwoPlayerCalc) CalcNewRatings(gi *skills.GameInfo, teams []skills.Team, ranks ...int) skills.PlayerRatings {
	newSkills := make(map[interface{}]skills.Rating)

	// Basic argument checking
	validateTeamCount(teams, twoPlayerTeamRange)
	validatePlayersPerTeam(teams, twoPlayerPlayerRange)

	// Copy the slices so we don't confuse the client code
	steams := append([]skills.Team{}, teams...)
	sranks := append([]int{}, ranks...)

	// Make sure things are in order
	sort.Sort(skills.NewRankedTeams(steams, sranks))

	// Since we verified that each team has one player, we know the player is the first one
	winningTeam := steams[0]
	winner := winningTeam.Players()[0]
	winnerPrevRating := winningTeam.PlayerRating(winner)

	losingTeam := steams[1]
	loser := losingTeam.Players()[0]
	loserPrevRating := losingTeam.PlayerRating(loser)

	wasDraw := sranks[0] == sranks[1]

	newSkills[winner] = twoPlayerCalcNewRating(gi, winnerPrevRating, loserPrevRating, cond(wasDraw, skills.Draw, skills.Win))
	newSkills[loser] = twoPlayerCalcNewRating(gi, loserPrevRating, winnerPrevRating, cond(wasDraw, skills.Draw, skills.Lose))

	return newSkills
}
Exemple #2
0
// Calculates new ratings based on the prior ratings and team ranks use 1 for first place, repeat the number for a tie (e.g. 1, 2, 2).
func (calc *TwoTeamCalc) CalcNewRatings(gi *skills.GameInfo, teams []skills.Team, ranks ...int) skills.PlayerRatings {
	newSkills := make(map[interface{}]skills.Rating)

	// Basic argument checking
	validateTeamCount(teams, twoTeamTeamRange)
	validatePlayersPerTeam(teams, twoTeamPlayerRange)

	// Copy slices so we don't confuse the client code
	steams := append([]skills.Team{}, teams...)
	sranks := append([]int{}, ranks...)

	// Make sure things are in order
	sort.Sort(skills.NewRankedTeams(steams, sranks))

	winningTeam := steams[0]
	losingTeam := steams[1]

	wasDraw := sranks[0] == sranks[1]

	twoTeamUpdateRatings(gi, newSkills, winningTeam, losingTeam, cond(wasDraw, skills.Draw, skills.Win))
	twoTeamUpdateRatings(gi, newSkills, losingTeam, winningTeam, cond(wasDraw, skills.Draw, skills.Lose))

	return newSkills
}