-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsingle_game.ml
79 lines (65 loc) · 2.12 KB
/
single_game.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(*
* Glicko2 library. Implements the Glicko2 algorithm.
* Copyright (C) 2018-present Bruce Ricard
*
* This file is part of glicko2.
*
* Glicko2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Glicko2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Glicko2. If not, see <http://www.gnu.org/licenses/>.
*)
module Glicko2 = Glicko2.Default.SingleGame
let alice =
match Glicko2.default_player () with
| `Ok p -> p
| `Error _ -> failwith "error creating player"
let bob =
match Glicko2.default_player ~rating:1800 () with
| `Ok p -> p
| `Error _ -> failwith "error creating player"
let charlie =
match Glicko2.default_player () with
| `Ok p -> p
| `Error _ -> failwith "error creating player"
let first_game_result =
Glicko2.{
player1 = alice;
player2 = bob;
game_outcome = `Player1Win;
}
let result =
match Glicko2.rate first_game_result with
| `Ok r -> r
| `Error _ -> failwith "deal with error"
let new_alice, new_bob =
Glicko2.(result.new_player1, result.new_player2)
let second_game_result =
Glicko2.{
player1 = new_alice;
player2 = new_bob;
game_outcome = `Player2Win;
}
let result =
match Glicko2.rate second_game_result with
| `Ok r -> r
| `Error _ -> failwith "deal with error"
let new_alice, new_bob =
Glicko2.(result.new_player1, result.new_player2)
let new_charlie =
match
Glicko2.update_player_after_not_player_in_rating_period charlie
with
| `Ok p -> p
| `Error _ -> failwith "deal with error"
(* Those are the players you have at the end *)
let new_players = [new_alice; new_bob; new_charlie]
let new_ratings = List.map (fun p -> p.Glicko2.rating) new_players