<?
function weiss_ki($weisefelder)
{
srand(time());
$erg = rand(1, 3);
if($erg == 1)
{
return weiss_ki_vvw($weisefelder);
}
elseif($erg == 2)
{
return weiss_ki_vhw($weisefelder);
}
elseif($erg == 3)
{
return weiss_ki_rand($weisefelder);
}
return false;
}
function weiss_ki_vvw($weisefelder)
{
$feld = 1;
while($feld <= 6)
{
$wert = $weisefelder[$feld];
if($wert >= 1)
{
$key = $feld;
$wert = $wert;
$_SESSION['weiss'][$key] = 0;
$key--;
$erg = weitergabe('weiss', $wert, $key, 'weiss');
if($erg == "passend")
{
$weisefelder = $_SESSION['weiss'];
unset($weisefelder['sammel']);
weiss_ki($weisefelder);
}
elseif($erg['farbe'] == 'weiss')
{
$key = $erg['feld'];
$key++;
if($_SESSION['weiss'][$key] == 1)
{
if($key == 6)
{
$schwarz_key = 1;
}
elseif($key == 5)
{
$schwarz_key = 2;
}
elseif($key == 4)
{
$schwarz_key = 3;
}
elseif($key == 3)
{
$schwarz_key = 4;
}
elseif($key == 2)
{
$schwarz_key = 5;
}
elseif($key == 1)
{
$schwarz_key = 6;
}
$anzahl = $_SESSION['weiss'][$key] + $_SESSION['schwarz'][$schwarz_key];
$_SESSION['weiss'][$key] = 0;
$_SESSION['schwarz'][$schwarz_key] = 0;
$_SESSION['weiss']['sammel'] = $_SESSION['weiss']['sammel'] + $anzahl;
}
}
break;
}// if($wert >= 1)
$feld++;
}//while($feld <= 6)
return true;
}
function weiss_ki_vhw($weisefelder)
{
$feld = 6;
while($feld >= 1)
{
$wert = $weisefelder[$feld];
if($wert >= 1)
{
$key = $feld;
$wert = $wert;
$_SESSION['weiss'][$key] = 0;
$key--;
$erg = weitergabe('weiss', $wert, $key, 'weiss');
if($erg == "passend")
{
$weisefelder = $_SESSION['weiss'];
unset($weisefelder['sammel']);
weiss_ki($weisefelder);
}
elseif($erg['farbe'] == 'weiss')
{
$key = $erg['feld'];
$key++;
if($_SESSION['weiss'][$key] == 1)
{
if($key == 6)
{
$schwarz_key = 1;
}
elseif($key == 5)
{
$schwarz_key = 2;
}
elseif($key == 4)
{
$schwarz_key = 3;
}
elseif($key == 3)
{
$schwarz_key = 4;
}
elseif($key == 2)
{
$schwarz_key = 5;
}
elseif($key == 1)
{
$schwarz_key = 6;
}
$anzahl = $_SESSION['weiss'][$key] + $_SESSION['schwarz'][$schwarz_key];
$_SESSION['weiss'][$key] = 0;
$_SESSION['schwarz'][$schwarz_key] = 0;
$_SESSION['weiss']['sammel'] = $_SESSION['weiss']['sammel'] + $anzahl;
}
}
break;
}// if($wert >= 1)
$feld--;
}//while($feld <= 6)
return true;
}
function weiss_ki_rand($weisefelder)
{
srand(time());
$feld = rand(1, 6);
$wert = $weisefelder[$feld];
if($wert >= 1)
{
$key = $feld;
$wert = $wert;
$_SESSION['weiss'][$key] = 0;
$key--;
$erg = weitergabe('weiss', $wert, $key, 'weiss');
if($erg == "passend")
{
$weisefelder = $_SESSION['weiss'];
unset($weisefelder['sammel']);
weiss_ki($weisefelder);
}
elseif($erg['farbe'] == 'weiss')
{
$key = $erg['feld'];
$key++;
if($_SESSION['weiss'][$key] == 1)
{
if($key == 6)
{
$schwarz_key = 1;
}
elseif($key == 5)
{
$schwarz_key = 2;
}
elseif($key == 4)
{
$schwarz_key = 3;
}
elseif($key == 3)
{
$schwarz_key = 4;
}
elseif($key == 2)
{
$schwarz_key = 5;
}
elseif($key == 1)
{
$schwarz_key = 6;
}
$anzahl = $_SESSION['weiss'][$key] + $_SESSION['schwarz'][$schwarz_key];
$_SESSION['weiss'][$key] = 0;
$_SESSION['schwarz'][$schwarz_key] = 0;
$_SESSION['weiss']['sammel'] = $_SESSION['weiss']['sammel'] + $anzahl;
}
}
return true;
}// if($wert >= 1)
else
{
if(!spiel_vorbei())
{
weiss_ki_rand($weisefelder);
}
else
{
break;
}
}
return true;
}
?>