Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

    http://www.teamopolis.com/tools/roun...generator.aspx

    thanks alot

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Never bothered to follow that link, but given that it links exactly to that text, I'd assume that it wouldn't work anyway.
    In any case though, what's your actual question?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 .

    PHP Code:
    <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 == 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 == $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 == 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;
    }
    ?>
    Last edited by Fou-Lu; 06-24-2010 at 04:53 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is your $teams array the names you are referring to?
    You'll need to clarify on input and output results.
    I type 1, what is my expected response? What about 4? What about 5 (out of bounds potentially)? What about 0?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •