| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { factions, messages } from "./constants.js"
- import {shuffle, splitArray, checkRemovedCount, annotateArray, getRandomItem } from "./utils.js"
- // Game options
- const players = ["Fletch", "Al", "Mike", "Ash", "Maddie"]
- const binnedFactions = ["Argent Flight"]
- // Remove any binned factions
- const factionsToUse = factions.filter(faction => !binnedFactions.includes(faction))
- // Just in case a binned faction was spelled wrong or something
- if (!checkRemovedCount(factions, factionsToUse, binnedFactions)) {
- throw new Error(messages.badBinnedFaction)
- }
- // Shuffle/randomise the factions then split them into groups equal to the number of players
- const groupedFactions = splitArray(shuffle(factionsToUse), players.length)
- // Shuffle/randomise the order of players
- const orderedPlayers = shuffle(players)
- // Assign factions
- const selections = annotateArray(orderedPlayers, groupedFactions)
- // Pick speaker
- const speaker = getRandomItem(orderedPlayers)
- // Output all this to console
- orderedPlayers.forEach(player => {
- const playerFactions = selections[player].join(", ");
- console.log(`Player: ${player}`)
- if (speaker === player) {
- console.log("[SPEAKER]")
- }
- console.log(`Factions: ${playerFactions}`)
- console.log(messages.divider)
- })
|