@@ -3,6 +3,8 @@ package impl
33
44private [glicko] trait Result :
55
6+ def getAdvantage (advantage : ColorAdvantage , p : Rating ): ColorAdvantage
7+
68 def getScore (player : Rating ): Double
79
810 def getOpponent (player : Rating ): Rating
@@ -14,6 +16,8 @@ private[glicko] trait Result:
1416// score from 0 (opponent wins) to 1 (player wins)
1517final private [glicko] class FloatingResult (player : Rating , opponent : Rating , score : Float ) extends Result :
1618
19+ def getAdvantage (advantage : ColorAdvantage , p : Rating ): ColorAdvantage = ColorAdvantage .zero
20+
1721 def getScore (p : Rating ) = if p == player then score else 1 - score
1822
1923 def getOpponent (p : Rating ) = if p == player then opponent else player
@@ -22,14 +26,17 @@ final private[glicko] class FloatingResult(player: Rating, opponent: Rating, sco
2226
2327 def players = List (player, opponent)
2428
25- final private [glicko] class GameResult (winner : Rating , loser : Rating , isDraw : Boolean ) extends Result :
29+ final private [glicko] class GameResult (first : Rating , second : Rating , outcome : chess. Outcome ) extends Result :
2630 private val POINTS_FOR_WIN = 1.0d
2731 private val POINTS_FOR_LOSS = 0.0d
2832 private val POINTS_FOR_DRAW = 0.5d
2933
30- def players = List (winner, loser )
34+ def players = List (first, second )
3135
32- def participated (player : Rating ) = player == winner || player == loser
36+ def participated (player : Rating ) = player == first || player == second
37+
38+ def getAdvantage (advantage : ColorAdvantage , player : Rating ): ColorAdvantage =
39+ if player == first then advantage.half else advantage.negate.half
3340
3441 /** Returns the "score" for a match.
3542 *
@@ -38,18 +45,17 @@ final private[glicko] class GameResult(winner: Rating, loser: Rating, isDraw: Bo
3845 * 1 for a win, 0.5 for a draw and 0 for a loss
3946 * @throws IllegalArgumentException
4047 */
41- def getScore (player : Rating ): Double =
42- if isDraw then POINTS_FOR_DRAW
43- else if winner == player then POINTS_FOR_WIN
44- else if loser == player then POINTS_FOR_LOSS
45- else throw new IllegalArgumentException (" Player did not participate in match" );
48+ def getScore (player : Rating ): Double = outcome.winner match
49+ case Some (chess.Color .White ) => if player == first then POINTS_FOR_WIN else POINTS_FOR_LOSS
50+ case Some (chess.Color .Black ) => if player == first then POINTS_FOR_LOSS else POINTS_FOR_WIN
51+ case _ => if participated(player) then POINTS_FOR_DRAW else throw new IllegalArgumentException (" Player did not participate in match" );
4652
4753 def getOpponent (player : Rating ) =
48- if winner == player then loser
49- else if loser == player then winner
54+ if first == player then second
55+ else if second == player then first
5056 else throw new IllegalArgumentException (" Player did not participate in match" );
5157
52- override def toString = s " $winner vs $loser = $isDraw "
58+ override def toString = s " $first vs $second = $outcome "
5359
5460private [glicko] trait RatingPeriodResults [R <: Result ]():
5561 val results : List [R ]
0 commit comments