View Single Post
Old 11-15-2012, 04:33 PM   PM User | #31
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
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>'
sonny is offline   Reply With Quote