Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CBaseGame :: OHFixedBalance( )
- {
- //Main beginning
- if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) )
- {
- CONSOLE_Print( "[GAME: " + m_GameName + "] error balancing slots - can't balance slots without fixed player settings" );
- return;
- }
- // Getting values
- vector<unsigned char> PlayerWins;
- for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i )
- {
- int Win = 0;
- // if( (*i)->GetGames( ) >= 10 )
- Win = (*i)->GetWinPerc( );
- CONSOLE_Print( "Name: " + (*i)->GetName() + " | Win Perc: " + UTIL_ToString( (*i)->GetWinPerc( ), 2 ) );
- PlayerWins.push_back( Win );
- }
- // find the best order
- uint32_t k = 0;
- for( vector<unsigned char> :: iterator i = PlayerWins.begin( ); i != PlayerWins.end( ); ++i )
- k =+ 1;
- if( k == 0 )
- {
- CONSOLE_Print( "Error, no players left" );
- }
- uint32_t counter;
- double BestSpread = 100;
- vector<unsigned char> BestOrder;
- for( vector<unsigned char> :: iterator a = PlayerWins.begin( ); a != PlayerWins.end( ); ++a )
- {
- for( vector<unsigned char> :: iterator b = PlayerWins.begin( ); b != PlayerWins.end( ); ++b )
- {
- if( a > b )
- {
- for( vector<unsigned char> :: iterator c = PlayerWins.begin( ); c != PlayerWins.end( ); ++c )
- {
- if( b > c )
- {
- for( vector<unsigned char> :: iterator d = PlayerWins.begin( ); d != PlayerWins.end( ); ++d )
- {
- if( c > d )
- {
- for( vector<unsigned char> :: iterator e = PlayerWins.begin( ); e != PlayerWins.end( ); ++e )
- {
- if( d > e )
- {
- double teampoints = 0;
- double result;
- double CurrentSpread;
- teampoints = *a + *b + *c + *d + *e;
- result = teampoints/5;
- if( result > 50 )
- CurrentSpread = result-50;
- else if( result < 50 )
- CurrentSpread = 50-result;
- else
- CONSOLE_Print( "Found 50 - 50 Teams, may break here" );
- if( CurrentSpread < BestSpread )
- {
- BestSpread = CurrentSpread;
- vector<unsigned char> BestOrder;
- BestOrder.push_back( *a );
- BestOrder.push_back( *b );
- BestOrder.push_back( *c );
- BestOrder.push_back( *d );
- BestOrder.push_back( *e );
- }
- counter++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- CONSOLE_Print( "Checked " + UTIL_ToString( counter ) + " possible combinations" );
- sort( BestOrder.begin( ), BestOrder.end( ) );
- //now swap
- for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i )
- {
- for( vector<unsigned char> :: iterator h = BestOrder.begin( ); h != BestOrder.end( ); ++h )
- {
- if( (*i)->GetWinPerc( ) == *h )
- {
- int oldpid = GetSIDFromPID( (*i)->GetPID( ) );
- if( (*h-1) != oldpid )
- {
- CONSOLE_Print( "Swapping [" + UTIL_ToString( oldpid ) + "] to " + UTIL_ToString( *h-1 ) );
- SwapSlots( (unsigned char)oldpid, (unsigned char)*h-1 );
- }
- }
- }
- }
- //for a better view order the other team also
- vector<unsigned char> OrderOtherTeam;
- for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i )
- {
- int oldpid = GetSIDFromPID( (*i)->GetPID( ) );
- if( oldpid > 5 )
- OrderOtherTeam.push_back( (*i)->GetWinPerc() );
- }
- sort( OrderOtherTeam.begin(), OrderOtherTeam.end() );
- bool AllOrdered = false;
- counter = 0;
- while( !AllOrdered )
- {
- for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i )
- {
- for( vector<unsigned char> :: iterator h = OrderOtherTeam.begin( ); h != OrderOtherTeam.end( ); ++h )
- {
- int oldpid = GetSIDFromPID( (*i)->GetPID( ) );
- if( (*i)->GetWinPerc( ) == *h && oldpid > 5 )
- {
- if( (*h+4) != oldpid )
- {
- CONSOLE_Print( "Swapping [" + UTIL_ToString( oldpid ) + "] to " + UTIL_ToString( *h+4 ) );
- SwapSlots( (unsigned char)oldpid, (unsigned char)*h+4 );
- }
- else
- counter++;
- if( counter == 5 )
- AllOrdered = true;
- }
- }
- }
- }
- //and finish the process with an output
- double SentPoints = 0;
- double ScouPoints = 0;
- for( vector<unsigned char> :: iterator i = BestOrder.begin( ); i != BestOrder.end( ); ++i )
- SentPoints += *i;
- for( vector<unsigned char> :: iterator i = OrderOtherTeam.begin( ); i != OrderOtherTeam.end( ); ++i )
- ScouPoints += *i;
- SendAllChat( "[Sentinel combined rating: " + UTIL_ToString( SentPoints, 2 ) + "]" );
- SendAllChat( "[Scourge combined rating: " + UTIL_ToString( ScouPoints, 2 ) + "]" );
- SendAllChat( "[Total Spread: " + UTIL_ToString( (SentPoints-ScouPoints), 2 ) + "]" );
- SendAllChat( "[Team WinChance: (Sentinel:" + UTIL_ToString( (SentPoints/(SentPoints+ScouPoints)), 2 ) + "%) (Scourge:" + UTIL_ToString( (ScouPoints/(SentPoints+ScouPoints)), 2 ) + "%)]" );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement