This commit is contained in:
Gnieark 2016-06-27 09:36:35 +02:00
parent 3b66174768
commit 83d4c1f5a0

View File

@ -205,72 +205,72 @@ function analize($line,$me,$opponent,$isVertical,$decalageX){
function should_opponent_win_if_i_play_at($map,$me,$opponent,$colToPlay){ function should_opponent_win_if_i_play_at($map,$me,$opponent,$colToPlay){
//j'ouvre l'a possibilité à l'adversaire de jouer au dessus de mon pion //j'ouvre l'a possibilité à l'adversaire de jouer au dessus de mon pion
// est-ce une connerie? // est-ce une connerie?
if(($map[4][$colToPlay] == $me) OR ($map[4][$colToPlay] == $opponent)){ if(($map[4][$colToPlay] == $me) OR ($map[4][$colToPlay] == $opponent)){
//top of the grid //top of the grid
return false; return false;
} }
for($y = 0; (($map[$y][$colToPlay] <> "+") && ($map[$y][$colToPlay] <> "-")); $y++){ for($y = 0; (($map[$y][$colToPlay] <> "+") && ($map[$y][$colToPlay] <> "-")); $y++){
} }
$map[$y][$colToPlay] = $me; $map[$y][$colToPlay] = $me;
$map[$y +1][$colToPlay] = "$opponent"; $map[$y +1][$colToPlay] = "$opponent";
$y++; $y++;
if(isset($map[$y +1][$colToPlay])){ if(isset($map[$y +1][$colToPlay])){
$map[$y +1][$colToPlay] = "+"; $map[$y +1][$colToPlay] = "+";
} }
//tester les lignes qui passent pas $y+1,$colToPlay //tester les lignes qui passent pas $y+1,$colToPlay
$loseStr = $opponent.$opponent.$opponent.$opponent; $loseStr = $opponent.$opponent.$opponent.$opponent;
//horizontale //horizontale
$line=""; $line="";
for($x=0; $x < 7; $x++){ for($x=0; $x < 7; $x++){
$line.=$map[$y][$x]; $line.=$map[$y][$x];
} }
if(strpos($line,$loseStr) !== false){ if(strpos($line,$loseStr) !== false){
return true; return true;
} }
//diagonal / //diagonal /
$line=""; $line="";
if($colToPlay > $y){ if($colToPlay > $y){
$kx=$colToPlay - $y; $kx=$colToPlay - $y;
$ky = 0; $ky = 0;
}else{ }else{
$kx = 0; $kx = 0;
$ky = $y - $colToPlay; $ky = $y - $colToPlay;
} }
while(isset($map[$ky][$kx])){ while(isset($map[$ky][$kx])){
$line.=$map[$ky][$kx]; $line.=$map[$ky][$kx];
$kx++; $kx++;
$ky++; $ky++;
} }
if(strpos($line,$loseStr) !== false){ if(strpos($line,$loseStr) !== false){
return true; return true;
} }
//diagional \ //diagional \
$line = ""; $line = "";
$kx = $colToPlay; $kx = $colToPlay;
$ky = $y; $ky = $y;
while(isset($map[$ky -1][$kx +1])){ while(isset($map[$ky -1][$kx +1])){
$kx++; $kx++;
$ky--; $ky--;
} }
while(isset($map[$ky][$kx])){ while(isset($map[$ky][$kx])){
$line.=$map[$ky][$kx]; $line.=$map[$ky][$kx];
$kx--; $kx--;
$ky++; $ky++;
} }
if(strpos($line,$loseStr) !== false){ if(strpos($line,$loseStr) !== false){
return true; return true;
} }
return false; return false;
} }
@ -399,7 +399,10 @@ switch($params['action']){
} }
} }
} }
if(count(array_unique($choice['colForNoLose'])) > 1){
//opponent has to places to win
remenber_previous_lap_is_a_bullshit();
}
if(count($choice['colForNoLose']) > 0){ if(count($choice['colForNoLose']) > 0){
//intersection entre $choice['colForNoLose'] et $colAvailable //intersection entre $choice['colForNoLose'] et $colAvailable
$intersection = array_intersect($choice['colForNoLose'],$colAvailable); $intersection = array_intersect($choice['colForNoLose'],$colAvailable);