Miasma Community

Gaming Zone => [MiA] Servers => Topic started by: Piglet on January 28, 2022, 13:32

Title: VCTF - working on balancer
Post by: Piglet on January 28, 2022, 13:32
As you may have seen as you joined the server recently, there's an alpha version of some code that isn't yet actually doing anything unless it's manually triggered.

The_cowboy's base code is here: https://github.com/ravimohan1991/Equalizer/tree/c1665627b7dcc682ee3d4a203fd83c0cafb4d78d

I've taken that and shoved in a load of debug and a few changes: Download from here (https://miasma.rocks/temp/Classes.zip)

In summary what the code currently on the server does is:


I'm not 100% sure step 3 is working fully. I've seen times when data hasn't been requested/not received.

There is the beginning of ordering and preparation for team balancing at the start. The code sorts the players, currently by points scores per time period into what it thinks is a fair split.

There is code which is triggered from the map start which saves away what those teams would look like.

2022-01-27 22:00:28 0 I would have balanced to team 0 Snoop (UA) : 283.00
2022-01-27 22:00:28 1 I would have balanced to team 1 ^Darkside- (CL) : 260.00
2022-01-27 22:00:28 2 I would have balanced to team 1 Yes (UK) : 238.00
2022-01-27 22:00:28 3 I would have balanced to team 0 notthc (HU) : 233.00
2022-01-27 22:00:28 4 I would have balanced to team 1 Rounin_Napoli (IT) : 231.00
2022-01-27 22:00:28 5 I would have balanced to team 0 Lòón (AR) : 182.00
2022-01-27 22:00:28 6 I would have balanced to team 1 Steve (UK) : 168.00
2022-01-27 22:00:28 7 I would have balanced to team 0 Meganoob (TR) : 163.00
2022-01-27 22:00:28 8 I would have balanced to team 1 maelman (CA) : 123.00
2022-01-27 22:00:28 9 I would have balanced to team 0 Teammate (BE) : 120.00
2022-01-27 22:00:28 10 I would have balanced to team 1 Risel (RU) : 119.00
2022-01-27 22:00:28 11 I would have balanced to team 0 cronix (HR) : 94.00
2022-01-27 22:00:28 12 I would have balanced to team 1 UR18 (DE) : 85.00
2022-01-27 22:00:28 13 I would have balanced to team 0 javiar (US) : 82.00
2022-01-27 22:00:28 14 I would have balanced to team 1 TRAINING_DAY (US) : 77.00
2022-01-27 22:00:28 15 I would have balanced to team 0 chris (US) : 35.00
2022-01-27 22:00:28 16 I would have balanced to team 1 Bluecat77 (US) : 29.00


Next steps are:

1. Identify how to know a point just before map start, before players are spawned at which we can insert the logic to balance the teams. I've not yet looked for that place in the code. It's rather easier in Freon as that's its own gametype and you can add in anything you like right into the core of the game code.

2. Actually move the players between teams. The code in there looks right to me, but I think the test I ran yesterday ran foul of the "keep teams same size" mutator code which I've now removed from vctf. I also ran it after players spawned....which mean that some people got switched teams after spawning in what became the enemy base. One person was swapped whilst standing on what became an enemy manta!





Title: Re: VCTF - working on balancer
Post by: Caracal on January 28, 2022, 14:18
Great! Thank you!

Is it possible to add to the balancer so that e.g. me and Hellfire are most probably in the same team? I mean, there are few players who use discord, and when we do, we always try to change to the same team.
Title: Re: VCTF - working on balancer
Post by: Piglet on January 28, 2022, 14:47
Nah! The point of all of this is to balance out the teams. Not to load one team with the players that can work most efficiently together to win a game. If you want that then set up a clan and do clan wars. :D
Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 28, 2022, 22:21
Thanks Piglet. My entire energy is engaged in this now.
I have created an issue https://github.com/ravimohan1991/Equalizer/issues/4. Feel absolutely free to unload yourself there or here.
Title: Re: VCTF - working on balancer
Post by: Piglet on January 28, 2022, 22:40
Right. Another step forward.

I found a way to hook in to the point just before the players spawn at the start of the map by firing up a timer and watching the DeathMatch(level.game).startupStage variable. That's the one the game uses to track the start of game status changes - waiting, 3..., 2..., 1..., & over time. When it counts down....that's the time to do the balance; right before the spawn.

I'd hoped there would be an even there to hook on to. - but I couldn't see one.

The server should now be doing "start of game better than random" team allocation.

Time to remove lots of the debug and tidy.

Then to add in something to deal with uneven player count.
Title: Re: VCTF - working on balancer
Post by: holyspam on January 29, 2022, 06:34
  if( ( Level.Game.IsInState == 'PendingMatch' && Level.Game.bWaitingToStartMatch == True && Level.Game.bWaitForNetPlayers == False )
        || ShuffleTeams )
  {
       if ( ( Level.Game.Countdown <= TimeToBalance || Level.Game.bQuickStart ) || ShuffleTeams )
       {
         doFirstBalance();
       }
  }

  else if (Level.Game.IsInState == 'MatchInProgress' && balance_trigger_flag )
  {
         BeginBalance();
  }

defaultproperties
{

WhenToBalance=3 // So we can adjust the moment of first balance
balance_trigger_flag=false
}

This should work at all times, since "bQuickStart" will not trigger the countdown and StartupStage the actual variable that the game looks at is Countdown.

1. Allows us to adjust the time of balance instead of a hard-coded value.
2. Allows us to re-use the initial balance function as a "hard-balance" function to shuffle really bad teams mid-game and then a "soft-balance" function that executes on player joins/leaves or periodically
3. A few additional checks, to make sure it will run in the few moments before a game begins(Game is in state PendingMatch and WaitingToStartMatch variable is true) and only when enough real players have joined(bWaitForNetPlayers becomes false).

Or right before balance we add an extra 1-2 seconds to make sure all players(especially higher pings) have enough time to receive the team-change replication

if (Level.Game.Countdown > 0) Level.Game.Countdown += 1;

This will make the announcer say 3...2...1...1...play

**Disclaimer: I have not tried to compile all these,but they **should work**


It might be better to use "event" instead of function if you want to make sure the timing matches with native C code.
Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 29, 2022, 20:31
I know it is crucial time of Equalizer, but I believe the mid-game function call is highly required.
People are wiping in it
(https://i.imgur.com/OKvEt4g.png)

The good balancing logic is being mangled here!!
Title: Re: VCTF - working on balancer
Post by: Piglet on January 29, 2022, 21:16
People moaned about the old team player count code which stopped that happening. I'll add it back in again after checking whether it needs an update to stop it conflicting with this code.
Title: Re: VCTF - working on balancer
Post by: Piglet on January 29, 2022, 21:18
Ok - checked the code. They should play nicely together. It's back on from next map.
Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 29, 2022, 21:22
I believe the old code is completely redundant now that we have cherry picked aspects of it (in some sense the team switch).

The important issue is at what points in time (during the match) to call for BalanceCTFTeams() function. I believe summoning all the powers who demanded Equalizer in the first place should be useful.

Indirectly I am pointing towards Flenser(US), Gil-Galad(PT) and Cronix(HR). Let the discussion begin!

I shall start with the issue that what to do with the players deliberately spectating and then joining a stronger team.
Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 29, 2022, 21:25
Another is how to introduce bot-crowd. Right now, if three players flee, from a team, then maybe we can fill up that with vacancy with 3 bots? IDK!
Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 29, 2022, 21:35
Quote from: Piglet on January 29, 2022, 21:18
Ok - checked the code. They should play nicely together. It's back on from next map.

Ah just saw your post (that is what I hoped, says I).

Ignore my posts then!!!
Title: Re: VCTF - working on balancer
Post by: Piglet on January 29, 2022, 22:05
The current logic in the team-size code is:

1. If the teams are the same number you can't swap teams
2. If there is one fewer player on a team a bot is added. As a player joins or leaves the bot is removed
3. If there are two+ players fewer on a team it waits a bit then moves the shortest-time-playing player from the bigger to the smaller team.

Thoughts:

The code above is pretty good, other than the fact that sometimes the swapped player has the flag, howeber as you say it can be abused: People leave lower numbered team and then someone is swapped. Then rejoin. Maybe even rejoin the better team deliberately. Then you need kicking from the server...

Code could be added to prevent a player from rejoining after leaving or spectating. However it's not just problem players who need to leave temporarily. Maybe a countdown time before they can rejoin. Maybe can only rejoin the team they came from....but what if it's the bigger team by then? Do we push the player that was swapped or just joined to the other team?

It's not as easy to detail a good solution let alone code it.

Code could track which team you were on and whether you were moved teams mid-game
Title: Re: VCTF - working on balancer
Post by: Piglet on January 29, 2022, 22:10
In Freon (the version used here) the teams are re-balanced each time a high-value player joins or leaves, or at admin request.

The code picks a pair of players that have a history&current playing rating that most closely events the average historical&current playing rating of each team.

Freon is rather different though. The swaps happen at the end of a round and not mid-play (unless the teams get 2+ apart - then the code above is used to even the numbers not the player values)
Title: Re: VCTF - working on balancer
Post by: Piglet on January 30, 2022, 00:00
Code updated on the server and on the link (https://miasma.rocks/temp/Classes.zip) - for some reason "bAddToServerPackages=True" didn't work. No idea why. It sometimes does and sometimes doesn't - which caused the rather strange start to bloodbath earlier.

Lots of tidy-up. A little more functionality. Preparation for more code at some point.

Title: Re: VCTF - working on balancer
Post by: The_Cowboy on January 30, 2022, 06:51
So this is how you smuggle the spaces into the code  :D

(https://i.imgur.com/bg4DNuh.png)

On serious note, I got to learn crucial things. Thanks again!
Title: Re: VCTF - working on balancer
Post by: Piglet on January 30, 2022, 09:58
Ahhh - yes! You have to smuggle them in somehow.

I added in a message to say what team you were in for the start of map (whether you'd been swapped or not) then moved it to the main balance routine instead.

Title: Re: VCTF - working on balancer
Post by: -Adler- on April 16, 2023, 22:52
Hi
there are thousands of entries in the ut2004 log


Warning: EQHUDFCLocation VCTF-SummerVillages-beta2.EQHUDFCLocation (Function Equalizer_TC_alpha1.EQHUDFCLocation.ShowTeamScorePassA:03BC) Accessed None 'Team'

https://github.com/ravimohan1991/Equalizer/blob/c1665627b7dcc682ee3d4a203fd83c0cafb4d78d/Classes/EQHUDFCLocation.uc

and

Warning: RZQ_ScoreBoardTeamDeathMatch VCTF-Veniis-Rezq-Fix-1.RZQ_ScoreBoardTeamDeathMatch (Function RezQSc2b.RZQ_ScoreBoardDeathMatch.GetTitleString:00E8) Accessed None 'GRI'
Title: Re: VCTF - working on balancer
Post by: Piglet on April 17, 2023, 12:14
I noticed that too. It's not my code, but I'll have a look to see if I can fix it
Title: Re: VCTF - working on balancer
Post by: holyspam on April 23, 2023, 00:08
Quote from: Piglet on April 17, 2023, 12:14
I noticed that too. It's not my code, but I'll have a look to see if I can fix it


if (PlayerOwner.PlayerReplicationInfo == None || PlayerOwner.PlayerReplicationInfo.Team == None)
{
     return;
}

if( PlayerOwner.GameReplicationInfo.PRIArray[i].HasFlag != none && PlayerOwner.PlayerReplicationInfo.Team.TeamIndex == PlayerOwner.GameReplicationInfo.PRIArray[i].Team.TeamIndex && PlayerOwner.PlayerReplicationInfo != PlayerOwner.GameReplicationInfo.PRIArray[i] )
{
LPRI = PlayerOwner.GameReplicationInfo.PRIArray[i];
C.Font = LoadFontStatic(7);
C.StrLen("FC:"$LPRI.GetLocationName(), XL, YL);

if(LPRI.Team.TeamIndex == 0)
{
C.DrawColor = WhiteColor;
C.SetPos(C.ClipX / 2 + C.ClipX * 0.03, C.ClipY * 0.08);
}
else
{
C.DrawColor = WhiteColor;
C.SetPos(C.ClipX / 2 - C.ClipX * 0.03 - XL, C.ClipY * 0.08);
}

C.DrawText("FC:"$LPRI.GetLocationName());
break;
}



Also if PRIArray is a dynamic array, it could change length between loops, isn't "foreach" better suited here?
Title: Re: VCTF - working on balancer
Post by: sup on April 23, 2023, 01:17
Holy can you take a look at the netcode please?
it got a lot worse for players with high ping, I have to shoot with superhuman precision now. Darkside, Rompeculos, Tupi, Tirofijo all are complaining about it


(Sorry for the off-topic)
Title: Re: VCTF - working on balancer
Post by: California on April 23, 2023, 06:18
Quote from: sup on April 23, 2023, 01:17
Holy can you take a look at the netcode please?
it got a lot worse for players with high ping, I have to shoot with superhuman precision now. Darkside, Rompeculos, Tupi, Tirofijo all are complaining about it


(Sorry for the off-topic)

Daddy is struggling too. God bless all of you.
Title: Re: VCTF - working on balancer
Post by: Nardaq_NL on April 23, 2023, 15:25
Oh, lets all use high ping and have netcode aim assist. =]
Title: Re: VCTF - working on balancer
Post by: sup on April 24, 2023, 19:22
Lol try to use minigun with my ping and aim assist nardaq