Verse Library verse

05 Defining The Algorithm

Shuffles players and assigns them to teams based on difference to achieve asymmetric balancing.

extracted-snippets/documentation/en-us/fortnite/triad-infiltration-03-balancing-teams-asymmetrically-in-verse/05-defining-the-algorithm.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/triad-infiltration-03-balancing-teams-asymmetrically-in-verse
# Local doc:  epic-docs/documentation/en-us/fortnite/triad-infiltration-03-balancing-teams-asymmetrically-in-verse.md
# Section:    Defining the Algorithm
# Balances all players on all teams in the game
BalanceTeams():void=
Logger.Print("Beginning to balance teams")
var AllPlayers:[]player := GetPlayspace().GetPlayers()
set AllPlayers = Shuffle(AllPlayers)
Logger.Print("AllPlayers Length is {AllPlayers.Length}")
for (TeamPlayer : AllPlayers):
var TeamToAssign:?team = false
set TeamToAssign = FindTeamWithLargestDifference()
if (AssignedTeam := TeamToAssign?, FortTeamCollection.AddToTeam[TeamPlayer, AssignedTeam]):
Logger.Print("Assigned player to a new team")

Comments

    Sign in to vote, comment, or suggest an edit. Sign in