Jump to content
Official BF Editor Forums
djbarney

Fix For Autobalance.py In Coop ?

Recommended Posts

I've had problems auto balancing bots in coop. I've seen a 48 "limit" cited before but this is not accurate as if there are more than 96 bots then one of the teams goes over 48. So there is no 48 limit.

Is there already a fix out there for this for the autobalance.py script that allows 50/50 balancing of bots for more than 96 bots ?

I've looked at the script and it does have AI support so I suspect there is a bug somewhere.

Share this post


Link to post
Share on other sites

The coop bot ratio maybe what you're looking for. Afaik its rather straight forward. Autobalance doesn't do anything with bots, else it wouldn't be any problem.

Afaik (I maybe wrong) the coop bot ratio is based on the ingame setting of how many bots exist, and not the one in mods/modname/ai.ai. Thus if the ingame number of bots differs from how many are set ingame, the teams may not be even.

Share this post


Link to post
Share on other sites

Hi!

The coop bot ratio maybe what you're looking for.

I'm looking through the Python Autobalance script now. Sv.CoopBotRatio is defined in the official BF2 1.5 Server server settings descriptions (xls spreadsheet file) as this ...

This determines the percentage of total bots that will be on Team 1, which is generally the MEC, Chinese, and their allies. This setting does not affect human players.

However I have to set it to 100 to get an even balance of 96 bots (48/48 bots + human players) which does not line up with the description. Setting it to 50 ends up with too many bots on one team (84/24 with 108 bots) which suggests to me bugged Python code. This is with sv.TeamRatioPercent set to 100.

This ratio represents how autoBalanceTeam considers the desired ratio between team 1 and team 2. The percent represents what percent of team 1's current players is considered 'even' for team 2.

Bots numbers are set to the same level in aidefault.con and in serversettings.con.

Afaik its rather straight forward. Autobalance doesn't do anything with bots, else it wouldn't be any problem.

Well, first of all I don't think this is straight forward because I suspect the Autobalance.py Python script is bugged. Hence the server settings never make sense. Hence all the confusion I have seen out there over these settings. Whatever they are set to just seems to cause more confusion. Confusion that can only be solved by going through the Autobalance.py Python script with a fine tooth comb, as I'm doing.

Secondly, the Autobalance.py Python script does do something with bots (but not the right thing) as the scripting has clear references to detecting AI players and doing balancing with them.

Afaik (I maybe wrong) the coop bot ratio is based on the ingame setting of how many bots exist, and not the one in mods/modname/ai.ai.

I'm setting bots in the serversettings.con file ... sv.coopBotCount 108, sv.maxPlayers 109.

Thus if the ingame number of bots differs from how many are set ingame, the teams may not be even.

I have the same number of bots set in aidefault.con.

Here is the relevant part of the serversettings.con. This is with BF2 1.5 and non-ranked BF2 1.5 Windows Server.

sv.autoBalanceTeam 1

sv.teamRatioPercent 100

sv.coopBotRatio 50 // SHOULD WORK WITH OVER 96 BOTS BUT DOES NOT. SET TO 100 IT WORKS WITH <=86 BOTS.

sv.coopBotCount 108

sv.maxPlayers 109

Here is the autobalance script. My comments in CAPITALS.

# team autobalance system

import bf2
import host
from bf2 import g_debug



def init():
if g_debug: print 'initializing autobalance script'

host.registerHandler('PlayerConnect', onPlayerConnect, 1)	
host.registerHandler('PlayerDeath', onPlayerDeath)
host.registerHandler('PlayerChangeTeams', onPlayerChangeTeams)



def onPlayerConnect(p):

# dont teamswitch alive players, or they will have the wrong teams kit 
if p.isAlive(): return

# place player on the team with least players
team1 = 0
team2 = 0
for tp in bf2.playerManager.getPlayers(): 	# THIS INCLUDES AI PLAYERS.
	if tp != p:
		if tp.getTeam() == 1: team1 += 1
		else: team2 += 1	

team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0		
if team2 > team1:
	p.setTeam(1)
else:
	p.setTeam(2)



def onPlayerDeath(p, vehicle):		

if not bf2.serverSettings.getAutoBalanceTeam(): return

if p.isSquadLeader(): return		
if p.isCommander(): return	

if (host.ss_getParam('gameMode') == "gpm_coop") and p.isAIPlayer(): 	# THIS SUGGESTS THAT NOTHING IS DONE ON THE DEATH OF AN AI BOT.
	return

# dont use autobalance when its suicide/changes team
if p.getSuicide(): 
	p.setSuicide(0)
	return

aiPlayerBalance = 0 	# BUT THEN WHAT IS THIS ?
team1 = 0
team2 = 0
for tp in bf2.playerManager.getPlayers():	
	if tp.getTeam() == 1:
		team1 += 1
	else:
		team2 += 1
	if tp.isAIPlayer():
		aiPlayerBalance += 1
	else:
		aiPlayerBalance -= 1					

if host.sgl_getIsAIGame():
	if not (host.ss_getParam('gameMode') == "gpm_coop"):
		if not (aiPlayerBalance < 0):		
			if not p.isAIPlayer():
				return

team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0

if (p.getTeam() == 1):
	if (team2+1) < team1:
		p.setTeam(2)			
elif (p.getTeam() == 2):
	if (team1+1) < team2:
		p.setTeam(1)			



def onPlayerChangeTeams(p, humanHasSpawned):

if not bf2.serverSettings.getAutoBalanceTeam(): return

# dont teamswitch alive players, or they will have the wrong teams kit 
if p.isAlive(): return

if host.sgl_getIsAIGame() and not (host.ss_getParam('gameMode') == "gpm_coop"):
	if humanHasSpawned: return
	if p.isAIPlayer(): return

	# handling aiplayer team change autobalance when round not started
	team = p.getTeam()	
	aiplayer = 0	

	for tp in bf2.playerManager.getPlayers():		
		if aiplayer == 0 and tp.getTeam() == team and tp.isAIPlayer(): 
			aiplayer = tp
			break

	if aiplayer: 	# THERE IS SOMETHING ABOVE THAT LOOKS LIKE IT IS EXCLUDING THE AI, BUT THEN WE HAVE "aiplayer.setTeam" BELOW IT SUGGESTING THE CAPABILITY TO SET AI AUTOBALANCE PROPERLY.
		if p.getTeam() == 1: aiplayer.setTeam(2)
		else: aiplayer.setTeam(1)

else:
	# checking to see if player is allowed to change teams
	team1 = 0
	team2 = 0
	for tp in bf2.playerManager.getPlayers():	
		if tp.getTeam() == 1: team1 += 1
		else: team2 += 1
	if abs(team1 - team2) > 1:
		if p.getTeam() == 1: p.setTeam(2)
		else: p.setTeam(1)

So the game is capable of balancing bots as I have seen it do properly for up to 96 bots (48/48). This is the officially supported number of bots as we can see if the BF2ServerLauncher is used. But the game engine can handle more then 48 bots if the bot number is taken over 96 bots ... because there will be more than 48 bots on one of the teams. They just aren’t balanced properly. It is highly likely that this is something to do with the autobalance script that DICE never got round to fixing. However in 2142 you can have over 96 bots balancing 50/50 so I should take a look at the 2142 script :).

I'm making a mod for Forgotten Hope to hardware accelerate the bots (multi CPU cores) and to quick start maps and switch to new maps from the in game GUI. So it would be nice to get this fixed as FH (and presumably other mods) really come alive with as many bots as possible as they fill all the gun positions and bring the entire thing to life for coop and single players.

Share this post


Link to post
Share on other sites

The autobalance script is not to blame as CoopBotRatio does not even appear in it. I can't find it anywhere else though so it is probably hardcoded.

Some testing reveals the following:

-Sv.CoopBotRatio seems to be irrelevant at these player numbers.

-Deactivating the autobalance script completely will still put exactly 32 AI players into team 1.

-Even with p.setTeam(1) in the connect event (which is called for AI as well) the results are the same.

However one can iterate through all players at an appropriate moment (when the game starts and when the first human player connects) and assign the teams correctly. Some bots will be without a squad even though there is room.

def init():
if g_debug: print 'initializing autobalance script'

host.registerHandler('PlayerConnect', onPlayerConnect,1)	
host.registerHandler('PlayerDeath', onPlayerDeath)
host.registerHandler('PlayerChangeTeams', onPlayerChangeTeams)
       host.registerGameStatusHandler(onGameStatusChanged)

def fixai():
       bots=[]
       for p in bf2.playerManager.getPlayers():
               if p.isAIPlayer():
                       bots.append(p)
       numbots=len(bots)
       for i in range(numbots):
               if i<numbots/2:
                       bots[i].setTeam(1)
               else:
                       bots[i].setTeam(2)

def onGameStatusChanged(status):
       if status == bf2.GameStatus.Playing:
               fixai()

def onPlayerConnect(p):
# dont teamswitch alive players, or they will have the wrong teams kit 
if p.isAlive(): return
if p.isAIPlayer(): return

       humans=0
       for tp in bf2.playerManager.getPlayers():
               if not tp.isAIPlayer():
                       humans+=1
       if humans==1:
               fixai()

[...]

Edited by Frankelstner

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...