vaskir
06/13/2017, 6:52 PMpoohbar
06/13/2017, 7:08 PMroberto.guerra
06/13/2017, 7:27 PMkirillrakhman
06/13/2017, 7:32 PMvaskir
06/13/2017, 7:39 PMlet scorePoint score point =
match score, point with
| Advantage player1, player2 when player1 = player2 -> Game player1
| Advantage player1, player2 -> Deuce
| Deuce, player -> Advantage player
| Points(Forty, _), A -> Game A
| Points(_, Forty), B -> Game B
| Points(a, b), A -> normalize (Points (nextPointScore a, b))
| Points(a, b), B -> normalize (Points (a, nextPointScore b))
| Game _ , _ -> (* printfn "the game is over!"; *) score
vs
fun scorePoint(currentScore : Score, point : Player) : Score {
return when (currentScore) {
is Score.Points ->
if (currentScore.playerA === PlayerScore.Forty && point === Player.A) { Score.Game(Player.A) }
else if (currentScore.playerB === PlayerScore.Forty && point === Player.B) { Score.Game(Player.B) }
else
if (point === Player.A) Score.Points(nextPointScore(currentScore.playerA), currentScore.playerB)
else Score.Points(currentScore.playerA, nextPointScore(currentScore.playerB))
is Score.Advantage -> when (currentScore.player) {
Player.A -> if(point === Player.A) Score.Game(Player.A) else Score.Deuce
Player.B -> if(point === Player.B) Score.Game(Player.B) else Score.Deuce
}
is Score.Deuce -> Score.Advantage(point)
is Score.Game -> throw Exception("Game already over")
}
}
poohbar
06/13/2017, 7:47 PMroberto.guerra
06/13/2017, 7:53 PMbamdmux
06/14/2017, 5:29 AMvaskir
06/14/2017, 7:16 AM