Untitled
unknown
javascript
3 years ago
2.1 kB
12
Indexable
const team1 = [ "jktskinny", "jktskiny24", "jkt48skinny", "jkt29skinny", "jktskin21" ]
const team2 = [ "raincurva", "arifcnp", "revan1928", "rj19", "ivancurva" ]
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function war(whiteTeam, blackTeam, totalRound = 5) {
let currentRound = 0
let whiteTeamScore = 0
let blackTeamScore = 0
while (whiteTeamScore < totalRound && blackTeamScore < 5) {
const white = whiteTeam.slice()
const black = blackTeam.slice()
shuffleArray(white)
shuffleArray(black)
while (white.length && black.length) {
const participants = [{ self: white.shift(), team: white }, { self: black.shift(), team: black }]
const killedPlayerIndex = Math.round(Math.random())
const killedPlayer = participants[killedPlayerIndex]
participants.splice(killedPlayerIndex, 1)
const winningPlayer = participants[0]
killedPlayer.self.death++
winningPlayer.self.kill++
winningPlayer.team.push(winningPlayer.self)
console.log(`${winningPlayer.self.name} [ ${winningPlayer.self.kill} ] kill ${killedPlayer.self.name} [ ${killedPlayer.self.kill} ]`)
console.log(`Current Score: White Team [ ${whiteTeamScore} ] | Black Team [ ${blackTeamScore} ]`)
console.log("\n")
}
if (white.length) {
console.log("WHITE TEAM WIN")
whiteTeamScore++
}
if (black.length) {
console.log("BLACK TEAM WIN")
blackTeamScore++
}
currentRound++
}
console.log({ whiteTeam, blackTeam })
return { whiteTeam, blackTeam }
}
const curvaNord = team1.map(t => ({ name: t, kill: 0, death: 0 }))
const jktSkinny = team2.map(t => ({ name: t, kill: 0, death: 0 }))
war(curvaNord, jktSkinny)
Editor is loading...