Skip to content
This repository
Browse code

Adds BracketTree::Template w/ Single/Double Elim

  • Loading branch information...
commit 4512c89352b9cba05d3eb2f61e5fb2a57a8a57f9 1 parent 34aa833
Andrew Nordman cadwallion authored
3  lib/bracket_tree.rb
... ... @@ -1,5 +1,8 @@
1 1 require 'json'
2 2 require 'bracket_tree/bracket'
  3 +require 'bracket_tree/template'
  4 +require 'bracket_tree/templates/double_elimination'
  5 +require 'bracket_tree/templates/single_elimination'
3 6
4 7 module BracketTree
5 8 end
1  lib/bracket_tree/bracket.rb
@@ -39,6 +39,7 @@ def add position, data
39 39 end
40 40 end
41 41
  42 + # This needs refactoring. Inconsistent interface
42 43 def add_winner winner
43 44 @root.payload.seed_value = winner.seed_position
44 45 @root.payload.race = winner.race
1  lib/bracket_tree/node.rb
@@ -13,6 +13,7 @@ def method_missing(sym, *args, &block)
13 13
14 14 def to_h
15 15 {
  16 + position: @position,
16 17 payload: @payload,
17 18 left: @left ? @left.to_h : nil,
18 19 right: @right ? @right.to_h : nil
82 lib/bracket_tree/template.rb
... ... @@ -0,0 +1,82 @@
  1 +module BracketTree
  2 + # Contains the logic for common template formats. Holds match progression as well as seat order to generate the correct bracket tree.
  3 + module Template
  4 + class Base
  5 + class << self
  6 + # Reads stored JSON files to generate a Template
  7 + #
  8 + # @param [Fixnum] size - player count
  9 + # return [nil, BracketTree::Template] template - the resulting bracket template
  10 + def by_size size
  11 + filename = File.join location, "#{size}.json"
  12 +
  13 + if File.exists? filename
  14 + from_json JSON.parse File.read filename
  15 + else
  16 + return nil
  17 + end
  18 + end
  19 +
  20 + # Generates Template from JSON
  21 + #
  22 + # @param [String] json - the bracket template in its standard data specification
  23 + # @return [BracketTree::Template]
  24 + def from_json json
  25 + template = new
  26 + if json['seats']
  27 + template.seats = json['seats'].map { |s| s['position'] }
  28 + end
  29 +
  30 + if json['startingSeats']
  31 + template.starting_seats = json['startingSeats']
  32 + end
  33 +
  34 + if json['nodes']
  35 + template.nodes = json['nodes']
  36 + end
  37 +
  38 + template
  39 + end
  40 +
  41 + # Folder location of the template JSON files. Abstract method
  42 + # @return [String] location - the folder name of the JSON files
  43 + def location
  44 + raise NotImplementedError, 'Abstract method, please define `location` in subclass.'
  45 + end
  46 + end
  47 +
  48 + attr_accessor :seats, :starting_seats, :nodes
  49 +
  50 + def initialize
  51 + @seats = []
  52 + @starting_seats = []
  53 + @nodes = []
  54 + end
  55 +
  56 + # Generates a Bracket object with placeholder empty hashes for each Seat in the
  57 + # Template
  58 + #
  59 + # @return [BracketTree::Bracket] bracket
  60 + def generate_blank_bracket
  61 + bracket = Bracket.new
  62 +
  63 + @seats.each do |position|
  64 + bracket.add position, {}
  65 + end
  66 +
  67 + bracket
  68 + end
  69 +
  70 + # Returns hash representation of the Template
  71 + #
  72 + # @return [Hash] template
  73 + def to_h
  74 + hash = {
  75 + 'seats' => @seats.map { |s| { 'position' => s } },
  76 + 'startingSeats' => @starting_seats,
  77 + 'nodes' => @nodes
  78 + }
  79 + end
  80 + end
  81 + end
  82 +end
13 lib/bracket_tree/templates/double_elimination.rb
... ... @@ -0,0 +1,13 @@
  1 +module BracketTree
  2 + module Template
  3 + # Template for double-elimination-based tournament formats. Uses the 'right' half
  4 + # of the binary tree for the loser's bracket and the 'left' half for the winner's
  5 + class DoubleElimination < Base
  6 + class << self
  7 + def location
  8 + File.join File.dirname(__FILE__), 'templates', 'double_elimination'
  9 + end
  10 + end
  11 + end
  12 + end
  13 +end
107 lib/bracket_tree/templates/double_elimination/16.json
... ... @@ -0,0 +1,107 @@
  1 +{
  2 + "nodes":[
  3 + { "seats":[1,3], "winnerTo":2, "loserTo":39 },
  4 + { "seats":[5,7], "winnerTo":6, "loserTo":41 },
  5 + { "seats":[9,11], "winnerTo":10, "loserTo":45 },
  6 + { "seats":[13,15], "winnerTo":14, "loserTo":47 },
  7 + { "seats":[17,19], "winnerTo":18, "loserTo":51 },
  8 + { "seats":[21,23], "winnerTo":22, "loserTo":53 },
  9 + { "seats":[25,27], "winnerTo":26, "loserTo":57 },
  10 + { "seats":[29,31], "winnerTo":30, "loserTo":59 },
  11 +
  12 + { "seats":[2,6], "winnerTo":4, "loserTo":55 },
  13 + { "seats":[10,14], "winnerTo":12, "loserTo":49 },
  14 + { "seats":[18,22], "winnerTo":20, "loserTo":43 },
  15 + { "seats":[26,30], "winnerTo":28, "loserTo":37 },
  16 + { "seats":[39,41], "winnerTo":40, "loserTo":null },
  17 + { "seats":[45,47], "winnerTo":46, "loserTo":null },
  18 + { "seats":[51,53], "winnerTo":52, "loserTo":null },
  19 + { "seats":[57,59], "winnerTo":58, "loserTo":null },
  20 +
  21 + { "seats":[4,12], "winnerTo":8, "loserTo":61 },
  22 + { "seats":[20,28], "winnerTo":24, "loserTo":35 },
  23 + { "seats":[37,40], "winnerTo":38, "loserTo":null },
  24 + { "seats":[43,46], "winnerTo":44, "loserTo":null },
  25 + { "seats":[49,52], "winnerTo":50, "loserTo":null },
  26 + { "seats":[55,58], "winnerTo":56, "loserTo":null },
  27 +
  28 + { "seats":[8,24], "winnerTo":16, "loserTo":33 },
  29 + { "seats":[38,44], "winnerTo":42, "loserTo":null },
  30 + { "seats":[50,56], "winnerTo":54, "loserTo":null },
  31 +
  32 +
  33 + { "seats":[35,42], "winnerTo":36, "loserTo":null },
  34 + { "seats":[54,61], "winnerTo":60, "loserTo":null },
  35 +
  36 + { "seats":[36,60], "winnerTo":48, "loserTo":null },
  37 +
  38 + { "seats":[33,48], "winnerTo":34, "loserTo":null },
  39 +
  40 + { "seats":[16,34], "winnerTo":null, "loserTo":null }
  41 + ],
  42 + "seats": [
  43 + { "position":32 },
  44 + { "position":16 },
  45 + { "position":8 },
  46 + { "position":24 },
  47 + { "position":4 },
  48 + { "position":12 },
  49 + { "position":20 },
  50 + { "position":28 },
  51 + { "position":2 },
  52 + { "position":6 },
  53 + { "position":10 },
  54 + { "position":14 },
  55 + { "position":18 },
  56 + { "position":22 },
  57 + { "position":26 },
  58 + { "position":30 },
  59 + { "position":1 },
  60 + { "position":3 },
  61 + { "position":5 },
  62 + { "position":7 },
  63 + { "position":9 },
  64 + { "position":11 },
  65 + { "position":13 },
  66 + { "position":15 },
  67 + { "position":17 },
  68 + { "position":19 },
  69 + { "position":21 },
  70 + { "position":23 },
  71 + { "position":25 },
  72 + { "position":27 },
  73 + { "position":29 },
  74 + { "position":31 },
  75 + { "position":34 },
  76 + { "position":33 },
  77 + { "position":48 },
  78 + { "position":36 },
  79 + { "position":60 },
  80 + { "position":35 },
  81 + { "position":42 },
  82 + { "position":54 },
  83 + { "position":61 },
  84 + { "position":38 },
  85 + { "position":44 },
  86 + { "position":50 },
  87 + { "position":56 },
  88 + { "position":37 },
  89 + { "position":40 },
  90 + { "position":43 },
  91 + { "position":46 },
  92 + { "position":49 },
  93 + { "position":52 },
  94 + { "position":55 },
  95 + { "position":58 },
  96 + { "position":39 },
  97 + { "position":41 },
  98 + { "position":45 },
  99 + { "position":47 },
  100 + { "position":51 },
  101 + { "position":53 },
  102 + { "position":57 },
  103 + { "position":59 }
  104 + ],
  105 + "startingSeats":[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31]
  106 +}
  107 +
202 lib/bracket_tree/templates/double_elimination/32.json
... ... @@ -0,0 +1,202 @@
  1 +{
  2 + "nodes":[
  3 + { "seats":[1,3], "winnerTo":2, "loserTo":73 },
  4 + { "seats":[5,7], "winnerTo":6, "loserTo":75 },
  5 + { "seats":[9,11], "winnerTo":10, "loserTo":79 },
  6 + { "seats":[13,15], "winnerTo":14, "loserTo":81 },
  7 + { "seats":[17,19], "winnerTo":18, "loserTo":87 },
  8 + { "seats":[21,23], "winnerTo":22, "loserTo":89 },
  9 + { "seats":[25,27], "winnerTo":26, "loserTo":93 },
  10 + { "seats":[29,31], "winnerTo":30, "loserTo":95 },
  11 + { "seats":[33,35], "winnerTo":34, "loserTo":103 },
  12 + { "seats":[37,39], "winnerTo":38, "loserTo":105 },
  13 + { "seats":[41,43], "winnerTo":42, "loserTo":109 },
  14 + { "seats":[45,47], "winnerTo":46, "loserTo":111 },
  15 + { "seats":[49,51], "winnerTo":50, "loserTo":117 },
  16 + { "seats":[53,55], "winnerTo":54, "loserTo":119 },
  17 + { "seats":[57,59], "winnerTo":58, "loserTo":123 },
  18 + { "seats":[61,63], "winnerTo":62, "loserTo":125 },
  19 +
  20 + { "seats":[2,6], "winnerTo":4, "loserTo":121 },
  21 + { "seats":[10,14], "winnerTo":12, "loserTo":115 },
  22 + { "seats":[18,22], "winnerTo":20, "loserTo":107 },
  23 + { "seats":[26,30], "winnerTo":28, "loserTo":101 },
  24 + { "seats":[34,38], "winnerTo":36, "loserTo":91 },
  25 + { "seats":[42,46], "winnerTo":44, "loserTo":85 },
  26 + { "seats":[50,54], "winnerTo":52, "loserTo":77 },
  27 + { "seats":[58,62], "winnerTo":60, "loserTo":71 },
  28 + { "seats":[73,75], "winnerTo":74, "loserTo":null },
  29 + { "seats":[79,81], "winnerTo":80, "loserTo":null },
  30 + { "seats":[87,89], "winnerTo":88, "loserTo":null },
  31 + { "seats":[93,95], "winnerTo":94, "loserTo":null },
  32 + { "seats":[103,105], "winnerTo":104, "loserTo":null },
  33 + { "seats":[109,111], "winnerTo":110, "loserTo":null },
  34 + { "seats":[117,119], "winnerTo":118, "loserTo":null },
  35 + { "seats":[123,125], "winnerTo":124, "loserTo":null },
  36 +
  37 + { "seats":[4,12], "winnerTo":8, "loserTo":69 },
  38 + { "seats":[20,28], "winnerTo":24, "loserTo":83 },
  39 + { "seats":[36,44], "winnerTo":40, "loserTo":99 },
  40 + { "seats":[52,60], "winnerTo":56, "loserTo":113 },
  41 + { "seats":[71,74], "winnerTo":72, "loserTo":null },
  42 + { "seats":[77,80], "winnerTo":78, "loserTo":null },
  43 + { "seats":[85,88], "winnerTo":86, "loserTo":null },
  44 + { "seats":[91,94], "winnerTo":92, "loserTo":null },
  45 + { "seats":[101,104], "winnerTo":102, "loserTo":null },
  46 + { "seats":[107,110], "winnerTo":108, "loserTo":null },
  47 + { "seats":[115,118], "winnerTo":116, "loserTo":null },
  48 + { "seats":[121,124], "winnerTo":122, "loserTo":null },
  49 +
  50 + { "seats":[8,24], "winnerTo":16, "loserTo":97 },
  51 + { "seats":[40,56], "winnerTo":48, "loserTo":67 },
  52 + { "seats":[72,78], "winnerTo":76, "loserTo":null },
  53 + { "seats":[86,92], "winnerTo":90, "loserTo":null },
  54 + { "seats":[102,108], "winnerTo":106, "loserTo":null },
  55 + { "seats":[116,122], "winnerTo":120, "loserTo":null },
  56 +
  57 + { "seats":[69,76], "winnerTo":70, "loserTo":null },
  58 + { "seats":[83,90], "winnerTo":84, "loserTo":null },
  59 + { "seats":[99,106], "winnerTo":100, "loserTo":null },
  60 + { "seats":[113,120], "winnerTo":114, "loserTo":null },
  61 +
  62 + { "seats":[70,84], "winnerTo":82, "loserTo":null },
  63 + { "seats":[100,114], "winnerTo":112, "loserTo":null },
  64 +
  65 + { "seats":[67,82], "winnerTo":68, "loserTo":null },
  66 + { "seats":[97,112], "winnerTo":98, "loserTo":null },
  67 +
  68 + { "seats":[68,98], "winnerTo":96, "loserTo":null },
  69 +
  70 + { "seats":[16,48], "winnerTo":32, "loserTo":65 },
  71 + { "seats":[65,96], "winnerTo":66, "loserTo":null },
  72 +
  73 + { "seats":[32,66], "winnerTo":null, "loserTo":null }
  74 + ],
  75 + "seats":[
  76 + { "position": 64 },
  77 + { "position": 32 },
  78 + { "position": 66 },
  79 + { "position": 16 },
  80 + { "position": 48 },
  81 + { "position": 65 },
  82 + { "position": 96 },
  83 + { "position": 68 },
  84 + { "position": 98 },
  85 + { "position": 67 },
  86 + { "position": 82 },
  87 + { "position": 97 },
  88 + { "position": 112 },
  89 + { "position": 70 },
  90 + { "position": 84 },
  91 + { "position": 100 },
  92 + { "position": 114 },
  93 + { "position": 69 },
  94 + { "position": 76 },
  95 + { "position": 83 },
  96 + { "position": 90 },
  97 + { "position": 99 },
  98 + { "position": 106 },
  99 + { "position": 113 },
  100 + { "position": 120 },
  101 + { "position": 72 },
  102 + { "position": 78 },
  103 + { "position": 86 },
  104 + { "position": 92 },
  105 + { "position": 102 },
  106 + { "position": 108 },
  107 + { "position": 116 },
  108 + { "position": 122 },
  109 + { "position": 71 },
  110 + { "position": 74 },
  111 + { "position": 77 },
  112 + { "position": 80 },
  113 + { "position": 85 },
  114 + { "position": 88 },
  115 + { "position": 91 },
  116 + { "position": 94 },
  117 + { "position": 101 },
  118 + { "position": 104 },
  119 + { "position": 107 },
  120 + { "position": 110 },
  121 + { "position": 115 },
  122 + { "position": 118 },
  123 + { "position": 121 },
  124 + { "position": 124 },
  125 + { "position": 73 },
  126 + { "position": 75 },
  127 + { "position": 79 },
  128 + { "position": 81 },
  129 + { "position": 87 },
  130 + { "position": 89 },
  131 + { "position": 93 },
  132 + { "position": 95 },
  133 + { "position": 103 },
  134 + { "position": 105 },
  135 + { "position": 109 },
  136 + { "position": 111 },
  137 + { "position": 117 },
  138 + { "position": 119 },
  139 + { "position": 123 },
  140 + { "position": 125 },
  141 + { "position": 8 },
  142 + { "position": 24 },
  143 + { "position": 40 },
  144 + { "position": 56 },
  145 + { "position": 4 },
  146 + { "position": 12 },
  147 + { "position": 20 },
  148 + { "position": 28 },
  149 + { "position": 36 },
  150 + { "position": 44 },
  151 + { "position": 52 },
  152 + { "position": 60 },
  153 + { "position": 2 },
  154 + { "position": 6 },
  155 + { "position": 10 },
  156 + { "position": 14 },
  157 + { "position": 18 },
  158 + { "position": 22 },
  159 + { "position": 26 },
  160 + { "position": 30 },
  161 + { "position": 34 },
  162 + { "position": 38 },
  163 + { "position": 42 },
  164 + { "position": 46 },
  165 + { "position": 50 },
  166 + { "position": 54 },
  167 + { "position": 58 },
  168 + { "position": 62 },
  169 + { "position": 1 },
  170 + { "position": 3 },
  171 + { "position": 5 },
  172 + { "position": 7 },
  173 + { "position": 9 },
  174 + { "position": 11 },
  175 + { "position": 13 },
  176 + { "position": 15 },
  177 + { "position": 17 },
  178 + { "position": 19 },
  179 + { "position": 21 },
  180 + { "position": 23 },
  181 + { "position": 25 },
  182 + { "position": 27 },
  183 + { "position": 29 },
  184 + { "position": 31 },
  185 + { "position": 33 },
  186 + { "position": 35 },
  187 + { "position": 37 },
  188 + { "position": 39 },
  189 + { "position": 41 },
  190 + { "position": 43 },
  191 + { "position": 45 },
  192 + { "position": 47 },
  193 + { "position": 49 },
  194 + { "position": 51 },
  195 + { "position": 53 },
  196 + { "position": 55 },
  197 + { "position": 57 },
  198 + { "position": 59 },
  199 + { "position": 61 },
  200 + { "position": 63 }
  201 + ],
  202 + "startingSeats":[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63]}
26 lib/bracket_tree/templates/double_elimination/4.json
... ... @@ -0,0 +1,26 @@
  1 +{
  2 + "nodes":[
  3 + { "seats":[1,3], "winnerTo":2, "loserTo":11 },
  4 + { "seats":[5,7], "winnerTo":6, "loserTo":13 },
  5 + { "seats":[2,6], "winnerTo":4, "loserTo":9 },
  6 + { "seats":[11,13], "winnerTo":12, "loserTo":null },
  7 + { "seats":[9,12], "winnerTo":10, "loserTo":null },
  8 + { "seats":[4,10], "winnerTo":null, "loserTo":null }
  9 + ],
  10 + "seats":[
  11 + { "position": 8 },
  12 + { "position": 4 },
  13 + { "position": 10 },
  14 + { "position": 9 },
  15 + { "position": 12 },
  16 + { "position": 11 },
  17 + { "position": 13 },
  18 + { "position": 2 },
  19 + { "position": 6 },
  20 + { "position": 5 },
  21 + { "position": 7 },
  22 + { "position": 1 },
  23 + { "position": 3 }
  24 + ],
  25 + "startingSeats":[1,3,5,7]
  26 +}
400 lib/bracket_tree/templates/double_elimination/64.json
... ... @@ -0,0 +1,400 @@
  1 +{
  2 + "seats": [
  3 + {"position": 128 },
  4 + {"position": 64},
  5 + {"position": 130},
  6 + {"position": 129},
  7 + {"position": 192},
  8 + {"position": 132},
  9 + {"position": 194},
  10 + {"position": 131},
  11 + {"position": 162},
  12 + {"position": 193},
  13 + {"position": 224},
  14 + {"position": 134},
  15 + {"position": 164},
  16 + {"position": 196},
  17 + {"position": 226},
  18 + {"position": 133},
  19 + {"position": 148},
  20 + {"position": 163},
  21 + {"position": 178},
  22 + {"position": 195},
  23 + {"position": 210},
  24 + {"position": 225},
  25 + {"position": 240},
  26 + {"position": 136},
  27 + {"position": 150},
  28 + {"position": 166},
  29 + {"position": 180},
  30 + {"position": 198},
  31 + {"position": 212},
  32 + {"position": 228},
  33 + {"position": 242},
  34 + {"position": 135},
  35 + {"position": 142},
  36 + {"position": 149},
  37 + {"position": 156},
  38 + {"position": 165},
  39 + {"position": 172},
  40 + {"position": 179},
  41 + {"position": 186},
  42 + {"position": 197},
  43 + {"position": 204},
  44 + {"position": 211},
  45 + {"position": 218},
  46 + {"position": 227},
  47 + {"position": 234},
  48 + {"position": 241},
  49 + {"position": 248},
  50 + {"position": 138},
  51 + {"position": 144},
  52 + {"position": 152},
  53 + {"position": 158},
  54 + {"position": 168},
  55 + {"position": 174},
  56 + {"position": 182},
  57 + {"position": 188},
  58 + {"position": 200},
  59 + {"position": 206},
  60 + {"position": 214},
  61 + {"position": 220},
  62 + {"position": 230},
  63 + {"position": 236},
  64 + {"position": 244},
  65 + {"position": 250},
  66 + {"position": 137},
  67 + {"position": 140},
  68 + {"position": 143},
  69 + {"position": 146},
  70 + {"position": 151},
  71 + {"position": 154},
  72 + {"position": 157},
  73 + {"position": 160},
  74 + {"position": 167},
  75 + {"position": 170},
  76 + {"position": 173},
  77 + {"position": 176},
  78 + {"position": 181},
  79 + {"position": 184},
  80 + {"position": 187},
  81 + {"position": 190},
  82 + {"position": 199},
  83 + {"position": 202},
  84 + {"position": 205},
  85 + {"position": 208},
  86 + {"position": 213},
  87 + {"position": 216},
  88 + {"position": 219},
  89 + {"position": 222},
  90 + {"position": 229},
  91 + {"position": 232},
  92 + {"position": 235},
  93 + {"position": 238},
  94 + {"position": 243},
  95 + {"position": 246},
  96 + {"position": 249},
  97 + {"position": 252},
  98 + {"position": 139},
  99 + {"position": 141},
  100 + {"position": 145},
  101 + {"position": 147},
  102 + {"position": 153},
  103 + {"position": 155},
  104 + {"position": 159},
  105 + {"position": 161},
  106 + {"position": 169},
  107 + {"position": 171},
  108 + {"position": 175},
  109 + {"position": 177},
  110 + {"position": 183},
  111 + {"position": 185},
  112 + {"position": 189},
  113 + {"position": 191},
  114 + {"position": 201},
  115 + {"position": 203},
  116 + {"position": 207},
  117 + {"position": 209},
  118 + {"position": 215},
  119 + {"position": 217},
  120 + {"position": 221},
  121 + {"position": 223},
  122 + {"position": 231},
  123 + {"position": 233},
  124 + {"position": 237},
  125 + {"position": 239},
  126 + {"position": 245},
  127 + {"position": 247},
  128 + {"position": 251},
  129 + {"position": 253},
  130 + {"position": 32},
  131 + {"position": 96},
  132 + {"position": 16},
  133 + {"position": 48},
  134 + {"position": 80},
  135 + {"position": 112},
  136 + {"position": 8},
  137 + {"position": 24},
  138 + {"position": 40},
  139 + {"position": 56},
  140 + {"position": 72},
  141 + {"position": 88},
  142 + {"position": 104},
  143 + {"position": 120},
  144 + {"position": 4},
  145 + {"position": 12},
  146 + {"position": 20},
  147 + {"position": 28},
  148 + {"position": 36},
  149 + {"position": 44},
  150 + {"position": 52},
  151 + {"position": 60},
  152 + {"position": 68},
  153 + {"position": 76},
  154 + {"position": 84},
  155 + {"position": 92},
  156 + {"position": 100},
  157 + {"position": 108},
  158 + {"position": 116},
  159 + {"position": 124},
  160 + {"position": 2},
  161 + {"position": 6},
  162 + {"position": 10},
  163 + {"position": 14},
  164 + {"position": 18},
  165 + {"position": 22},
  166 + {"position": 26},
  167 + {"position": 30},
  168 + {"position": 34},
  169 + {"position": 38},
  170 + {"position": 42},
  171 + {"position": 46},
  172 + {"position": 50},
  173 + {"position": 54},
  174 + {"position": 58},
  175 + {"position": 62},
  176 + {"position": 66},
  177 + {"position": 70},
  178 + {"position": 74},
  179 + {"position": 78},
  180 + {"position": 82},
  181 + {"position": 86},
  182 + {"position": 90},
  183 + {"position": 94},
  184 + {"position": 98},
  185 + {"position": 102},
  186 + {"position": 106},
  187 + {"position": 110},
  188 + {"position": 114},
  189 + {"position": 118},
  190 + {"position": 122},
  191 + {"position": 126},
  192 + {"position": 1},
  193 + {"position": 3},
  194 + {"position": 5},
  195 + {"position": 7},
  196 + {"position": 9},
  197 + {"position": 11},
  198 + {"position": 13},
  199 + {"position": 15},
  200 + {"position": 17},
  201 + {"position": 19},
  202 + {"position": 21},
  203 + {"position": 23},
  204 + {"position": 25},
  205 + {"position": 27},
  206 + {"position": 29},
  207 + {"position": 31},
  208 + {"position": 33},
  209 + {"position": 35},
  210 + {"position": 37},
  211 + {"position": 39},
  212 + {"position": 41},
  213 + {"position": 43},
  214 + {"position": 45},
  215 + {"position": 47},
  216 + {"position": 49},
  217 + {"position": 51},
  218 + {"position": 53},
  219 + {"position": 55},
  220 + {"position": 57},
  221 + {"position": 59},
  222 + {"position": 61},
  223 + {"position": 63},
  224 + {"position": 65},
  225 + {"position": 67},
  226 + {"position": 69},
  227 + {"position": 71},
  228 + {"position": 73},
  229 + {"position": 75},
  230 + {"position": 77},
  231 + {"position": 79},
  232 + {"position": 81},
  233 + {"position": 83},
  234 + {"position": 85},
  235 + {"position": 87},
  236 + {"position": 89},
  237 + {"position": 91},
  238 + {"position": 93},
  239 + {"position": 95},
  240 + {"position": 97},
  241 + {"position": 99},
  242 + {"position": 101},
  243 + {"position": 103},
  244 + {"position": 105},
  245 + {"position": 107},
  246 + {"position": 109},
  247 + {"position": 111},
  248 + {"position": 113},
  249 + {"position": 115},
  250 + {"position": 117},
  251 + {"position": 119},
  252 + {"position": 121},
  253 + {"position": 123},
  254 + {"position": 125},
  255 + {"position": 127}
  256 + ],
  257 + "nodes": [
  258 + {"seats": [1,3],"winnerTo": 2,"loserTo": 139},
  259 + {"seats": [2,6],"winnerTo": 4,"loserTo": 249},
  260 + {"seats": [5,7],"winnerTo": 6,"loserTo": 141},
  261 + {"seats": [4,12],"winnerTo": 8,"loserTo": 135},
  262 + {"seats": [9,11],"winnerTo": 10,"loserTo": 145},
  263 + {"seats": [10,14],"winnerTo": 12,"loserTo": 243},
  264 + {"seats": [13,15],"winnerTo": 14,"loserTo": 147},
  265 + {"seats": [8,24],"winnerTo": 16,"loserTo": 225},
  266 + {"seats": [17,19],"winnerTo": 18,"loserTo": 153},
  267 + {"seats": [18,22],"winnerTo": 20,"loserTo": 235},
  268 + {"seats": [21,23],"winnerTo": 22,"loserTo": 155},
  269 + {"seats": [20,28],"winnerTo": 24,"loserTo": 149},
  270 + {"seats": [25,27],"winnerTo": 26,"loserTo": 159},
  271 + {"seats": [26,30],"winnerTo": 28,"loserTo": 229},
  272 + {"seats": [29,31],"winnerTo": 30,"loserTo": 161},
  273 + {"seats": [16,48],"winnerTo": 32,"loserTo": 131},
  274 + {"seats": [33,35],"winnerTo": 34,"loserTo": 169},
  275 + {"seats": [34,38],"winnerTo": 36,"loserTo": 219},
  276 + {"seats": [37,39],"winnerTo": 38,"loserTo": 171},
  277 + {"seats": [36,44],"winnerTo": 40,"loserTo": 165},
  278 + {"seats": [41,43],"winnerTo": 42,"loserTo": 175},
  279 + {"seats": [42,46],"winnerTo": 44,"loserTo": 213},
  280 + {"seats": [45,47],"winnerTo": 46,"loserTo": 177},
  281 + {"seats": [40,56],"winnerTo": 48,"loserTo": 195},
  282 + {"seats": [49,51],"winnerTo": 50,"loserTo": 183},
  283 + {"seats": [50,54],"winnerTo": 52,"loserTo": 205},
  284 + {"seats": [53,55],"winnerTo": 54,"loserTo": 185},
  285 + {"seats": [52,60],"winnerTo": 56,"loserTo": 179},
  286 + {"seats": [57,59],"winnerTo": 58,"loserTo": 189},
  287 + {"seats": [58,62],"winnerTo": 60,"loserTo": 199},
  288 + {"seats": [61,63],"winnerTo": 62,"loserTo": 191},
  289 + {"seats": [32,96],"winnerTo": 64,"loserTo": 129},
  290 + {"seats": [65,67],"winnerTo": 66,"loserTo": 201},
  291 + {"seats": [66,70],"winnerTo": 68,"loserTo": 187},
  292 + {"seats": [69,71],"winnerTo": 70,"loserTo": 203},
  293 + {"seats": [68,76],"winnerTo": 72,"loserTo": 197},
  294 + {"seats": [73,75],"winnerTo": 74,"loserTo": 207},
  295 + {"seats": [74,78],"winnerTo": 76,"loserTo": 181},
  296 + {"seats": [77,79],"winnerTo": 78,"loserTo": 209},
  297 + {"seats": [72,88],"winnerTo": 80,"loserTo": 163},
  298 + {"seats": [81,83],"winnerTo": 82,"loserTo": 215},
  299 + {"seats": [82,86],"winnerTo": 84,"loserTo": 173},
  300 + {"seats": [85,87],"winnerTo": 86,"loserTo": 217},
  301 + {"seats": [84,92],"winnerTo": 88,"loserTo": 211},
  302 + {"seats": [89,91],"winnerTo": 90,"loserTo": 221},
  303 + {"seats": [90,94],"winnerTo": 92,"loserTo": 167},
  304 + {"seats": [93,95],"winnerTo": 94,"loserTo": 223},
  305 + {"seats": [80,112],"winnerTo": 96,"loserTo": 193},
  306 + {"seats": [97,99],"winnerTo": 98,"loserTo": 231},
  307 + {"seats": [98,102],"winnerTo": 100,"loserTo": 157},
  308 + {"seats": [101,103],"winnerTo": 102,"loserTo": 233},
  309 + {"seats": [100,108],"winnerTo": 104,"loserTo": 227},
  310 + {"seats": [105,107],"winnerTo": 106,"loserTo": 237},
  311 + {"seats": [106,110],"winnerTo": 108,"loserTo": 151},
  312 + {"seats": [109,111],"winnerTo": 110,"loserTo": 239},
  313 + {"seats": [104,120],"winnerTo": 112,"loserTo": 133},
  314 + {"seats": [113,115],"winnerTo": 114,"loserTo": 245},
  315 + {"seats": [114,118],"winnerTo": 116,"loserTo": 143},
  316 + {"seats": [117,119],"winnerTo": 118,"loserTo": 247},
  317 + {"seats": [116,124],"winnerTo": 120,"loserTo": 241},
  318 + {"seats": [121,123],"winnerTo": 122,"loserTo": 251},
  319 + {"seats": [122,126],"winnerTo": 124,"loserTo": 137},
  320 + {"seats": [125,127],"winnerTo": 126,"loserTo": 253},
  321 +
  322 + {"seats": [139,141],"winnerTo": 140,"loserTo": null},
  323 + {"seats": [145,147],"winnerTo": 146,"loserTo": null},
  324 + {"seats": [153,155],"winnerTo": 154,"loserTo": null},
  325 + {"seats": [159,161],"winnerTo": 160,"loserTo": null},
  326 + {"seats": [169,171],"winnerTo": 170,"loserTo": null},
  327 + {"seats": [175,177],"winnerTo": 176,"loserTo": null},
  328 + {"seats": [183,185],"winnerTo": 184,"loserTo": null},
  329 + {"seats": [189,191],"winnerTo": 190,"loserTo": null},
  330 + {"seats": [201,203],"winnerTo": 202,"loserTo": null},
  331 + {"seats": [207,209],"winnerTo": 208,"loserTo": null},
  332 + {"seats": [215,217],"winnerTo": 216,"loserTo": null},
  333 + {"seats": [221,223],"winnerTo": 222,"loserTo": null},
  334 + {"seats": [231,233],"winnerTo": 232,"loserTo": null},
  335 + {"seats": [237,239],"winnerTo": 238,"loserTo": null},
  336 + {"seats": [245,247],"winnerTo": 246,"loserTo": null},
  337 + {"seats": [251,253],"winnerTo": 252,"loserTo": null},
  338 +
  339 + {"seats": [143,146],"winnerTo": 144,"loserTo": null},
  340 + {"seats": [151,154],"winnerTo": 152,"loserTo": null},
  341 + {"seats": [157,160],"winnerTo": 158,"loserTo": null},
  342 + {"seats": [167,170],"winnerTo": 168,"loserTo": null},
  343 + {"seats": [173,176],"winnerTo": 174,"loserTo": null},
  344 + {"seats": [181,184],"winnerTo": 182,"loserTo": null},
  345 + {"seats": [187,190],"winnerTo": 188,"loserTo": null},
  346 + {"seats": [199,202],"winnerTo": 200,"loserTo": null},
  347 + {"seats": [205,208],"winnerTo": 206,"loserTo": null},
  348 + {"seats": [213,216],"winnerTo": 214,"loserTo": null},
  349 + {"seats": [219,222],"winnerTo": 220,"loserTo": null},
  350 + {"seats": [229,232],"winnerTo": 230,"loserTo": null},
  351 + {"seats": [235,238],"winnerTo": 236,"loserTo": null},
  352 + {"seats": [243,246],"winnerTo": 244,"loserTo": null},
  353 + {"seats": [249,252],"winnerTo": 250,"loserTo": null},
  354 + {"seats": [137,140],"winnerTo": 138,"loserTo": null},
  355 +
  356 + {"seats": [138,144],"winnerTo": 142,"loserTo": null},
  357 + {"seats": [152,158],"winnerTo": 156,"loserTo": null},
  358 + {"seats": [168,174],"winnerTo": 172,"loserTo": null},
  359 + {"seats": [182,188],"winnerTo": 186,"loserTo": null},
  360 + {"seats": [200,206],"winnerTo": 204,"loserTo": null},
  361 + {"seats": [214,220],"winnerTo": 218,"loserTo": null},
  362 + {"seats": [230,236],"winnerTo": 234,"loserTo": null},
  363 + {"seats": [244,250],"winnerTo": 248,"loserTo": null},
  364 +
  365 + {"seats": [179,186],"winnerTo": 180,"loserTo": null},
  366 + {"seats": [149,156],"winnerTo": 150,"loserTo": null},
  367 + {"seats": [165,172],"winnerTo": 166,"loserTo": null},
  368 + {"seats": [197,204],"winnerTo": 198,"loserTo": null},
  369 + {"seats": [211,218],"winnerTo": 212,"loserTo": null},
  370 + {"seats": [227,234],"winnerTo": 228,"loserTo": null},
  371 + {"seats": [241,248],"winnerTo": 242,"loserTo": null},
  372 + {"seats": [135,142],"winnerTo": 136,"loserTo": null},
  373 +
  374 + {"seats": [136,150],"winnerTo": 148,"loserTo": null},
  375 + {"seats": [228,242],"winnerTo": 240,"loserTo": null},
  376 + {"seats": [166,180],"winnerTo": 178,"loserTo": null},
  377 + {"seats": [198,212],"winnerTo": 210,"loserTo": null},
  378 +
  379 +
  380 + {"seats": [163,178],"winnerTo": 164,"loserTo": null},
  381 + {"seats": [195,210],"winnerTo": 196,"loserTo": null},
  382 + {"seats": [225,240],"winnerTo": 226,"loserTo": null},
  383 + {"seats": [133,148],"winnerTo": 134,"loserTo": null},
  384 +
  385 + {"seats": [134,164],"winnerTo": 162,"loserTo": null},
  386 + {"seats": [196,226],"winnerTo": 224,"loserTo": null},
  387 +
  388 + {"seats": [193,224],"winnerTo": 194,"loserTo": null},
  389 + {"seats": [131,162],"winnerTo": 132,"loserTo": null},
  390 +
  391 + {"seats": [132,194],"winnerTo": 192,"loserTo": null},
  392 +
  393 + {"seats": [129,192],"winnerTo": 130,"loserTo": null},
  394 +
  395 + {"seats": [64,130],"winnerTo": null,"loserTo": null}
  396 + ],
  397 + "startingSeats": [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,
  398 + 41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,
  399 + 89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127]
  400 +}
50 lib/bracket_tree/templates/double_elimination/8.json
... ... @@ -0,0 +1,50 @@
  1 +{
  2 +"nodes":[
  3 + { "seats": [1,3], "winnerTo": 2, "loserTo": 21 },
  4 + { "seats": [5,7], "winnerTo": 6, "loserTo": 23 },
  5 + { "seats": [9,11], "winnerTo": 10, "loserTo": 25 },
  6 + { "seats": [13,15], "winnerTo": 14, "loserTo": 27 },
  7 + { "seats": [2,6], "winnerTo": 4, "loserTo": 29 },
  8 + { "seats": [10,14], "winnerTo": 12, "loserTo": 19 },
  9 + { "seats": [21,23], "winnerTo": 22, "loserTo": null },
  10 + { "seats": [25,27], "winnerTo": 26, "loserTo": null },
  11 + { "seats": [4,12], "winnerTo": 8, "loserTo": 17 },
  12 + { "seats": [19,22], "winnerTo": 20, "loserTo": null },
  13 + { "seats": [26,29], "winnerTo": 28, "loserTo": null },
  14 + { "seats": [20,28], "winnerTo": 24, "loserTo": null },
  15 + { "seats": [17,24], "winnerTo": 18, "loserTo": null },
  16 + { "seats": [8,18], "winnerTo": null, "loserTo": null }
  17 +],
  18 +"seats":[
  19 + { "position":16 },
  20 + { "position":8 },
  21 + { "position":18 },
  22 + { "position":4 },
  23 + { "position":12 },
  24 + { "position":17 },
  25 + { "position":24 },
  26 + { "position":20 },
  27 + { "position":28 },
  28 + { "position":19 },
  29 + { "position":22 },
  30 + { "position":26 },
  31 + { "position":29 },
  32 + { "position":21 },
  33 + { "position":23 },
  34 + { "position":25 },
  35 + { "position":27 },
  36 + { "position":2 },
  37 + { "position":6 },
  38 + { "position":10 },
  39 + { "position":14 },
  40 + { "position":1 },
  41 + { "position":3 },
  42 + { "position":5 },
  43 + { "position":7 },
  44 + { "position":9 },
  45 + { "position":11 },
  46 + { "position":13 },
  47 + { "position":15 }
  48 +],
  49 +"startingSeats":[1,3,5,7,9,11,13,15]
  50 +}
11 lib/bracket_tree/templates/single_elimination.rb
... ... @@ -0,0 +1,11 @@
  1 +module BracketTree
  2 + module Template
  3 + class SingleElimination < Base
  4 + class << self
  5 + def location
  6 + File.join File.dirname(__FILE__), 'templates', 'single_elimination'
  7 + end
  8 + end
  9 + end
  10 + end
  11 +end
1,917 lib/bracket_tree/templates/single_elimination/128.json
... ... @@ -0,0 +1,1917 @@
  1 +{
  2 + "nodes": [
  3 + {
  4 + "seats": [
  5 + 1,
  6 + 3
  7 + ],
  8 + "winnerTo": 2,
  9 + "loserTo": null
  10 + },
  11 + {
  12 + "seats": [
  13 + 5,
  14 + 7
  15 + ],
  16 + "winnerTo": 6,
  17 + "loserTo": null
  18 + },
  19 + {
  20 + "seats": [
  21 + 9,
  22 + 11
  23 + ],
  24 + "winnerTo": 10,
  25 + "loserTo": null
  26 + },
  27 + {
  28 + "seats": [
  29 + 13,
  30 + 15
  31 + ],
  32 + "winnerTo": 14,
  33 + "loserTo": null
  34 + },
  35 + {
  36 + "seats": [
  37 + 17,
  38 + 19
  39 + ],
  40 + "winnerTo": 18,
  41 + "loserTo": null
  42 + },
  43 + {
  44 + "seats": [
  45 + 21,
  46 + 23
  47 + ],
  48 + "winnerTo": 22,
  49 + "loserTo": null
  50 + },
  51 + {
  52 + "seats": [
  53 + 25,
  54 + 27
  55 + ],
  56 + "winnerTo": 26,
  57 + "loserTo": null
  58 + },
  59 + {
  60 + "seats": [
  61 + 29,
  62 + 31
  63 + ],
  64 + "winnerTo": 30,
  65 + "loserTo": null
  66 + },
  67 + {
  68 + "seats": [
  69 + 33,
  70 + 35
  71 + ],
  72 + "winnerTo": 34,
  73 + "loserTo": null
  74 + },
  75 + {
  76 + "seats": [
  77 + 37,
  78 + 39
  79 + ],
  80 + "winnerTo": 38,
  81 + "loserTo": null
  82 + },
  83 + {
  84 + "seats": [
  85 + 41,
  86 + 43
  87 + ],
  88 + "winnerTo": 42,
  89 + "loserTo": null
  90 + },
  91 + {
  92 + "seats": [
  93 + 45,
  94 + 47
  95 + ],
  96 + "winnerTo": 46,
  97 + "loserTo": null
  98 + },
  99 + {
  100 + "seats": [
  101 + 49,
  102 + 51
  103 + ],
  104 + "winnerTo": 50,
  105 + "loserTo": null
  106 + },
  107 + {
  108 + "seats": [
  109 + 53,
  110 + 55
  111 + ],
  112 + "winnerTo": 54,
  113 + "loserTo": null
  114 + },
  115 + {
  116 + "seats": [
  117 + 57,
  118 + 59
  119 + ],
  120 + "winnerTo": 58,
  121 + "loserTo": null
  122 + },
  123 + {
  124 + "seats": [
  125 + 61,
  126 + 63
  127 + ],
  128 + "winnerTo": 62,
  129 + "loserTo": null
  130 + },
  131 + {
  132 + "seats": [
  133 + 65,
  134 + 67
  135 + ],
  136 + "winnerTo": 66,
  137 + "loserTo": null
  138 + },
  139 + {
  140 + "seats": [
  141 + 69,
  142