diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2014-04-20 16:03:24 -0400 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2014-04-20 16:03:24 -0400 |
commit | 641b619ae503ea70ea36c75d658f133775379deb (patch) | |
tree | 7e663e3a6aa9c8548413737da20c82f87a8459f7 | |
parent | 49f579f025235045840e17005fd84edc9e12f9eb (diff) | |
parent | 16750bab527d574867a64e3092f7335a028195cb (diff) |
Merge branch 'master' of github.com:LukeShu/leaguer
-rw-r--r-- | app/controllers/tournaments_controller.rb | 10 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 12 | ||||
-rw-r--r-- | db/seeds.rb | 5 | ||||
-rw-r--r-- | lib/scoring_algorithms/Recommended.rb | 8 | ||||
-rw-r--r-- | lib/scoring_algorithms/ScoringAlgorithms.rb | 28 |
5 files changed, 54 insertions, 9 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index bb1d222..57e73aa 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -127,12 +127,11 @@ class TournamentsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_tournament - if @tournament.nil? - respond_to do |format| - format.html { redirect_to @tournament, notice: 'That tournament no longer exists.' } - end + begin + @tournament = Tournament.find(params[:id]) + rescue + redirect_to tournaments_url, notice: 'That tournament no longer exists.' end - @tournament = Tournament.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. @@ -148,4 +147,5 @@ class TournamentsController < ApplicationController def check_edit set_tournament end + end diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index c0f8367..8bb0532 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -19,15 +19,18 @@ <%= fields_for "tournament[preferences]", @tournament.preferences do |setting_fields| %> <% @game.settings.each do |setting| %> + <p> + <%= setting_fields.label setting.name %> + <br> <% case setting.stype %> <% when 0 %> - <%= setting_fields.text_field( setting.name, :name ) %> + <%= setting_fields.text_field( setting.name ) %> <% when 1 %> - <%# setting_fields.text_area( setting.name, setting.name ) %> + <%= setting_fields.text_area( setting.name ) %> <% when 2 %> - <%# setting_fields.collection_radio_buttons( setting.name, setting.type_opt.split(',') ) %> + <%= setting_fields.collection_radio_buttons( setting.name, setting.type_opt.split(','), :first, :last, { item_wrapper_tag: false } ) %> <% when 3 %> - <%= setting_fields.collection_check_boxes( setting.name, setting.type_opt.split(',') ) %> + <%= setting_fields.collection_check_boxes( setting.name, setting.type_opt.split(','), :first, :last, { item_wrapper_tag: false } ) %> <% when 4 %> <%= setting_fields.radio_button( setting.name, "true" ) %> <%= setting_fields.radio_button( setting.name, "false" ) %> @@ -35,6 +38,7 @@ <%= setting_fields.select( setting.name, setting.type_opt.split(',') ) %> <% end %> <% end %> + </p> <% end %> <%= f.submit %> <% end %> diff --git a/db/seeds.rb b/db/seeds.rb index 85ccd92..fe7c32e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -12,6 +12,7 @@ Server.create(default_user_permissions: p[:join_tournament] | p[:create_pm]) Game.create(name: "League of Legends",min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true) Game.create(name: "Chess", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true) Game.create(name: "Hearthstone", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: 1, randomized_teams: false) +Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 1, max_teams_per_match: nil, set_rounds: nil, randomized_teams: false) Game.find_by_name("League of Legends").settings.create(name: "Map", default: "Summoners Rift", type_opt: "Summoners Rift,Twisted Treeline,Crystal Scar,Haunted Abyss", description: "Select a map to play on.", stype: 5, display_order: 1) Game.find_by_name("League of Legends").settings.create(name: "Pick Type", type_opt: "Blind Pick,Draft", description: "Select a pick type.", stype: 5, display_order: 2) @@ -20,6 +21,10 @@ Game.find_by_name("Chess").settings.create(name: "Time Control", description: "E Game.find_by_name("Hearthstone").settings.create(name: "Deck Name", description: "Enter a name for your deck, be descriptive.", stype: 1, display_order: 1) +Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Favorite Object", description: "What is your favorite object in RPS?", type_opt: "Rock,Paper,Scissors", stype: 2, display_order: 2) +Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Lizard, Spock allowed?", description: "Will you allow Lizard and Spock?", stype: 4, display_order: 1) +Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Why are those up there even called radio buttons?", description: "Check boxes make sense at least", type_opt: "I do not know.,There is now spoon.,Wow.,Because electricity.,Wat?", stype: 2, display_order: 3) + unless ENV["RAILS_ENV"] and ENV["RAILS_ENV"] != "development" User.create(name: "Administrator", user_name: "admin", email: "root@localhost.lan", password: "password", password_confirmation: "password", permissions: 0xFFFFFFFF) diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb new file mode 100644 index 0000000..8033bd2 --- /dev/null +++ b/lib/scoring_algorithms/Recommended.rb @@ -0,0 +1,8 @@ +class Recommended + def self.score(votes, win, blowout) + fibonacci = Hash.new{ |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] } + fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7) + end +end + +#puts Recommended.score(4, true, false) diff --git a/lib/scoring_algorithms/ScoringAlgorithms.rb b/lib/scoring_algorithms/ScoringAlgorithms.rb new file mode 100644 index 0000000..7f8ec12 --- /dev/null +++ b/lib/scoring_algorithms/ScoringAlgorithms.rb @@ -0,0 +1,28 @@ +class ScoringAlgorithm + def self.score(*args) + end +end + +class FibonacciPeerWithBlowout < ScoringAlgorithm + def self.score(votes, win, blowout) + fibonacci = Hash.new{ |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] } + fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7) + end +end + +class WinnerTakesAll < ScoringAlgorithm + def self.score(win) + win.nil? ? 0.5 : win ? 1 : 0 + end +end + +class MarginalPeer < ScoringAlgorithm + def self.score(rating) + rating + end +end + + +#puts Recommended.score(4, true, false) +#puts WinnerTakesAll.score(nil) +#puts WinnerTakesAll.score(true) |