Location: PHPKode > scripts > Team schedule maker > team-schedule-maker/schedule.php
class schedule{
	var $history=array();
	var $num=8;
	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();
		}
	}
}
Return current item: Team schedule maker