From 7eafe19af2ec4b8c6e21ad5e17b136c0bbcbe715 Mon Sep 17 00:00:00 2001 From: vonavi Date: Wed, 9 Oct 2013 21:51:19 +0300 Subject: [PATCH] Add the calculation of Berger's coefficients. --- lib/lorchess/tournament_table.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/lorchess/tournament_table.rb b/lib/lorchess/tournament_table.rb index e204d20..98a7777 100644 --- a/lib/lorchess/tournament_table.rb +++ b/lib/lorchess/tournament_table.rb @@ -37,7 +37,7 @@ module LORChess fill_results calculate - stylize_table + results_to_s # Clean the vacancy place num = @player_numbers['Kasparov'] @@ -81,6 +81,8 @@ module LORChess player_scores << { :number => num, :total => sum } end + calculate_berger + # Sort players in the reverse order to total score player_scores.sort! { |x,y| y[:total] <=> x[:total] } @@ -89,13 +91,24 @@ module LORChess end end - def stylize_table + def calculate_berger + @game_scores.each do |row| + berger = 0.0 + row.each_with_index do |score, cell| + berger += score * @total_scores[cell] unless score.nil? + end + @berger_coefs << berger + end + end + + def results_to_s for row in 0..(@@dim - 1) for cell in 0..(@@dim - 1) @game_scores[row][cell] = stylize_score @game_scores[row][cell] end @total_scores[row] = stylize_score @total_scores[row] + @berger_coefs[row] = @berger_coefs[row].to_s end end @@ -129,6 +142,7 @@ module LORChess @buffer << " Игры\n" @buffer << " Очки\n" @buffer << " Место\n" + @buffer << " Бергер\n" @buffer << " \n" @buffer << " \n" @buffer << " \n" @@ -151,6 +165,7 @@ module LORChess @buffer << " " << @player_games[row] << "\n" @buffer << " " << @total_scores[row] << "\n" @buffer << " " << @player_places[row] << "\n" + @buffer << " " << @berger_coefs[row] << "\n" @buffer << " \n" end