• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Maths help...

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
Hi,

I've been banging my head against this for a while and I just cannot work out the formula...so I thought I'd ask for help!

I have an arena map and I'm working on a function to randomise teams, you can have teams of 2,3,4,6, and 12 (with a total of 24 players available). Where I'm struggling is I had a function that added a random player a player group index, then when that player group had the required number of players it'd bump up to the next index. My problem is working out how to balance the number of players if there isn't a full set of players. For example

if you want to play as teams of 12, but only have 20 players, it needs to work out to bump up the index at 10 players. I have this one working but it doesn't work with the other team sizes.

When I tried 20 players with teams of 2 it calculated 1.6 players per team, which then is rounded down so everyone is on their own team...

I'm sure there's a simple formula for this but my lord am I struggling to work it out

See my trigger below (team size is set up in a seperate trigger - All_Players is a seperate player group variable that only includes active players)

Code:
Randomise Teams
    Events
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Or - Any (Conditions) are true
                    Conditions
                        (Number of players in TeamGroup[TeamCount]) Equal to TeamSize
                        (Number of players in TeamGroup[TeamCount]) Equal to ((Number of players in Players_All) / (24 / TeamSize))
            Then - Actions
                Set VariableSet TeamCount = (TeamCount + 1)
            Else - Actions
                Set VariableSet TempPlayer = (Random player from TempPlayerGroup)
                Set VariableSet PlayerTeamNumber[(Player number of TempPlayer)] = TeamCount
                Player Group - Add TempPlayer to TeamGroup[TeamCount]
                Player Group - Remove TempPlayer from TempPlayerGroup.

EDIT: A bit I took out of this copied trigger is if "TempPlayerGroup" has any players in it the trigger then repeats itself
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Add 0.99 to your Real and it should always round up once converted to an Integer. This way even if the formula calculated 1.01 players per team, it would result in 2 (1.01 + 0.99 = 2.00 -> 2).

Regarding "if you want to play as teams of 12, but only have 20 players, it needs to work out to bump up the index at 10 players. I have this one working but it doesn't work with the other team sizes."

I believe the solution for that would be something like this:
  • set var teamSize = what you want the team sizes to be
  • set var totalPlayers = the total amount of players in the game
  • set var halfSize = totaPlayers / 2
  • set var newTeamSize = teamSize
  • if teamSize > halfSize then
  • --> for loop Integer A from 1 to halfSize do
  • ----> if newTeamSize > halfSize then
  • -------> set var newTeamSize = newTeamSize - 1
With this design, newTeamSize will either be updated (the bump up you described) or remain the same (it worked by default so no changes were necessary). Ideally, you'd break out of the loop once newTeamSize is equal to halfSize for the sake of efficiency.

There's definitely some simpler method that can be done here but I think it should work...
 
Last edited:
Level 13
Joined
Oct 16, 2010
Messages
731
Thanks for the help, I had a think about it and decided to just change how the options work. Now when the dialog is first created each of the options are made by checking what equal teams can be made with the number of players in the game. This does limit the options for a game with a prime number of players...but I'm thinking of how to get around that...

Think I need a line that works out that a slightly uneven team isn't too bad (Aka 11 players, 1 team of 5 and 1 team of 6 is acceptable. But 5v5v1 is not)

EDIT: I got it to work! Think it looks pretty cool too :D

1621973810633.png
 
Last edited:
Status
Not open for further replies.
Top