Raised This Month: $ Target: $400
 0% 

Dividing players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 04-28-2011 , 15:38   Dividing players
Reply With Quote #1

Hey, would someone help me, to do a plugin that divides users by their numbers for example, Like I've 10 players,

PHP Code:
PLAYER_NAME                  NUMBER
reinert1                         150
reinert2                         600
reinert3                         50
reinert4                         200
reinert5                         300
reinert6                         450
reinert7                         500
reinert8                         300
reinert9                         100
reinert10                       200 
I Would like to make that they will be divided to 2 parts ( 5 / 5 ), and the first part total number would be equal or similar to the second parts number.

Total NUMBER is 2850, so I'll divide them by 2, and then Part1 should be around 1425 and part2 aswell..

So part1 will be: reinert1 + reinert2 + reinert4 + reinert8 + reinert10 (total number 1450)
and part2 will be: reinert3 + reinert5 + reinert6 + reinert7 + reinert9 (1400)

Help help help !

Last edited by reinert; 04-28-2011 at 15:41.
reinert is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 04-28-2011 , 15:46   Re: Dividing players
Reply With Quote #2

For best result you should sort player by points, descending.
Some like Players[33], where player[1] will be userid of player who has most points.
And then use something like this:
PHP Code:
public separate_players()
{
    static 
players1[32], players2[32], playercount1playercount2pointcount1pointcount2
    
    playercount1
=0
    playercount2
=0
    pointcount1
=0
    pointcount2
=0

    
for (i=1;i<=g_maxplayers;i++)
    {
        if (!
is_user_connected(Players[i]))
            continue
        
        if (
pointcount1==pointcount2||pointcount2>pointcount1)
        {
            
players1[playercount1]=Players[i]
            
playercount1++
            
pointcount1+=points[Players[i]]
        }
        
        
        if (
pointcount1>pointcount2)
        {
            
players2[playercount2]=Players[i]
            
playercount2++
            
pointcount2+=points[Players[i]]
        }
    }

__________________


Last edited by SonicSonedit; 04-29-2011 at 09:17.
SonicSonedit is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-28-2011 , 15:51   Re: Dividing players
Reply With Quote #3

Could someone explain me it more detailed ? please. I still don't get it ;(
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-28-2011 , 16:17   Re: Dividing players
Reply With Quote #4

1. Add all values
2. Divide by number of values
Done

May be this example would help you to understand :

PHP Code:
SharePlayersMoney()
{
    new 
iTotalMoney
    
new iPlayers[32], iNumid
    get_players
(iPlayersiNum"h")
    for(new 
ii<iNumi++)
    {
        
iTotalMoney += cs_get_user_moneyiPlayers[i] )
    }
    new 
iSharedMoney iTotalMoney iNum
    
for(new ii<iNumi++)
    {
        
cs_set_user_moneyiPlayers[i] , iSharedMoney )
    }

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-28-2011 at 16:20.
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-28-2011 , 16:34   Re: Dividing players
Reply With Quote #5

Well it's not what I need ;( Lets say I've 10 players they have the different amount of points, I would like to divide them to 2 teams (CT and T), and the CT and T team would be with equal or similar amount of points. I don't want to change their points.

I thought of sorting them in descending order, and then select every other (1, 3, 5, 7, 9 || 2, 4, 6, 8, 10). But it's not the best way of sorting players to 2 groups. Because I will get a teams like: (600+450+300+200+100 = 1650) and the other team (500+300+200+150+50 = 1200) well it's not the rightest way

Last edited by reinert; 04-28-2011 at 16:40.
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-28-2011 , 16:38   Re: Dividing players
Reply With Quote #6

So you you to balance teams levels ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-28-2011 , 16:40   Re: Dividing players
Reply With Quote #7

Yes.
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-28-2011 , 18:12   Re: Dividing players
Reply With Quote #8

There was similiar request: http://forums.alliedmods.net/showthr...41#post1250441

The idea goes like this:
1. Sort all numbers in descending order.
2. Loop through all numbers. In each iteration you add player to group that has lower total amount of points and is not full.
__________________
Impossible is Nothing
Sylwester is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 04-29-2011 , 07:05   Re: Dividing players
Reply With Quote #9

Quote:
The idea goes like this:
1. Sort all numbers in descending order.
2. Loop through all numbers. In each iteration you add player to group that has lower total amount of points and is not full.
Quote:
Originally Posted by SonicSonedit View Post
For best result you should sort player by points, descending.
Some like Players[32], where player[0] will be userid of player who has most points.
And then use something like this:
PHP Code:
public separate_players()
{
    static 
players1[32], players2[32], playercount1playercount2pointcount1pointcount2
    
    playercount1
=0
    playercount2
=0
    pointcount1
=0
    pointcount2
=0

    
for (i=0;i<32;i++)
    {
        if (!
is_user_connected(Players[i]))
            continue
        
        if (
pointcount1==pointcount2||pointcount2>pointcount1)
        {
            
players1[playercount1]=Players[i]
            
playercount1++
            
pointcount1+=points[Players[i]]
        }
        
        
        if (
pointcount1>pointcount2)
        {
            
players2[playercount2]=Players[i]
            
playercount2++
            
pointcount2+=points[Players[i]]
        }
    }

__________________


Last edited by SonicSonedit; 04-29-2011 at 09:17.
SonicSonedit is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-29-2011 , 09:04   Re: Dividing players
Reply With Quote #10

Oh, it looks like I didn't read your post before posting and also your code will fail if in any iteration pointcount 1 and 2 become equal.
__________________
Impossible is Nothing
Sylwester is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode