@@ -14,22 +14,41 @@ def matchup(players)
14
14
15
15
def retire ( players )
16
16
retired = Set . new
17
- elo = players [ 0 ] . elo
18
- ( players . count / 10 ) . times {
19
- i = rand ( players . count - 1 ) + 1 # don't retire idx 0
20
- players [ i ] = Elo ::Player . new ( elo , skill : rand . round ( 3 ) )
21
- retired . add i
17
+
18
+ # take 1 from the top 10 or 20
19
+ if rand ( 3 ) % 2 == 1
20
+ retired . add rand ( 10 )
21
+ else
22
+ retired . add rand ( 10 ) + 10
23
+ end
24
+ # take the bottom 4
25
+ ( players . count - 4 ) . upto ( players . count - 1 ) { |i | retired . add i }
26
+ # 5 others randomly outside the top 10 and bottom 5
27
+ 5 . times { retired . add rand ( players . count - 14 ) + 10 }
28
+
29
+ retired . each { |i |
30
+ players [ i ] = Elo ::Player . new ( elo : ELO , skill : rand . round ( 3 ) )
22
31
}
23
32
retired . sort
24
33
end
25
34
35
+ ELO = Elo . new ( initial : 1500 )
36
+
26
37
num_players = 99
27
38
num_matches = 9999
28
- elo = Elo . new ( initial : 1500 )
29
- players = Elo ::Player . init_pool ( num_players , elo ) . each { |p |
39
+ retirement_periods = 3
40
+ offset = 7
41
+
42
+ players = Elo ::Player . init_pool ( num_players , elo : ELO ) . each { |p |
30
43
p . skill = rand . round ( 3 )
31
44
}
32
45
46
+ class Array
47
+ def rank
48
+ sort { |a , b | b <=> a }
49
+ end
50
+ end
51
+
33
52
puts
34
53
puts "#{ num_matches } matches without retirement"
35
54
puts
@@ -39,26 +58,27 @@ def retire(players)
39
58
players [ a ] . simulate players [ b ]
40
59
}
41
60
42
- players . each { | p | puts p }
61
+ puts players = players . rank
43
62
puts
44
63
puts "Avg Rating: #{ avg_rating ( players ) } "
45
64
puts
46
65
47
66
########
48
67
49
- puts "#{ num_matches } matches with 10x 10% retirement"
68
+ puts "#{ num_matches } matches with #{ retirement_periods } x 10% retirement"
50
69
puts
51
70
52
71
num_matches . times { |i |
53
72
a , b = matchup ( players )
54
73
players [ a ] . simulate players [ b ]
55
- if i % ( num_matches / 10 ) == num_matches / 15
74
+ if i % ( num_matches / retirement_periods ) == num_matches / offset
75
+ players = players . rank
56
76
puts format ( "Played %i matches, retired %s" , i , retire ( players ) . join ( ', ' ) )
57
77
end
58
78
}
59
79
puts
60
80
61
- players . each { | p | puts p }
81
+ puts players = players . rank
62
82
puts
63
83
puts "Avg Rating: #{ avg_rating ( players ) } "
64
84
puts
@@ -75,17 +95,13 @@ def retire(players)
75
95
else
76
96
players [ a ] . simulate ( players [ b ] )
77
97
end
78
- if i % ( num_matches / 10 ) == num_matches / 15
98
+ if i % ( num_matches / retirement_periods ) == num_matches / offset
79
99
puts format ( "Played %i matches, retired %s" , i , retire ( players ) . join ( ', ' ) )
80
100
end
81
101
}
82
102
puts
83
103
84
- players . each { | p | puts p }
104
+ puts players = players . rank
85
105
puts
86
106
puts "Avg Rating: #{ avg_rating ( players ) } "
87
107
puts
88
-
89
- puts "SORTED:"
90
- players . sort_by { |p | -1 * p . rating } . each { |p | puts p }
91
- puts
0 commit comments