index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { factions, messages } from "./constants.js"
  2. import {shuffle, splitArray, checkRemovedCount, annotateArray, getRandomItem } from "./utils.js"
  3. // Game options
  4. const players = ["Fletch", "Al", "Mike", "Ash", "Maddie"]
  5. const binnedFactions = ["Argent Flight"]
  6. // Remove any binned factions
  7. const factionsToUse = factions.filter(faction => !binnedFactions.includes(faction))
  8. // Just in case a binned faction was spelled wrong or something
  9. if (!checkRemovedCount(factions, factionsToUse, binnedFactions)) {
  10. throw new Error(messages.badBinnedFaction)
  11. }
  12. // Shuffle/randomise the factions then split them into groups equal to the number of players
  13. const groupedFactions = splitArray(shuffle(factionsToUse), players.length)
  14. // Shuffle/randomise the order of players
  15. const orderedPlayers = shuffle(players)
  16. // Assign factions
  17. const selections = annotateArray(orderedPlayers, groupedFactions)
  18. // Pick speaker
  19. const speaker = getRandomItem(orderedPlayers)
  20. // Output all this to console
  21. orderedPlayers.forEach(player => {
  22. const playerFactions = selections[player].join(", ");
  23. console.log(`Player: ${player}`)
  24. if (speaker === player) {
  25. console.log("[SPEAKER]")
  26. }
  27. console.log(`Factions: ${playerFactions}`)
  28. console.log(messages.divider)
  29. })