Best way to check when to autobalance teams based off differing max#players for certain teams based on gamemode

Looking for some assistance with this, I plan to code up autobalance detection but am having slight difficulty on detecting (utilized some conditional statements but they ended up not covering all use cases)

Sample cases:
1 gamemode has: Team1 MAX of 10 players, Team 2 MAX of 14 players

1 gamemode has Team1 MAX of 12 players, Team 2 MAX of 12 players

how would I best determine to autobalance? typically I don’t want to autobalance when 1 player leaves from a team, but 2 leaving/missing should trigger it.

Using the first sample case: Team 1 has 8 players, Team2 still has 14 players, this should trigger autobalance towards team 1

another: Team 1 has 8 players, Team2 has 13 players, well it shouldnt autobalance

another: Team 1 has 8 players, Team2 has 12 players, well it shouldnt autobalance, at least i dont think so, they both lack 2 people, but team 2 has 4 more players in general as their max cap

Lets say TeamA can have maximum 14 players, and TeamB can have maximum 10 players.
Then when you check for teambalance, you just do #TeamA - 4, and after that, checks the balance. (since they maximum can have 4 more than TeamB. TeamB in this case acts as the baseNumber.

Edit: You’ve updated the post a bit. Each time you add a criteria, you just check if that criteria is met.

I think the problem is more complicated than that

if #TeamB<#TeamAthen

check how bad the discrepancy is

if #TeamB<#TeamA-4
 check if #TeamB+1<#TeamA-4 then autobalance


use cases

#TeamA==14

#TeamB==0->8 will trigger autobalance

-----

#TeamA==13

#TeamB==0->7 will trigger autobalance

--

#TeamA==12

#TeamB==0->6 will trigger autobalance
.....

when A==5 things start not working.

#TeamA==5

#TeamB==0 will not trigger autobalance

seems more complicated...

The more criterias you want to check for, the more complicated it gets. I would advice you to start with the basic, and add onto it, instead of trying to solve all of it at once.