Fikstür Tarzında Takım Oluşturup Eşleştirmek

<?php
class fikstur{
	var $history=array();
	var $sayi=8;
	var $a=array();
	function takimOlustur(){
		for($i=1;$i<=$this->sayi;$i++){
			$this->a[]="Takim ".$i;
		}
	}
	function gecmisiTemizle($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 gecmisOlustur(){
		for($i=0;$i<$this->sayi;$i++){
			for($j=0;$j<$this->sayi;$j++){				
				if($i==$j) $this->history[$this->a[$i]][]=0;
				else $this->history[$this->a[$i]][]=$this->a[$j];
			}
		}
	}
	function takimYazdir(){
		print_r($this->teams);
	}
	function gemisKontrol($temphistory,$team){
		if(sizeof($temphistory)>0){
			foreach($temphistory as $val){
				if($val==$team){
					return false;
				}
			}
		}
		return true;
	}
	function tasi(){
		$temphistory=array();
		for($i=0;$i<$this->sayi;$i++){	
			if(sizeof($this->history)>0){		
				foreach($this->history[$this->a[$i]] as $key => $val){
					if($val&&$this->gemisKontrol($temphistory,$val)&&$this->gemisKontrol($temphistory,$this->a[$i])){	
						$temphistory[]=$this->a[$i];
						$temphistory[]=$val;
						break;
					}
				}
			}
		}
		$this->a=$temphistory;
	}
	function calistir(){
		for($j=1;$j<$this->sayi;$j++){
			for($i=0;$i<$this->sayi;$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->gecmisiTemizle($this->a[$i],$this->a[$i+1]);
				$this->gecmisiTemizle($this->a[$i+1],$this->a[$i]);
			}
			echo "<hr>";
			$this->tasi();
		}
	}
}
$s=new fikstur();
$s->sayi=8;
$s->takimOlustur();
$s->gecmisOlustur();
$s->calistir();
?>

Çıktısı

Takim 2-Takim 1
Takim 3-Takim 4
Takim 6-Takim 5
Takim 8-Takim 7
Takim 1-Takim 3
Takim 4-Takim 2
Takim 5-Takim 7
Takim 8-Takim 6
Takim 4-Takim 1
Takim 3-Takim 2
Takim 8-Takim 5
Takim 6-Takim 7
Takim 5-Takim 1
Takim 4-Takim 6
Takim 3-Takim 7
Takim 2-Takim 8
Takim 6-Takim 1
Takim 2-Takim 5
Takim 7-Takim 4
Takim 8-Takim 3
Takim 1-Takim 7
Takim 6-Takim 2
Takim 3-Takim 5
Takim 4-Takim 8
Takim 1-Takim 8
Takim 7-Takim 2
Takim 3-Takim 6
Takim 5-Takim 4