From fdca9f33aadea4f139619f35e992760a0355d007 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 19 Apr 2014 22:20:35 -0400 Subject: redirect is slightly more intelligent --- app/controllers/tournaments_controller.rb | 10 +++++----- app/views/tournaments/_selected.html.erb | 4 ++-- 2 files changed, 7 insertions(+), 7 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..d37c741 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -23,9 +23,9 @@ <% when 0 %> <%= setting_fields.text_field( setting.name, :name ) %> <% when 1 %> - <%# setting_fields.text_area( setting.name, setting.name ) %> + <%= setting_fields.text_area( setting.name, 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(',') ) %> <% when 3 %> <%= setting_fields.collection_check_boxes( setting.name, setting.type_opt.split(',') ) %> <% when 4 %> -- cgit v1.1-4-g5e80 From 1512dfafba22473830118db37a55ef42ed2bd0d7 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 19 Apr 2014 23:05:44 -0400 Subject: Added ScoringAlgorithms to lib --- lib/scoring_algorithms/Recommended.rb | 8 ++++++++ lib/scoring_algorithms/ScoringAlgorithm.rb | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 lib/scoring_algorithms/Recommended.rb create mode 100644 lib/scoring_algorithms/ScoringAlgorithm.rb diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb new file mode 100644 index 0000000..c871fd4 --- /dev/null +++ b/lib/scoring_algorithms/Recommended.rb @@ -0,0 +1,8 @@ +class Recommended #< 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 + +#puts Recommended.score(4, true, false) diff --git a/lib/scoring_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb new file mode 100644 index 0000000..ab7c81b --- /dev/null +++ b/lib/scoring_algorithms/ScoringAlgorithm.rb @@ -0,0 +1,6 @@ +class ScoringAlgorithm + + def score(*args) + end + +end -- cgit v1.1-4-g5e80 From 4a492f3036ad05718e16289436f9840b4fa5331e Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sat, 19 Apr 2014 23:31:43 -0400 Subject: Added some more scoring functions in ScoringAlgorithms.rb --- lib/scoring_algorithms/Recommended.rb | 2 +- lib/scoring_algorithms/ScoringAlgorithm.rb | 6 ------ lib/scoring_algorithms/ScoringAlgorithms.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 lib/scoring_algorithms/ScoringAlgorithm.rb create mode 100644 lib/scoring_algorithms/ScoringAlgorithms.rb diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb index c871fd4..8033bd2 100644 --- a/lib/scoring_algorithms/Recommended.rb +++ b/lib/scoring_algorithms/Recommended.rb @@ -1,4 +1,4 @@ -class Recommended #< ScoringAlgorithm +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) diff --git a/lib/scoring_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb deleted file mode 100644 index ab7c81b..0000000 --- a/lib/scoring_algorithms/ScoringAlgorithm.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ScoringAlgorithm - - def score(*args) - end - -end 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) -- cgit v1.1-4-g5e80 From 16750bab527d574867a64e3092f7335a028195cb Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sun, 20 Apr 2014 00:04:55 -0400 Subject: Made settings work for all the different types, CSS needs to be updated. --- app/views/tournaments/_selected.html.erb | 12 ++++++++---- db/seeds.rb | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index d37c741..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| %> +

+ <%= setting_fields.label setting.name %> +
<% 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 %> +

<% 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) -- cgit v1.1-4-g5e80