Message Boards Message Boards

2
|
5010 Views
|
2 Replies
|
5 Total Likes
View groups...
Share
Share this post:
GROUPS:

Fantasy Football Draft Board Generator

Posted 11 years ago
I needed a way to randomly order a list of people for my fantasy football league. This was pretty simple to do using RandomSample[], but the final ouput left something to be desired!
RandomSample[{"Jim", "Bob", "Dave"}, 3]
Out= {"Dave", "Bob", "Jim"}

So, wanting something that could be a little cleaner, I created a more robust function that actually creates the full draft list for nrounds, assuming you wanta snake (rather than linear) draft order.
 DraftOrder[players_, rounds_] := {
   playerorder = RandomSample[players, Length[players]];
   Do[
    Print[Style[StringJoin["Round ", IntegerString[currentround]],
      "Section"]];
    Do[
     prefacestring =
      StringJoin["Draft pick number ", IntegerString[i], " goes to "];
     finalstring =
     StringJoin[prefacestring, ToString[playerorder[[i]]]];
    Print[Style[finalstring, "Text"]], {i, 1, Length[players], 1}];
   playerorder = Reverse[playerorder];
   , {currentround, 1, rounds}]
  }
[/i][/i]
The function can then be called with
DraftOrder[{"Bill", "Jim", "Dave", "Sam", "Adam", "Matt"}, 18]

If anyone wants to lend a helping hand, there was one sticky issue I couldn't work around. I wanted the rounds parameter to have a default value, so that if you only pass in a list of players it automatically gives you, say, 14 rounds. Using a function definition like
DraftOrder[players_, rounds_:1] :=
didn't work, and I couldn't seem to find a reason why.

Anyway, I hope someone besides me gets at least a little use out of this bit of code.
POSTED BY: Ben Hammerslag
2 Replies
Well, I'm not sure why that wasn't working for me before, but I got it working by upgrading from 9.0.0 to 9.0.1.

It seems like a weird thing to be broken by missing that upgrade, but it fixed it.
POSTED BY: Ben Hammerslag
This seems to work for me: 
 DraftOrder[players_, rounds_: 10] := {playerorder =
    RandomSample[players, Length[players]];
   Do[Print[
     Style[StringJoin["Round ", IntegerString[currentround]],
      "Section"]];
    Do[prefacestring =
      StringJoin["Draft pick number ", IntegerString[i], " goes to "];
     finalstring =
      StringJoin[prefacestring, ToString[playerorder[[i]]]];
    Print[Style[finalstring, "Text"]], {i, 1, Length[players], 1}];
   playerorder = Reverse[playerorder];, {currentround, 1, rounds}]}

DraftOrder[{"Bill", "Jim", "Dave", "Sam", "Adam", "Matt"}]
POSTED BY: Shenghui Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract