82 % 4 = 2
Player 3 will be going first!
New number: 93
82 % 4 = 2
Player 3 will be going first!
New number: 93
63 / 4 = 15.75
15.75 - 15 = 0.75
0.75 * 4 = 3 (Therefore player 4 goes first)
In code: 63 % 4 = 3 (donβt know enough about code to actually do it)
93 % 4 = 1 (Therefore player 2 goes first)
New Number: 55
1%4 = 0.25
0.25*4 = 1
Player 2 turn.
Next Number: 148
I took a bit of a different approach to solving this. I ran a while loop that would generate a new player from a list of players. This is in javascript:
// player array
const players = [{ name: "newt", turn: 0 }, { name: "ripley", turn: 0 }, { name: "hicks", turn: 0 }, { name: "apone", turn: 1}];
// set global turn order array
let turnOrder = [];
// get random number helper fn
function getRandomInteger(max) {
return Math.round(Math.random() * max);
}
// check if a number is in an array
function validatePlayer(num, arr) {
if (!arr) {
console.error("no array has been passed");
return;
}
if (!arr.includes(num)) {
return true;
}
}
// update global turn order array fn
function setTurnOrder() {
// while loop to test if the arrays line up
while (turnOrder.length < players.length) {
let nextPlayer = getRandomInteger(players.length - 1);
// check if that player has already been assigned
if (validatePlayer(nextPlayer, turnOrder)) {
// if they haven't, then add them to the array
players[nextPlayer].turn = turnOrder.length
turnOrder.push(nextPlayer);
}
}
}
setTurnOrder()
console.log(players, turnOrder)```