Created
February 3, 2011 13:57
-
-
Save sanity/809494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// Two player example | |
TrueskillCalc trueskillCalc = new TrueskillCalc(); | |
// or, to use non-default gameInfo | |
TrueskillCalc trueskillCalc = new TrueskillCalc(GameInfo gameInfo); | |
Rating playerRating1 = trueskillCalc.newDefaultRating(); | |
or | |
Rating playerRating2 = new Rating(mean, stdDev); | |
// player1 wins, player2 comes second | |
trueskillCalc.updateRatings(playerRating1, 1, playerRating2, 2); | |
// Note, there are multiple overloaded implementations of TrueskillCalc.updateRatings() | |
// In this case, we use updateRatings(Player a, int aResult, Player b, bResult) - and | |
// this contains code specific to a one-on-one game (like TwoPlayerTrueSkillCalculator) | |
// Note also that the Ratings are updated in-place. This is more efficient and probably | |
// in-keeping with the most common use-cases. Rating should implement a clone() | |
// method, so that they can be copied before giving them to updateRatings() if the | |
// caller needs to keep the original around. | |
//// Two teams with 2 players in the first team, and 3 players in the second | |
// Team implements the List<Rating> interface | |
Team team1 = Team.create(playerRating1, playerRating2); | |
Team team2 = Team.create(playerRating3, playerRating4, playerRating5); | |
trueskillCalc.updateRatings(team1, 1, team2, 2); | |
//// What about multiple players? We use a map | |
// ("Maps" is a utility class provided by Google's guava-libraries) | |
// Here, player1 wins, and player2 and player3 tie for second place | |
Map<Rating, Integer> gameResults = Maps.newHashMap(); | |
Rating playerRating1 = ... | |
gameResults.put(playerRating1, 1); | |
Rating playerRating2 = ... | |
gameResults.put(playerRating2, 2); | |
Rating playerRating3 = ... | |
gameResults.put(playerRating3, 2); | |
trueskillCalc.updateRatings(gameResults); | |
// HOWEVER, we can't use another overloaded implementation of our updateRatings() to do the | |
// same with teams because of a limitation of Java's generics, so we do this: | |
Map<Team, Integer> gameResults = Maps.newHashMap(); | |
// .. create the teams and add them to gameResults | |
trueskillCalc.updateTeamRatings(gameResults); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment