VCTF - working on balancer  (Read 36494 times)

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
VCTF - working on balancer
« 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

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

  • Track player achievements
  • Save away those achievements to an external database - communication is server-server over http to a php backend
  • On joining the server, for achievements are requested and sourced from the external database

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.

Code: [Select]
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!






Caracal

  • Sr. Member
  • *
  • Posts: 138
  • Country: ru
    • caracalRus
Re: VCTF - working on balancer
« Reply #1 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.

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #2 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

The_Cowboy

  • 1337
  • *
  • Posts: 259
  • Country: in
  • CodeZilla
Re: VCTF - working on balancer
« Reply #3 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.
Quote from: Wormbo
You learn UnrealScript mainly by reading other people's code. Removing code without an important reason (download size reduction and lack of helpfulness are not important in that sense) is extremely antisocial IMHO.

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #4 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.

holyspam

  • 1337
  • *
  • Posts: 343
  • Country: gr
Re: VCTF - working on balancer
« Reply #5 on: January 29, 2022, 06:34 »
Code: [Select]
  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
Code: [Select]
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.
« Last Edit: January 29, 2022, 10:51 by holyspam »

The_Cowboy

  • 1337
  • *
  • Posts: 259
  • Country: in
  • CodeZilla
Re: VCTF - working on balancer
« Reply #6 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


The good balancing logic is being mangled here!!
Quote from: Wormbo
You learn UnrealScript mainly by reading other people's code. Removing code without an important reason (download size reduction and lack of helpfulness are not important in that sense) is extremely antisocial IMHO.

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #7 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.

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #8 on: January 29, 2022, 21:18 »
Ok - checked the code. They should play nicely together. It's back on from next map.

The_Cowboy

  • 1337
  • *
  • Posts: 259
  • Country: in
  • CodeZilla
Re: VCTF - working on balancer
« Reply #9 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.
Quote from: Wormbo
You learn UnrealScript mainly by reading other people's code. Removing code without an important reason (download size reduction and lack of helpfulness are not important in that sense) is extremely antisocial IMHO.

The_Cowboy

  • 1337
  • *
  • Posts: 259
  • Country: in
  • CodeZilla
Re: VCTF - working on balancer
« Reply #10 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!
Quote from: Wormbo
You learn UnrealScript mainly by reading other people's code. Removing code without an important reason (download size reduction and lack of helpfulness are not important in that sense) is extremely antisocial IMHO.

The_Cowboy

  • 1337
  • *
  • Posts: 259
  • Country: in
  • CodeZilla
Re: VCTF - working on balancer
« Reply #11 on: January 29, 2022, 21:35 »
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!!!
Quote from: Wormbo
You learn UnrealScript mainly by reading other people's code. Removing code without an important reason (download size reduction and lack of helpfulness are not important in that sense) is extremely antisocial IMHO.

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #12 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

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #13 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)

Piglet

  • 1337
  • *
  • Posts: 3253
  • Country: gb
Re: VCTF - working on balancer
« Reply #14 on: January 30, 2022, 00:00 »
Code updated on the server and on the link - 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.