Skip to content

Conversation

@aflock
Copy link
Owner

@aflock aflock commented Oct 1, 2013

not ready for merge yet.

cc @nateberkopec this takes care of no duplicate pairings with a sorted tree algorithm :P needs to be debugged/tested but take a look

swiss.rb Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was avoiding 1.9+ hash syntax so we could keep 1.8.7 compat, so you dont need to install new rubies to run this on a generic Mac lappy

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you are so right

@nateberkopec
Copy link
Contributor

  generate pairings based on match score
  for each pair
    pair allowed?
    if pair not allowed
      find players with same match score (players with same match score (if any))
      try to pair with them
      if cant pair with same match score
        look for neighbors (players with next highest and next lowest match scores)
        try to pair with them
        if cant pair with neighbors
          try to pair with next level of neighbors (players with next highest match score than the previous step, etc)
          ...keep going until sorted all pairings valid
   end

i think this is what youre doing, if not, plz enlighten

@aflock
Copy link
Owner Author

aflock commented Oct 1, 2013

Not exactly- the problem with that approach is in some cases you can pick valid pairings all the way down, but still be left with two people who have already played each other at the bottom.

what happens now is we do the old fashioned sort n slice, but if that doesn't work, do the following:

for each valid pairing C:
  start a chain of pairing C - [] - [] -[] (or get passed an existing one)
  find which pairings are still valid after having chosen C, 
  recursively call this method with the new pairings and the current chain

once a chain is the required length you return it and we have the pairings.

so this will be pretty random pairings but will all be valid. To make it less random we can sort all the potential pairings so the most desirable ones (people with the same match score) are considered first

@nateberkopec
Copy link
Contributor

oh alright, your approach makes a lot more sense. I get it now. I see why you need the sorting part as well.

@aflock
Copy link
Owner Author

aflock commented Dec 2, 2013

this works now and i made it ruby 1.8.x compatible I THINK cc @nateberkopec

@nateberkopec
Copy link
Contributor

Syntax check works on 1.8.7, I didn't debug anything else tho

$ rbenv shell 1.8.7-p358
$ ruby -c swiss.rb 
Syntax OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants