re-open stupid IA for debug
This commit is contained in:
parent
ae1dc89119
commit
656c8fe291
|
@ -1,5 +1,28 @@
|
|||
<?php
|
||||
/*
|
||||
function is_it_possible_to_place_ships_on_grid($gridWidth,$gridHeight,$nbShipsSize1,$nbShipsSize2,$nbShipsSize3,$nbShipsSize4,$nbShipsSize5,$nbShipsSize6){
|
||||
//return false or true
|
||||
//not a perfect solution
|
||||
$shipsArea=$nbShipsSize1 + 2 * $nbShipsSize2 + 3 * $nbShipsSize3 + 4 * $nbShipsSize4 + 5 * $nbShipsSize5 + 6 * $nbShipsSize6;
|
||||
if( $shipsArea < $gridHeight * $gridwidth / 2){
|
||||
return false;
|
||||
}
|
||||
//longest ship
|
||||
for($i=6; $i > 0; $i--){
|
||||
$var='nbShipsSize'.$i;
|
||||
if($$var > 0){
|
||||
$longestShip=$$var;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( (!isset($longestShip))
|
||||
OR(($longestShip > $gridWidth) && ($longestShip > $gridHeight))
|
||||
){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function place_ship_on_map($x1,$y1,$x2,$y2,$map){
|
||||
if ((($x1 <> $x2) && ($y1 <> $y2))
|
||||
OR (!isset($map[$y1][$x1]))
|
||||
|
@ -68,13 +91,20 @@ switch($_POST['act']){
|
|||
if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){
|
||||
echo "parametre incorrect"; die;
|
||||
}
|
||||
|
||||
if(!is_it_possible_to_place_ships_on_grid($width,$height,$ship1,$ship2,$ship3,$ship4,$ship5,$ship6)){
|
||||
echo "I don't want play this game";
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
$map=array();
|
||||
//construire une grille
|
||||
for($i=0; $i < $width; $i++){
|
||||
for($j=0; $j < $height; $j++){
|
||||
$map[$j][$i]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shipsCoords=array();
|
||||
|
||||
|
@ -132,9 +162,7 @@ switch($_POST['act']){
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$directions=array();
|
||||
if($top){
|
||||
$directions[]='top';
|
||||
|
@ -173,7 +201,7 @@ switch($_POST['act']){
|
|||
|
||||
}
|
||||
}
|
||||
print_r($map);
|
||||
//print_r($map);
|
||||
echo json_encode($shipsCoords);
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue
Block a user