agoragames/bracket_tree — pull request #3 by spaghetticode (2014-07-02 13:44:54+00:00)
Title: Single elimination template generator for 256 and above players json

Hi there, I need to generate json templates for trees with more than 128 players. So I did some reverse engineering on existing jsons, and built the single_elimination_generator.rb file to build these jsons.

I have a problem: I can't really understand the logic behind the json "seats" attributes.
* the first seat position, up to the 64.json file, is the double of the preceding seat (ie: 8 -> 24 for 16.json)
. On the 128 files instead it seems to be the sum of the 2 preceeding seats (64 + 192 = 256). I don't know how to unify the 2 behaviors in code.

* I can extrapolate the "seats" attribute order looking at the "seats" attribute in the "matches". I also have to reverse them in some ways, but the reversing strategy seems to be different for jsons below 32. Still, I'd like to unify the behavior.

The relevant code is the following, please excuse the bad quality but I wanted to be able to inspect the various steps in my specs:

```ruby
def populate_seats
@matches_seats = matches.map {|arr| arr.map {|a| a[:seats]}}
@ordered_seats = contenders < 32 ? @matches_seats.reverse.map {|a| a.reverse} : @matches_seats.reverse
@flat_seats = @ordered_seats.flatten
@first_seat = contenders > 64 ? @flat_seats.first + @flat_seats.second : @flat_seats.first*2
@all_seats = @flat_seats.unshift @first_seat
@object_seats = @all_seats.map! {|n| {:position => n} }
@seats = @object_seats
end
```

The code is in lib/bracket_tree/templates/single_elimination_generator.rb and the specs are in specs/single_elimination_json_generator_spec.rb

Once the issues are solved maybe you could consider merging this code, so that anyone can generate jsons with arbitrary numbers of players. Of course if you need some clarification please contact me.

Regards

Andrea