place ships function

This commit is contained in:
gnieark 2015-12-16 18:31:13 +01:00
parent 5666d4d10c
commit f16807d8a8

View File

@ -1,10 +1,26 @@
<?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:
}
}
function get_Post_Params($botsCount){
function get_Post_Params($ccbotsCount){
$keysBots=array('bot1','bot2');
foreach($keysBots as $botKey){
if(!isset($_POST[$botKey])){