whole_history_rating 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,6 +10,26 @@ Installation
10
10
 
11
11
  * gem install whole_history_rating
12
12
 
13
+
14
+ Usage
15
+ -----
16
+
17
+ require 'whole_history_rating'
18
+
19
+ @whr = WholeHistoryRating::Base.new
20
+
21
+ # WholeHistoryRating::Base#create_game arguments: black player name, white player name, winner, day number, handicap
22
+ @whr.create_game("shusaku", "shusai", "B", 1, 0)
23
+ @whr.create_game("shusaku", "shusai", "W", 2, 0)
24
+ @whr.create_game("shusaku", "shusai", "W", 3, 0)
25
+
26
+ # Iterate the WHR algorithm towards convergence with more players/games, more iterations are needed.
27
+ @whr.iterate(50)
28
+
29
+ # Results are stored in one triplet for each day: [day_number, elo_rating, uncertainty]
30
+ @whr.ratings_for_player("shusaku") => [[1, -92, 71], [2, -94, 71], [3, -95, 71], [4, -96, 72]]
31
+ @whr.ratings_for_player("shusai") => [[1, 92, 71], [2, 94, 71], [3, 95, 71], [4, 96, 72]]
32
+
13
33
  Enjoy!
14
34
 
15
35
  -Pete
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  module WholeHistoryRating
4
4
 
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
 
7
7
  STDOUT.sync = true
8
8
 
@@ -43,7 +43,7 @@ module WholeHistoryRating
43
43
  player.days.map {|d| [d.day, d.elo.round, (d.uncertainty*100).round]}
44
44
  end
45
45
 
46
- def create_game(black, white, winner, time_step, handicap, extras = {})
46
+ def setup_game(black, white, winner, time_step, handicap, extras = {})
47
47
 
48
48
  # Avoid self-played games (no info)
49
49
  if black == white
@@ -56,6 +56,11 @@ module WholeHistoryRating
56
56
  game = Game.new(black_player, white_player, winner, time_step, handicap, extras)
57
57
  game
58
58
  end
59
+
60
+ def create_game(black, white, winner, time_step, handicap, extras = {})
61
+ game = setup_game(black, white, winner, time_step, handicap, extras)
62
+ add_game(game)
63
+ end
59
64
 
60
65
  def add_game(game)
61
66
  game.white_player.add_game(game)
data/test/whr_test.rb CHANGED
@@ -6,61 +6,56 @@ class WholeHistoryRatingTest < Test::Unit::TestCase
6
6
  def setup
7
7
  @whr = WholeHistoryRating::Base.new
8
8
  end
9
-
10
- def add_game(black, white, winner, time_step, handicap)
11
- game = @whr.create_game(black, white, winner, time_step, handicap)
12
- @whr.add_game(game)
13
- end
14
-
15
- def build_test_game_force_elo(white_elo, black_elo, handicap)
16
- game = add_game("black", "white", "W", 1, handicap)
9
+
10
+ def setup_game_with_elo(white_elo, black_elo, handicap)
11
+ game = @whr.create_game("black", "white", "W", 1, handicap)
17
12
  game.black_player.days[0].elo = black_elo
18
13
  game.white_player.days[0].elo = white_elo
19
14
  game
20
15
  end
21
16
 
22
17
  def test_even_game_between_equal_strength_players_should_have_white_winrate_of_50_percent
23
- game = build_test_game_force_elo(500, 500, 0)
18
+ game = setup_game_with_elo(500, 500, 0)
24
19
  assert_in_delta 0.0001, 0.5, game.white_win_probability
25
20
  end
26
21
 
27
22
  def test_handicap_should_confer_advantage
28
- game = build_test_game_force_elo(500, 500, 1)
23
+ game = setup_game_with_elo(500, 500, 1)
29
24
  assert game.black_win_probability > 0.5
30
25
  end
31
26
 
32
27
  def test_higher_rank_should_confer_advantage
33
- game = build_test_game_force_elo(600, 500, 0)
28
+ game = setup_game_with_elo(600, 500, 0)
34
29
  assert game.white_win_probability > 0.5
35
30
  end
36
31
 
37
32
  def test_winrates_are_equal_for_same_elo_delta
38
- game = build_test_game_force_elo(100, 200, 0)
39
- game2 = build_test_game_force_elo(200, 300, 0)
33
+ game = setup_game_with_elo(100, 200, 0)
34
+ game2 = setup_game_with_elo(200, 300, 0)
40
35
  assert_in_delta 0.0001, game.white_win_probability, game2.white_win_probability
41
36
  end
42
37
 
43
38
  def test_winrates_for_twice_as_strong_player
44
- game = build_test_game_force_elo(100, 200, 0)
39
+ game = setup_game_with_elo(100, 200, 0)
45
40
  assert_in_delta 0.0001, 0.359935, game.white_win_probability
46
41
  end
47
42
 
48
43
  def test_winrates_should_be_inversely_proportional_with_unequal_ranks
49
- game = build_test_game_force_elo(600, 500, 0)
44
+ game = setup_game_with_elo(600, 500, 0)
50
45
  assert_in_delta 0.0001, game.white_win_probability, 1-game.black_win_probability
51
46
  end
52
47
 
53
48
  def test_winrates_should_be_inversely_proportional_with_handicap
54
- game = build_test_game_force_elo(500, 500, 4)
49
+ game = setup_game_with_elo(500, 500, 4)
55
50
  assert_in_delta 0.0001, game.white_win_probability, 1-game.black_win_probability
56
51
  end
57
52
 
58
53
  def test_output
59
- add_game("shusaku", "shusai", "B", 1, 0)
60
- add_game("shusaku", "shusai", "W", 2, 0)
61
- add_game("shusaku", "shusai", "W", 3, 0)
62
- add_game("shusaku", "shusai", "W", 4, 0)
63
- add_game("shusaku", "shusai", "W", 4, 0)
54
+ @whr.create_game("shusaku", "shusai", "B", 1, 0)
55
+ @whr.create_game("shusaku", "shusai", "W", 2, 0)
56
+ @whr.create_game("shusaku", "shusai", "W", 3, 0)
57
+ @whr.create_game("shusaku", "shusai", "W", 4, 0)
58
+ @whr.create_game("shusaku", "shusai", "W", 4, 0)
64
59
  @whr.iterate(50)
65
60
  assert_equal [[1, -92, 71], [2, -94, 71], [3, -95, 71], [4, -96, 72]], @whr.ratings_for_player("shusaku")
66
61
  assert_equal [[1, 92, 71], [2, 94, 71], [3, 95, 71], [4, 96, 72]], @whr.ratings_for_player("shusai")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whole_history_rating
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: