Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tournament system should be fully functional now

  • Loading branch information...
commit cad6e9b307b61b221735c85ff87dd2d6ea4bb234 1 parent b042e4a
@zombieCraig zombieCraig authored
View
12 app/controllers/matches_controller.rb
@@ -118,6 +118,7 @@ def start_round
def grant_point
@bot = Sumobot.find(params[:bot_id])
@match = Match.find(params[:id])
+ @other_bot_id
if cannot? :manage, @match then
redirect_to "/hax.html"
@@ -141,6 +142,7 @@ def grant_point
when 3 then
@match.update_attributes(:first_bot_round3_score => 1)
end
+ @other_bot_id = @match.second_bot_id
elsif @match.second_bot_id == @bot.id then
case round
when 1 then
@@ -150,6 +152,7 @@ def grant_point
when 3 then
@match.update_attributes(:second_bot_round3_score => 1)
end
+ @other_bot_id = @match.first_bot_id
end
if @match.bot1_final_score == 2 or
@@ -164,7 +167,7 @@ def grant_point
if nextmatch then
nextmatch.update_attributes(:second_bot_id => @bot.id)
else
- puts "TODO: Game done, assign winnners"
+ set_tournament_winner(@match, @bot.id, @other_bot_id)
end
end
end
@@ -191,7 +194,7 @@ def process_bye
if nextmatch then
nextmatch.update_attributes(:second_bot_id => @match.first_bot_id)
else
- puts "TODO: Game done, assign winnners"
+ set_tournament_winner(@match, @match.first_bot_id, -1)
end
end
end
@@ -201,4 +204,9 @@ def process_bye
format.xml { head :ok }
end
end
+
+ def set_tournament_winner(match, first, second)
+ @tournament = Tournament.find(match.tournament_id)
+ @tournament.update_attributes(:first_place => first, :second_place => second)
+ end
end
View
5 app/controllers/tournaments_controller.rb
@@ -49,7 +49,7 @@ def create
end
@bot_ids = Array.new
- @competing.each_key {|bot_id| @bot_ids << bot_id }
+ @competing.each_key {|bot_id| @bot_ids << bot_id if @competing[bot_id] == "1"}
@bot_ids.shuffle!
@@ -134,17 +134,14 @@ def build_blank_match(current_round, t_id, bye=false)
# Assigns bots to first round
def assign_round1(t_id, bots)
-puts "DEBUG: assign_round(#{t_id}, #{bots.inspect})"
matches = Match.find(:all, :conditions => {:tournament_id => t_id, :tournament_round => 1})
matches.each do |match|
if match.first_bot_from_match == 0 then
bot_id = bots.pop
-puts "DEBUG: first_bot_id = #{bot_id}"
match.update_attributes(:first_bot_id => bot_id)
end
if match.second_bot_from_match == 0 then
bot_id = bots.pop
-puts "DEBUG: second_bot_id = #{bot_id}"
match.update_attributes(:second_bot_id => bot_id)
end
end
View
7 app/views/tournaments/index.html.haml
@@ -21,7 +21,12 @@
%tr
%td= tournament.current_round
%td= tournament.max_rounds
- %td= "TODO"
+ %td
+ - if tournament.first_place
+ - bot = Sumobot.find(tournament.first_place)
+ = "Winner: #{bot.botname}"
+ - else
+ = "In Progess"
%td= link_to 'Show', tournament
- if can? :manage, tournament then
%td= link_to 'Edit', edit_tournament_path(tournament)
View
5 app/views/tournaments/show.html.haml
@@ -17,6 +17,11 @@
= render :partial => 'tournament_match_bracket', :locals => {:match => match}
- else
Winner
+ - if @tournament.first_place
+ %br
+ %b
+ - bot = Sumobot.find(@tournament.first_place)
+ = bot.botname
%br
Please sign in to comment.
Something went wrong with that request. Please try again.