Skip to content

Instantly share code, notes, and snippets.

@tnoworyta
Last active April 10, 2019 12:15
Show Gist options
  • Save tnoworyta/3cf74253d10d09fa69f6fa0d4b71c9a2 to your computer and use it in GitHub Desktop.
Save tnoworyta/3cf74253d10d09fa69f6fa0d4b71c9a2 to your computer and use it in GitHub Desktop.

Create a board games tournament planner

There is a board games day scheduled and organizers would like to automatically get a list of all possible game tournaments & players that will take place during that day according to the preference of the attendees.

The organizers have created an online poll where attendees could select multiple game titles they would like to play that day. The data have already been collected and is represented through class Player. One player has a name and can have multiple games associated with him/her (these are the game names that the player would like to play).

There is needed of course another class for Game which would only consist of name, ranking (integer from range 1-10, signifies in what order the games should be considered for tournaments, the higher the ranking the game should be taken first into consideration for matching) and max_players_count (always even number).

Finally we need some logic that takes Player objects, Game objects and performs matching - could be a function or separate class. The result will be all possible combinations of the games that can be played during the day and the list of their players according to preferences.

Criteria for choosing games and matching them with players:

  • minimum number of players for any game is 2 players
  • maximum number of players is determined by object game#max_players_count, however the number of players always needs to be even (if there is more players than the limit or number of players is odd then allocate only the valid amount of players)
  • players expressed interst it that game
  • when particular game does not satisfy this requirements, then it can be rejected

Tasks

  • Create a Ruby script that implements aforementioned logic.
  • Prepare some example setup data for possible Players and Games.
  • Implement planning logic taking into account the rules and constraints of games.
  • Prints out final game turnaments table (each row consists of Game name, list of player names) in descending order of ranking.
  • Also print out list of games that were excluded (no one wanted to play them, they didn't have required amount of minimal players, the number of player was odd, or their ranking was low and players were already allocated to games with higher ranking)

Example data

  • Player => name: John, games: Chess, Takenoko

  • Player => name: Alice, games: Takenoko, Black Sail

  • Player => name: Tom, games: Takenoko, Chess

  • Game => Chess, ranking: 2, max players: 6

  • Game => Takenoko, ranking: 9, max players: 10

  • Game => Black Sail, ranking: 3, max players: 6

Printout:

  • Takenoko, players: John, Alice
  • Chess, players: John, Tom
  • Rejected: Black Sail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment