This commit is contained in:
Gnieark 2016-06-13 22:22:24 +02:00
parent 833247af23
commit e32ad48429

View File

@ -28,7 +28,7 @@ function score($board,$me,$opponent,$colToPlay,$depth){
$line.=$newBoard[$y][$i]; $line.=$newBoard[$y][$i];
} }
if(strpos($searchValue,$line) !== false ){ if(strpos($searchValue,$line) !== false ){
return 42 - $depth; return 42;
} }
//verticaly //verticaly
@ -38,7 +38,7 @@ function score($board,$me,$opponent,$colToPlay,$depth){
} }
//echo $line."p".$searchValue." ".strpos($searchValue,$line)."|\n"; //echo $line."p".$searchValue." ".strpos($searchValue,$line)."|\n";
if(strpos($searchValue,$line) !== false){ if(strpos($searchValue,$line) !== false){
return 42 - $depth; return 42;
} }
@ -57,7 +57,7 @@ function score($board,$me,$opponent,$colToPlay,$depth){
$line.=$newBoard[$jy][$jx]; $line.=$newBoard[$jy][$jx];
} }
if(strpos($searchValue,$line) !== false ){ if(strpos($searchValue,$line) !== false ){
return 42 - $depth; return 42;
} }
//diagonal / //diagonal /
$b = $y - $colToPlay; $b = $y - $colToPlay;
@ -74,7 +74,7 @@ function score($board,$me,$opponent,$colToPlay,$depth){
$line.=$newBoard[$jy][$jx]; $line.=$newBoard[$jy][$jx];
} }
if(strpos($searchValue,$line) !== false){ if(strpos($searchValue,$line) !== false){
return 42 - $depth; return 42;
} }
//if grid is full //if grid is full
@ -91,12 +91,16 @@ function score($board,$me,$opponent,$colToPlay,$depth){
if($depth < 7){ if($depth < 7){
//CO //CO
return - better_col($newBoard,$opponent,$me,$depth + 1) + $depth; if(($depth % 2) == 0){
return better_col($newBoard,$opponent,$me,$depth + 1) - $depth;
}else{
return $depth - better_col($newBoard,$opponent,$me,$depth + 1);
}
}else{ }else{
return 0; return 0;
} }
} }
/*
function worst_col($board,$me,$opponent,$depth){ function worst_col($board,$me,$opponent,$depth){
$worstScore= 1000; $worstScore= 1000;
$worstCol= -1; $worstCol= -1;
@ -110,10 +114,10 @@ function worst_col($board,$me,$opponent,$depth){
} }
} }
} }
return $betterCo return $worstScore;
} }
*/
function better_col($board,$me,$opponent,$depth){ function better_col($board,$me,$opponent,$depth){
$betterScore= -1000; $betterScore= -1000;
@ -154,7 +158,7 @@ switch($params['action']){
$opponent="X"; $opponent="X";
} }
echo '{"play":"'.better_col($params['board'],$params['you'],$opponent,1).'"}'; echo '{"play":"'.better_col($params['board'],$params['you'],$opponent,0).'"}';
break; break;
default: default:
break; break;