[bfprog] autobalance

Anton Jansen gradius at fmf.nl
Tue Jun 21 11:56:30 PDT 2005


ScratchMonkey wrote:

> Over on the Icculus server list was mention of a patch to 
> admin/standard_admin/autobalance.py to exclude squad members from the 
> autobalance decision:
>
> diff -rw 
> bf2-linuxded-1.0.2442.0-ORIGINAL/admin/standard_admin/autobalance.py 
> bf2-linuxded-1.0.2442.0/admin/standard_admin/autobalance.py
> 35a36,40
>
>>       # Only balance with un-squadded players
>>       if p.isCommander(): return None
>>       if p.isSquadLeader(): return None
>>       if p.getSquadId() > 0: return None
>>
>
> I noticed in looking through the file that that balance policy is 
> based on player count, and that each routine separately counts players 
> by iterating over the player list. This seems like a good thing to 
> factor. Any pythonistas here who know an idiom for a routine that 
> accumulates multiple counts from some data and returns the collection? 
> In Perl I'd accumulate the team counts in a hash indexed by keys 
> 'team1' and 'team2' and return a reference to the hash. What's the 
> Python equivalent?

The same, it's called a dict. Works like:

countdict = {} # Create empty dict
countdict["team1"] = 0 # Assign start value
#Parse stuff and update dict
countdict["team1"] = countdict["team1"] + 1


> I'd rather have a policy that balances based on score instead of team 
> size. If the weighted scores differ by more than some amount or ratio, 
> the balancer kicks in. That way one can always switch to the underdog 
> team.
> _______________________________________________

Sure, use the dict construct for your score counting for each team, then 
decide who to kick.

With kind regards,

Anton Jansen


More information about the BFProg mailing list