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.
Page 3 of 3 FirstFirst 123
Results 31 to 35 of 35
  1. #31
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Ok, guess I'll pass on this one, I thought I explained it in simple terms, but it sounds like
    I don't understand what exactly is required. my take was you simply take 40 games
    and evenly spread out the match ups between 8 teams?. that's it.

    When you think about it
    a bye is nothing more then just like facing another team only you don't play that. I found
    some open source league scripts I will install and play with,

    I still say the basic schedule function theory should work with number of teams, and
    number of games. the hard part is spreading the match ups evenly among all of them.
    that's why I sought help here.

    I found this script below, problem is it errors when it gets to the part teams play more
    then once and also there is no way to enter total games played. but this is something like
    how to do it.
    PHP Code:

    class schedule{
        var 
    $history=array();
        var 
    $num=10;
        var 
    $a=array();
        function 
    make_teams(){
            for(
    $i=1;$i<=$this->num;$i++){
                
    $this->a[]="team ".$i;
            }
        }
        
        function 
    remove_history($team1,$team2){
            if(
    sizeof($this->history)>0){
                foreach(
    $this->history[$team1] as $key => $val){                            
                    if(
    $val==$team2&&$val){
                        
    $this->history[$team1][$key]=0;
                        break;
                    }
                }
            }
        }
        
        function 
    make_history(){
            for(
    $i=0;$i<$this->num;$i++){
                for(
    $j=0;$j<$this->num;$j++){                
                    if(
    $i==$j$this->history[$this->a[$i]][]=0;
                    else 
    $this->history[$this->a[$i]][]=$this->a[$j];
                }
            }
        }
        
        function 
    print_teams(){
            
    print_r($this->teams);
        }
        function 
    check_temp_history($temphistory,$team){
            if(
    sizeof($temphistory)>0){
                foreach(
    $temphistory as $val){
                    if(
    $val==$team){
                        return 
    false;
                    }
                }
            }
            return 
    true;
        }
        function 
    move(){
            
    $temphistory=array();
            for(
    $i=0;$i<$this->num;$i++){    
                if(
    sizeof($this->history)>0){        
                    foreach(
    $this->history[$this->a[$i]] as $key => $val){
                        if(
    $val&&$this->check_temp_history($temphistory,$val)&&$this->check_temp_history($temphistory,$this->a[$i])){    
                            
    $temphistory[]=$this->a[$i];
                            
    $temphistory[]=$val;
                            break;
                        }
                    }
                }
            }
            
    $this->a=$temphistory;
        }
        
        function 
    run(){
            for(
    $j=1;$j<$this->num;$j++){
                for(
    $i=0;$i<$this->num;$i+=2){
                    
    srand();
                    
    $r=rand(0,1);
                    if(
    $r==1){
                        echo 
    $this->a[$i]."-".$this->a[$i+1];
                    }
                    else{
                        echo 
    $this->a[$i+1]."-".$this->a[$i];
                    }
                    echo 
    "<br />";
                    
    $this->remove_history($this->a[$i],$this->a[$i+1]);
                    
    $this->remove_history($this->a[$i+1],$this->a[$i]);
                }
                echo 
    "<hr>";
                
    $this->move();
            }
        }
    }

    // Do It, make the schedule
    $s=new schedule();
    //number of teams
    $s->num=16;
    //makes the teams
    $s->make_teams();
    //makes the history-all the possibilities of the teams(team1 can play against all and so on)
    $s->make_history();

    //print schedule
    echo '<div align=center><table width=200><tr><td>';
    $s->run();
    echo 
    '</td></tr></table></div>'

  2. #32
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Right, which is what the combinations will do for you.
    If you run that with 8 teams (which is successful), it will specify 4x teams over 7 weeks, and won't accommodate anything over 7 weeks. Which is expected. If you used 12 (and the script wasn't fubard), it would specify 6 games for 11 weeks.
    So scheduling a combination without repeating a team per week is mostly trivial to do. Specifying missing days or overages require a custom ruleset to deal with them. If I specified 3 teams total, then there would be 3 games in total to deal with every combination. That would be 1 game per week for 3 weeks. So what would happen with the other 7 weeks?

  3. #33
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Right, which is what the combinations will do for you.
    If you run that with 8 teams (which is successful), it will specify 4x teams over 7 weeks, and won't accommodate anything over 7 weeks. Which is expected. If you used 12 (and the script wasn't fubard), it would specify 6 games for 11 weeks.
    So scheduling a combination without repeating a team per week is mostly trivial to do. Specifying missing days or overages require a custom ruleset to deal with them. If I specified 3 teams total, then there would be 3 games in total to deal with every combination. That would be 1 game per week for 3 weeks. So what would happen with the other 7 weeks?

    Fou Check this out

    Just in case anybody out there is also looking to do something like this, its not done its
    probably not even the best way to it, but it works, as I said earlier its not that complex as
    it appears, note the teams and start times, it will take whatever number of teams and
    start times and do a schedule for you just pass it the number of weeks and it does the
    rest.

    I'd appropriate, any advice on improving or styling this better

    PHP Code:
    // If you wind up with odd number teams, simply add bye as shown.

        
    $teams = array('Team 1','Team 2','Team 3','Team 4','Team 5','team6','team7','bye');

        
    $season 'Spring 13';
        
    $league 'Boys';
        
    $date '2013-02-03';// Schedule start date
        
    $times =  array('9am','11am','1pm','3pm');

        
    $date_bits explode('-',$date);
        
    $start_day mktime(000$date_bits[1], $date_bits[2], $date_bits[0]);          

        
    $weeks 10;

        
    $count count($teams);
        
    $times array_slice($times,0,floor($count/2));
        
    $times_count count($times);
        
    $start 1;

        if(
    $count%2!=0)
        {
            
    $teams[] = 'Bye';
            
    $count++;
        }

        
    $date_i 0;
        for(
    $i=0;$i<$weeks;$i++)
        {
            
    $keyA $start;
            
    $keyB $keyA-1; if($keyB<1)$keyB $count-1;
            
    $tA = array();
            
    $tB = array();
            for(
    $k=0;$k<$count-1;$k++)
            {
                
    $tA[] = $teams[$keyA];
                
    $tB[] = $teams[$keyB];
                
    $keyA++; if($keyA>$count-1$keyA 1;
                
    $keyB--; if($keyB<1$keyB $count-1;
            }
            
    array_unshift($tA,$teams[0]);
            
    $tB[] = $teams[0];          

            
    $inc 0// time increment
            
    for($k=0;$k<$count;$k++)
            {
                if(
    $tA[$k]=='Bye'||$tB[$k]=='Bye') continue;

                
    $col = array();
                
    $col['season'] = $season//season
                
    $col['league'] = $league//league
                
    $col['Week'] = 'Week '.($i+1); //Week
                
    $col['date'] = date('Y-m-d',strtotime("+{$i} week",$start_day)); //date
                
    $col['time'] = $times[$inc]; //time
                
    $col['teamA'] = $tA[$k]; //result_teamA
                
    $col['_result'] = 'vs';
                
    //$col['teamA_result'] = '0'; //result_teamA
                
    $col['teamB'] = $tB[$k]; //result_teamB
                // $col['teamB_result'] = 0;
                
    $data['results'][] = $col;

                
    $inc++;
                if(
    $inc==$times_count) break;
            }

            
    $start--; if($start<1$start $count-1;

            
    // shift allocated times
            
    $first $times[0];
            
    $times array_slice($times,1,count($times));
            
    array_push($times,$first);

        }
        echo 
    '<div align=center><table width=700 border="1">';
        foreach(
    $data['results'] as $result)
        {
            echo 
    '<tr><td align=center nowrap>'.implode('</td><td align=center nowrap>',array_values($result)).'</td></tr>';
        }
        echo 
    '</table>'
    Last edited by sonny; 11-16-2012 at 01:03 AM.

  4. #34
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Is that what you want to do with it:
    Code:
    Spring 13	Boys	Week 2	2013-02-10	11am	Team 1	vs	team7
    Spring 13	Boys	Week 9	2013-03-31	9am	Team 1	vs	team7
    You have a few like that; ultimately this is exactly what my question has been. How do you control whom replays whom when you cannot allot everyone playing every team twice.

    It doesn't work properly though. It looks to me that you'll end up with. . . 44 records in there, so that'll be 11 weeks worth, not 10. Since 44 doesn't work with a full combination calculation on sets of 2x, without being able to parse this code entirely (writecodeonline is unhappy about the buffer sizes its using), I can't tell whether it's short or just over.

  5. #35
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Is that what you want to do with it:
    Code:
    Spring 13	Boys	Week 2	2013-02-10	11am	Team 1	vs	team7
    Spring 13	Boys	Week 9	2013-03-31	9am	Team 1	vs	team7
    You have a few like that; ultimately this is exactly what my question has been. How do you control whom replays whom when you cannot allot everyone playing every team twice.

    It doesn't work properly though. It looks to me that you'll end up with. . . 44 records in there, so that'll be 11 weeks worth, not 10. Since 44 doesn't work with a full combination calculation on sets of 2x, without being able to parse this code entirely (writecodeonline is unhappy about the buffer sizes its using), I can't tell whether it's short or just over.
    I have always been saying this I'm just looking to create match ups for whatever amount
    of teams and start times for 10 weeks. Its as close as you can get, everyone has a match
    up for 10 weeks and the times and byes are spread out best as possible. this does exactly
    that, problem I am having now is styling the results within the implode, I don't want week
    1 on every entry just that group for that week only once, I think the way I did this does
    not allow easy format styling.

    Sonny
    Last edited by sonny; 11-16-2012 at 04:30 PM.


 
Page 3 of 3 FirstFirst 123

Posting Permissions

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