/    Sign up×
Community /Pin to ProfileBookmark

Distribute teams in a Schedule with php

Hello
i’m going to have teams and distributes it in a schedule which every team play with the other but not to play twice in the day or with the same team twice .
In the link below you enter the number of teams and press generate then the it distribute the number of teams you had entered in a schedule and i want to do like this by using php

[url]http://www.teamopolis.com/tools/round-robin-generator.aspx[/url]

thanks alot

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ragyauthorJun 24.2010 — hello

i tried this code and it works ,but i want to show the name of each team not the numbers. this code accepts the number of teams to play and generate the schedule .


<body>

<form id="4" name="4" action="test.php" method="post">

<input type="text" id="teams" name="teams" />

<input type="submit" name="submit" value="submit" />

</form>

<?php

$teams=array ("team1","team2","team3","team4");

$n =$_POST['teams'];

if (!empty($_
GET['n']) && ctype_digit($_GET['n'])) {

$n = $_
GET['n'];

}

echo '<pre>' . generateRoundRobinPairings($n) . '</pre>';

function generateRoundRobinPairings($num_players) {

//do we have a positive number of players? otherwise default to 4

$num_players = ($num_players > 0) ? (int)$num_players : 0;

//set number of players to even number

$num_players = ($num_players &#37; 2 == 0) ? $num_players : $num_players + 1;

//format for pretty alignment of pairings across rounds

$format = "%0" . ceil(log10($num_players)) . "d";

$pairing = "$format-$format ";

//set the return value

$ret = $num_players . " Player Round Robin:n-----------------------";

//print the rounds

for ($round = 1; $round < $num_players; $round++) {

$ret .= sprintf("nDay #$format : ", $round);

$players_done = array();

//print the pairings

for ($player = 1; $player < $num_players; $player++) {

if (!in_array($player, $players_done)) {

//select opponent

//$opponents= array("team")

$opponent = $round - $player;

//echo $opponent.'<br>';
$opponent += ($opponent < 0) ? $num_players : 1;
//ensure opponent is not the current player
if ($opponent != $player) {
//choose colours
if ($player % 2 == $opponent % 2) {
if ($player < $opponent) {
//player plays black
$ret .= sprintf($pairing, $opponent, $player);
} else {
//player plays white
// $ret .= sprintf($pairing, $player, $opponent);
}
} else {
if ($player < $opponent) {
//player plays white
$ret .= sprintf($pairing, $player, $opponent);
} else {
//player plays black
$ret .= sprintf($pairing, $opponent, $player);
}
}
//these players are done for this round
$players_done[] = $player;
$players_done[] = $opponent;
}
}
}
//print the last pairing (i.e. for the last player)
if ($round % 2 == 0) {
$opponent = ($round + $num_players)/ 2;
//last player plays white
$ret .= sprintf($pairing, $num_players, $opponent);
} else {
$opponent = ($round + 1) / 2;
//last player plays black
$ret .= sprintf($pairing, $opponent, $num_players);
}
}
return $ret;

}

?>
Copy linkTweet thisAlerts:
@ragyauthorJun 24.2010 — to continue the previous post i get the names of the teams from database
×

Success!

Help @ragy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...