diff --git a/autumn2013/results.yml b/autumn2013/results.yml index 1fc6ed3..be60fbe 100644 --- a/autumn2013/results.yml +++ b/autumn2013/results.yml @@ -164,7 +164,7 @@ - date: 22.09.2013 white: Magian black: Nedis - result: '0:1' + result: '1:0' - date: 21.09.2013 white: Genuine diff --git a/autumn2013/tour_04/tour_info b/autumn2013/tour_04/tour_info index 05c233c..e5495ed 100644 --- a/autumn2013/tour_04/tour_info +++ b/autumn2013/tour_04/tour_info @@ -4,7 +4,7 @@ Время проведения: 15.09.2013 - 22.09.2013 22.09.2013 — redgremlin 1:0 Kasparov -22.09.2013 — Magian 0:1 Nedis +22.09.2013 — Magian 1:0 Nedis 21.09.2013 — Genuine 0:1 iVS LongLiveUbuntu vs darkenshvein 17.09.2013 — raven_cler 0:1 HunOL diff --git a/lib/lorchess/tournament_table.rb b/lib/lorchess/tournament_table.rb index 0b277cd..76403cd 100644 --- a/lib/lorchess/tournament_table.rb +++ b/lib/lorchess/tournament_table.rb @@ -20,6 +20,7 @@ module LORChess @dim = @@db_players.length @results = Array.new(@dim) { Array.new(@dim, '') } @player_score = [] + @player_place = [] @buffer = '' @@db_players.each do |player| @@ -33,16 +34,13 @@ module LORChess fill calculate + stylize_table # Clean the vacancy place index = @player_pos['Kasparov'] if index @players[index] = 'отсутствует' - @elo_list[index] = '' - for cell in 0..(@dim-1) - @results[index][cell] = '' - end - @player_score[index] = '' + @elo_list[index] = '1200' end end @@ -64,12 +62,42 @@ module LORChess end def calculate - @results.each do |row| + score_data = [] + + @results.each_with_index do |row, i| sum = 0.0 row.each { |score| sum += score.to_f } - sum = sum.to_i if sum == sum.to_i # remove the fractional part if possible @player_score << sum.to_s + score_data << {:position => i, :total => sum} end + + # Sort players in the reverse order to total score + score_data.sort! { |x,y| y[:total] <=> x[:total] } + + score_data.each_with_index { |data,i| @player_place[data[:position]] = (i+1).to_s } + end + + def stylize_table + for row in 0..(@dim-1) + for cell in 0..(@dim-1) + @results[row][cell] = stylize_score @results[row][cell] + end + + @player_score[row] = stylize_score @player_score[row] + end + end + + # Replace the fractional part `0.5' by ½ + def stylize_score score + frac = score.split '.' + return '' if frac[0].nil? + unless frac[0] == '0' + score = frac[0] + score += '½' if frac[1] == '5' + else + score = (frac[1] == '5') ? '½' : '0' + end + score end def to_html @@ -78,7 +106,7 @@ module LORChess @buffer << "