import { factions, messages, voidPlayer } from "./constants.js" import {shuffle, splitArray, checkRemovedCount, annotateArray, getRandomItem, removeFromArray, insertEntriesRandomlyIntoArray } from "./utils.js" // Game options const players = ["Fletch", "Al", "Mouse", "Ash", "Maddie"] const binnedFactions = ["Clan of Saar", "Xxcha Kingdom"] const voidPlayerCount = 1; // 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) } // Ensure all players get an equal number of choices by calculating the number // of factions that should be removed for an even split const numFactionsToBin = factionsToUse.length % players.length // Shuffle/randomise the factions, use the number from above to make it an even // split, then split them into groups equal to the number of players const groupedFactions = splitArray( removeFromArray( shuffle(factionsToUse), numFactionsToBin ), 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) // Insert Void player(s) when required (to keep an even map) const playerLayout = insertEntriesRandomlyIntoArray(orderedPlayers, voidPlayerCount, voidPlayer) // Output all this to console playerLayout.forEach((player, index) => { const isSpeaker = player === speaker ? messages.speaker : messages.blank const isVoid = player === voidPlayer ? messages.voidPlayer : messages.blank const playerNumber = index + 1 const playerFactions = (selections[player] || []).join(", "); console.log(`Player ${playerNumber}: ${player} ${[isSpeaker, isVoid].join(" ")}`) console.log(`Factions: ${playerFactions}`) console.log(messages.divider) })