Skip to content

Commit

Permalink
add play_7 option
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhull committed Jun 10, 2024
1 parent 4e2e4f8 commit 80fe3b6
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions examples/elo_tourney.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def rank
pool_matchups = 99_999
tourney_size = 64
iters = 5
play_7 = true

# randomize skill levels
pool = Elo::Player.init_pool(pool_size).each { |player|
Expand Down Expand Up @@ -73,23 +74,28 @@ def rank
b = a + 1
puts format("%s vs %s", tpool[a], tpool[b])

# best 4 out of 7
wins, losses = 0, 0
while (wins < 4 and losses < 4) or (wins == losses)
outcome = tpool[a].simulate(tpool[b])
if outcome == 0.5
wins += 0.5
losses += 0.5
elsif outcome < 0.5
losses += 1
if play_7
# best 4 out of 7
wins, losses = 0, 0
while (wins < 4 and losses < 4) or (wins == losses)
outcome = tpool[a].simulate(tpool[b])
if outcome == 0.5
wins += 0.5
losses += 0.5
elsif outcome < 0.5
losses += 1
else
wins += 1
end
end
if wins > losses
outcome, winner = 1, tpool[a]
else
wins += 1
outcome, winner = 0, tpool[b]
end
end
if wins > losses
outcome, winner = 1, tpool[a]
else
outcome, winner = 0, tpool[b]
outcome = tpool[a].simulate(tpool[b], type: :rand)
winner = tpool[outcome >= 0.5 ? a : b]
end
next_round << winner
puts "Outcome: #{outcome}\tWinner: #{winner}"
Expand Down

0 comments on commit 80fe3b6

Please sign in to comment.