Gossamer Forum
Home : General : Perl Programming :

random teams

Quote Reply
random teams
Trying to set up a script that creates random teams of a certain number of players.

I have the players in an array. Lets say there are 6 players.
Now, I want to be able to spread these into different teams, which I set in a box(the number of teams).


Code:
<select size="1" name="teams">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select></center>

I display this from on a page, and press a button to go to the script file.
Where I have something like this. I pick out the players from a file and check who of them are playing that type of game.
Then I try to give them a random team. The problem is that all of the players end up on the same team. No matter how many teams I want to set up. The team they are set to is different from each time, but all end up on same team.

And I don't know if there is any way of getting the teams to be fair? It will always be the right number of players (2-4-6-8 and so on), but how can I place like 2 players on that team, and two on another?

This is the code I have:

Code:
open (FILE, "$file") or feilmelding("couldnt open $file: $! \n");
my@players = <FILE>;
close (FILE);
my $number = 0;
foreach $player (@players){
($number1,$name,$games,$date) = split(/\|/, $player);
if ($games =~ /warcraft3/i) {
$number++;

if ($FORM{'teams'} != "") {
srand (time|$$);
$numberofteams = $FORM{'teams'} + 1;
$yourteam = int(rand($numberofteams));
print "<tr><td><input type=\"text\" readonly=\"readonly\" size=\"25\" value=\"$name\" name=\"$name\"/> <input type=\"text\" readonly=\"readonly\" size=\"2\" name=\"$number\" value=\"$yourteam\" />$number</td></tr>";
}
I miss a lot of code yet. Anyone who can help?

Thanks.

- kbergem
Subject Author Views Date
Thread random teams perlman 3729 May 24, 2004, 2:20 AM
Post Re: [perlman] random teams
perlman 3614 May 25, 2004, 12:41 AM