re-open stupid IA for debug
This commit is contained in:
parent
ae1dc89119
commit
656c8fe291
|
@ -1,5 +1,28 @@
|
||||||
<?php
|
<?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){
|
function place_ship_on_map($x1,$y1,$x2,$y2,$map){
|
||||||
if ((($x1 <> $x2) && ($y1 <> $y2))
|
if ((($x1 <> $x2) && ($y1 <> $y2))
|
||||||
OR (!isset($map[$y1][$x1]))
|
OR (!isset($map[$y1][$x1]))
|
||||||
|
@ -68,6 +91,13 @@ switch($_POST['act']){
|
||||||
if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){
|
if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){
|
||||||
echo "parametre incorrect"; die;
|
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();
|
$map=array();
|
||||||
//construire une grille
|
//construire une grille
|
||||||
for($i=0; $i < $width; $i++){
|
for($i=0; $i < $width; $i++){
|
||||||
|
@ -133,8 +163,6 @@ switch($_POST['act']){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$directions=array();
|
$directions=array();
|
||||||
if($top){
|
if($top){
|
||||||
$directions[]='top';
|
$directions[]='top';
|
||||||
|
@ -173,7 +201,7 @@ switch($_POST['act']){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_r($map);
|
//print_r($map);
|
||||||
echo json_encode($shipsCoords);
|
echo json_encode($shipsCoords);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user