diff --git a/html/style.css b/html/style.css index bca793a..7d0ef87 100644 --- a/html/style.css +++ b/html/style.css @@ -108,6 +108,7 @@ pre{ font-family: Consolas, "Times New Roman", Verdana; border-left: 4px solid #CCC; padding-left: 8px; + white-space: normal; } .podium{list-style-type:none;padding: 5px 20px 5px 0;} .podium li{padding: 5px 20px 5px 0;} diff --git a/lang/en.php b/lang/en.php index fdd58e7..03920af 100644 --- a/lang/en.php +++ b/lang/en.php @@ -1,5 +1,14 @@ 'en', diff --git a/lang/fr.php b/lang/fr.php index 653dba8..6c4a2e6 100644 --- a/lang/fr.php +++ b/lang/fr.php @@ -1,5 +1,14 @@ 'fr', diff --git a/src/aboutBot.php b/src/aboutBot.php index f0185f3..395cac1 100644 --- a/src/aboutBot.php +++ b/src/aboutBot.php @@ -1,5 +1,16 @@
A props de '.htmlentities($_GET['params']).'

Inscrit le '.$theBot['date_inscription'].'

'.$theBot['description'].'

Si vous êtes le propriétaire de ce bot, vous pouvez le modifier

'; ?> diff --git a/src/act.php b/src/act.php index 09e6264..f9df799 100644 --- a/src/act.php +++ b/src/act.php @@ -1,4 +1,14 @@ 2"); diff --git a/src/addBot.php b/src/addBot.php index 660ec5b..c74e65f 100644 --- a/src/addBot.php +++ b/src/addBot.php @@ -1,6 +1,17 @@
if((isset($_POST['xd_check'])) && ($_POST['act'] == "addBot")){ diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 1bb6aa7..24a3316 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -20,305 +20,357 @@ switch ($_POST['act']){ session_unset(); $_SESSION['xd_check']=$xd; - //verifier parametres POST - $postParamsWanted=array( - // key,min,max - array('gridWidth',1,100), - array('gridHeight',1,100), - array('nbShip1',0,10), - array('nbShip2',0,10), - array('nbShip3',0,10), - array('nbShip4',0,10), - array('nbShip5',0,10), - array('nbShip6',0,10) - ); - - foreach($postParamsWanted as $p){ - if(!isset($_POST[$p[0]])){ - error (500,'missing parameter 1'); - die; - }else{ - $value=$_POST[$p[0]]; - } - if ( - (!is_numeric($value)) - OR ($value < $p[1]) - OR ($value > $p[2]) - ) - { - error(500,'wrong parameters '.$p[0]); - die; - } - $postValues[$p[0]]=$value; - - } - //check if bots exists - $bot1Exists = false; - $bot2Exists = false; - foreach($bots as $bot){ - if($bot['id'] == $_POST['bot1']){ - - $bot1 = $bot; - $_SESSION['bot1']=$bot; - $bot1Exists =true; - } - if($bot['id'] == $_POST['bot2']){ - $bot2 = $bot; - $_SESSION['bot2']=$bot; - $bot2Exists =true; - } - if ($bot1Exists && $bot2Exists){ - break; - } - } - if ((!$bot1Exists) OR (!$bot2Exists)){ - error (500,"missing parameter 2"); - } - - if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'],$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'],$postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6'])){ - error (404,"grid is too little for these ships"); - } - - //vars checked, lets init the initGame - - $_SESSION['matchId']=get_unique_id(); - - - for($player = 1; $player <= 2; $player++){ - - if($player==1){ - $opponentName=$bot2['name']; - $currentBot=$bot1; - }else{ - $opponentName=$bot1['name']; - $currentBot=$bot2; - } - - $botParamsToSend=array( - 'game' => 'Battleship', - 'match_id' => $_SESSION['matchId']."-1", - 'act' => 'init', - 'opponent' => $opponentName, - 'width' => $postValues['gridWidth'], - 'height' => $postValues['gridHeight'], - 'ship1' => $postValues['nbShip1'], - 'ship2' => $postValues['nbShip2'], - 'ship3' => $postValues['nbShip3'], - 'ship4' => $postValues['nbShip4'], - 'ship5' => $postValues['nbShip5'], - 'ship6' => $postValues['nbShip6'] - - ); - $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); - $boatsPlayer = json_decode( html_entity_decode($anwserPlayer)); - if(!$boatsPlayer){ - echo $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer; - if($player==1){ - save_battle('Battleship',$bot1['name'],$bot2['name'],2); - }else{ - save_battle('Battleship',$bot1['name'],$bot2['name'],1); - } - die; - } - - //init grid - for($y = 0; $y < $postValues['gridHeight']; $y++){ - for($x = 0; $x < $postValues['gridWidth']; $x++){ - $grid[$player][$y][$x]=0; - } - } - - //vérifier si'il y a le bon nombre de bateaux et les placer - $nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], - $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); - - foreach($boatsPlayer as $boat){ - list($startCoord,$endCoord) = explode("-",$boat); - list($xStart,$yStart)=explode(",",$startCoord); - list($xEnd,$yEnd)=explode(",",$endCoord); - if($xStart == $xEnd){ - $long=abs($yStart - $yEnd) +1; - }else{ - $long=abs($xStart - $xEnd) +1; - } - $nbBoatsIwant[$long]-=1; - $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); - if(!$grid[$player]){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd."; - if($player==1){ - save_battle('Battleship',$bot1['name'],$bot2['name'],2); - }else{ - save_battle('Battleship',$bot1['name'],$bot2['name'],1); - } - die; - } - //remember each cases of each boats - $boatListOfCases=array(); - if($xStart == $xEnd){ - if($yStart <= $yEnd ){ - $start=$yStart; - $end=$yEnd; - }else{ - $start=$yEnd; - $end=$yStart; + //verifier parametres POST + $postParamsWanted=array( + // key,min,max + array('gridWidth',1,100), + array('gridHeight',1,100), + array('nbShip1',0,10), + array('nbShip2',0,10), + array('nbShip3',0,10), + array('nbShip4',0,10), + array('nbShip5',0,10), + array('nbShip6',0,10) + ); + + foreach($postParamsWanted as $p){ + if(!isset($_POST[$p[0]])){ + error (500,'missing parameter 1'); + die; + }else{ + $value=$_POST[$p[0]]; + } + if ( + (!is_numeric($value)) + OR ($value < $p[1]) + OR ($value > $p[2]) + ) + { + error(500,'wrong parameters '.$p[0]); + die; } - for($i = $start; $i <= $end; $i++){ - $boatListOfCases[]=$xStart.",".$i; - } - }else{ - if($xStart <= $xEnd ){ - $start=$xStart; - $end=$xEnd; - }else{ - $start=$xEnd; - $end=$xStart; - } - for($i = $start; $i <= $end; $i++){ - $boatListOfCases[]=$i.",".$yStart; - } - - } - $_SESSION['ships'][$player][]=$boatListOfCases; - } - foreach($nbBoatsIwant as $nb){ - if($nb <> 0){ - echo $currentBot['name']." n'a pas placé le bon nombre de bateaux. Il perd."; - if($player==1){ - save_battle('Battleship',$bot1['name'],$bot2['name'],2); - }else{ - save_battle('Battleship',$bot1['name'],$bot2['name'],1); - } - die; - } - } - } - $_SESSION['ship1']=$postValues['nbShip1']; - $_SESSION['ship2']=$postValues['nbShip2']; - $_SESSION['ship3']=$postValues['nbShip3']; - $_SESSION['ship4']=$postValues['nbShip4']; - $_SESSION['ship5']=$postValues['nbShip5']; - $_SESSION['ship6']=$postValues['nbShip6']; - $_SESSION['strikes'][1]=array(); - $_SESSION['strikes'][2]=array(); - $_SESSION['width']=$postValues['gridWidth']; - $_SESSION['height']=$postValues['gridHeight']; - echo json_encode($grid); die; - - die; - - break; - case "fight": - - if(count($_SESSION['strikes'][1]) == count($_SESSION['strikes'][2])){ - //player 1 has to fight - $currentPlayer=1; - $currentBot=$_SESSION['bot1']; - $opponent=2; - $opponentName=$_SESSION['bot2']['name']; - }else{ - //it's player2 - $currentPlayer=2; - $currentBot=$_SESSION['bot2']; - $opponentName=$_SESSION['bot1']['name']; - $opponent=1; + $postValues[$p[0]]=$value; } - - $botParamsToSend=array( - 'game' => 'Battleship', - 'match_id' => $_SESSION['matchId']."-".$currentPlayer, - 'act' => 'fight', - 'opponent' => $opponentName, - 'width' => $_SESSION['width'], - 'height' => $_SESSION['height'], - 'ship1' => $_SESSION['ship1'], - 'ship2' => $_SESSION['ship2'], - 'ship3' => $_SESSION['ship3'], - 'ship4' => $_SESSION['ship4'], - 'ship5' => $_SESSION['ship5'], - 'ship6' => $_SESSION['ship6'], - 'your_strikes' => json_encode($_SESSION['strikes'][$currentPlayer]), - 'his_strikes' => json_encode($_SESSION['strikes'][$opponent]) - - ); - $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); - - if(!preg_match('/^[0-9]+,[0-9]+$/',$anwserPlayer)){ - echo json_encode(array( - 'target' => '', - 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer - )); - save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); - die; - } - list($x,$y)=explode(",",$anwserPlayer); - - //check if shot is under map's limits - if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ - echo json_encode(array( - 'target' => '', - 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. ".$x.",".$y." C'est interdit par les conventions de Geneve. Il perd" - )); - save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); - die; - } - - //put previous strikes in a one dimmension array ; - $previousStrikes=array(); - foreach( $_SESSION['strikes'][$currentPlayer] as $strikes){ - $previousStrikes[]=$strikes['target']; - } - - //do this strike hit a boat? - $continue=1; - $result=''; - - for( $shipIndex = 0; $shipIndex < count( $_SESSION['ships'][$opponent]); $shipIndex ++){ - $ennemyBoat = $_SESSION['ships'][$opponent][$shipIndex]; - - if(in_array($x.",".$y, $ennemyBoat)){ - $result='hit'; - //sunk? - $sunk=true; - foreach($ennemyBoat as $boatCase){ - if((!in_array($boatCase,$previousStrikes)) && ($boatCase <> $x.",".$y)) { - $sunk=false; - break; - } + if(($_POST['fullLogs'] <> 'true') && ($_POST['fullLogs'] <> 'false')){ + error(500, 'wrong POST parameters'); + die; + } + if($_POST['fullLogs'] == 'true'){ + $wantFullLogs = true; + }else{ + $wantFullLogs = false; + } + + //check if bots exists + $bot1Exists = false; + $bot2Exists = false; + foreach($bots as $bot){ + if($bot['id'] == $_POST['bot1']){ + + $bot1 = $bot; + $_SESSION['bot1']=$bot; + $bot1Exists =true; + } + if($bot['id'] == $_POST['bot2']){ + $bot2 = $bot; + $_SESSION['bot2']=$bot; + $bot2Exists =true; + } + if ($bot1Exists && $bot2Exists){ + break; + } + } + if ((!$bot1Exists) OR (!$bot2Exists)){ + error (500,"missing parameter 2"); + } + + + if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'], + $postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], + $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6'])) + { + error (404,"grid is too little for these ships"); + } + + //******vars checked, lets init the initGame ******* + + $_SESSION['matchId']=get_unique_id(); + $grid['logs'] = array(); + + for($player = 1; $player <= 2; $player++){ + + if($player==1){ + $opponentName=$bot2['name']; + $currentBot=$bot1; + }else{ + $opponentName=$bot1['name']; + $currentBot=$bot2; + } + + $botParamsToSend=array( + 'game-id' => $_SESSION['matchId'], + 'game' => 'battleship', + 'action' => 'init', + 'players' => 2, + 'player-index' => $player -1, + 'board' => array( + 'opponent' => $opponentName, + 'width' => $postValues['gridWidth'], + 'height' => $postValues['gridHeight'], + 'ship1' => $postValues['nbShip1'], + 'ship2' => $postValues['nbShip2'], + 'ship3' => $postValues['nbShip3'], + 'ship4' => $postValues['nbShip4'], + 'ship5' => $postValues['nbShip5'], + 'ship6' => $postValues['nbShip6'] + ) + ); + + $anwserPlayerJson=get_IA_Response($currentBot['url'],$botParamsToSend); + if($wantFullLogs){ + $fullLogs='Arena send to '.$currentBot['name'].''.htmlentities($anwserPlayerJson['messageSend']).'
+ HTTP status: '.htmlentities($anwserPlayerJson['httpStatus']).'
+ Bot anwser: '.htmlentities($anwserPlayerJson['response']).'
'; + }else{ + $fullLogs=""; + } + + if(!isset($anwserPlayerJson['responseArr']['boats'])){ + + echo $fullLogs.$currentBot['name']." a fait une réponse non conforme, il perd 1."; + if($player==1){ + save_battle('Battleship',$bot1['name'],$bot2['name'],2); + }else{ + save_battle('Battleship',$bot1['name'],$bot2['name'],1); + } + die; + } + + $boatsPlayer = $anwserPlayerJson['responseArr']['boats']; + + //init grid + for($y = 0; $y < $postValues['gridHeight']; $y++){ + for($x = 0; $x < $postValues['gridWidth']; $x++){ + $grid[$player][$y][$x]=0; + } + } + + //vérifier si'il y a le bon nombre de bateaux et les placer + $nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], + $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); + + foreach($boatsPlayer as $boat){ + list($startCoord,$endCoord) = explode("-",$boat); + list($xStart,$yStart)=explode(",",$startCoord); + list($xEnd,$yEnd)=explode(",",$endCoord); + if($xStart == $xEnd){ + $long=abs($yStart - $yEnd) +1; + }else{ + $long=abs($xStart - $xEnd) +1; + } + $nbBoatsIwant[$long]-=1; + $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); + if(!$grid[$player]){ + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd."; + if($player==1){ + save_battle('Battleship',$bot1['name'],$bot2['name'],2); + }else{ + save_battle('Battleship',$bot1['name'],$bot2['name'],1); + } + die; + } + //remember each cases of each boats + $boatListOfCases=array(); + if($xStart == $xEnd){ + if($yStart <= $yEnd ){ + $start=$yStart; + $end=$yEnd; + }else{ + $start=$yEnd; + $end=$yStart; + } + for($i = $start; $i <= $end; $i++){ + $boatListOfCases[]=$xStart.",".$i; + } + }else{ + if($xStart <= $xEnd ){ + $start=$xStart; + $end=$xEnd; + }else{ + $start=$xEnd; + $end=$xStart; + } + for($i = $start; $i <= $end; $i++){ + $boatListOfCases[]=$i.",".$yStart; + } + + } + $_SESSION['ships'][$player][]=$boatListOfCases; + } + foreach($nbBoatsIwant as $nb){ + if($nb <> 0){ + echo $fullLogs.$currentBot['name']." n'a pas placé le bon nombre de bateaux. Il perd."; + if($player==1){ + save_battle('Battleship',$bot1['name'],$bot2['name'],2); + }else{ + save_battle('Battleship',$bot1['name'],$bot2['name'],1); + } + die; + } + } + $grid['logs'][] = $fullLogs.$currentBot['name']." put his ships on the map."; + } + $_SESSION['ship1']=$postValues['nbShip1']; + $_SESSION['ship2']=$postValues['nbShip2']; + $_SESSION['ship3']=$postValues['nbShip3']; + $_SESSION['ship4']=$postValues['nbShip4']; + $_SESSION['ship5']=$postValues['nbShip5']; + $_SESSION['ship6']=$postValues['nbShip6']; + $_SESSION['strikes'][1]=array(); + $_SESSION['strikes'][2]=array(); + $_SESSION['width']=$postValues['gridWidth']; + $_SESSION['height']=$postValues['gridHeight']; + echo json_encode($grid); die; + + die; + + break; + case "fight": + if(($_POST['fullLogs'] <> 'true') && ($_POST['fullLogs'] <> 'false')){ + error(500, 'wrong POST parameters'); + die; + } + if($_POST['fullLogs'] == 'true'){ + $wantFullLogs = true; + }else{ + $wantFullLogs = false; } - if($sunk){ - $result="hit and sunk"; - //remove the ship - unset($_SESSION['ships'][$opponent][$shipIndex]); - $_SESSION['ships'][$opponent] = array_values($_SESSION['ships'][$opponent]); - //var_dump($_SESSION['ships'][$opponent]); - //win the game? - if(count($_SESSION['ships'][$opponent]) == 0){ - $result="hit sunk and win"; - $continue=0; - save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$currentPlayer); - } + + if(!isset($fullLogs)){ + $fullLogs = ""; } - - break; - } - } - - //remember this shot - $_SESSION['strikes'][$currentPlayer][]=array( - 'target' => $x.",".$y, - 'result' => $result - ); - - //send message for the arena's ajax web page - echo json_encode(array( - 'opponent'=> $opponent, - 'target' => $x.",".$y, - 'log' => $currentBot['name']." tire en ".$x.",".$y." ".$result, - 'continue' => $continue - )); - - die; - break; - default: - break; + + if(count($_SESSION['strikes'][1]) == count($_SESSION['strikes'][2])){ + //player 1 has to fight + $currentPlayer=1; + $currentBot=$_SESSION['bot1']; + $opponent=2; + $opponentName=$_SESSION['bot2']['name']; + }else{ + //it's player2 + $currentPlayer=2; + $currentBot=$_SESSION['bot2']; + $opponentName=$_SESSION['bot1']['name']; + $opponent=1; + } + + $botParamsToSend=array( + 'game' => 'Battleship', + 'game-id' => $_SESSION['matchId'], + 'action' => 'play-turn', + 'player-index' => $currentPlayer - 1, + 'board' => array( + 'opponent' => $opponentName, + 'width' => $_SESSION['width'], + 'height' => $_SESSION['height'], + 'ship1' => $_SESSION['ship1'], + 'ship2' => $_SESSION['ship2'], + 'ship3' => $_SESSION['ship3'], + 'ship4' => $_SESSION['ship4'], + 'ship5' => $_SESSION['ship5'], + 'ship6' => $_SESSION['ship6'], + 'your_strikes' => $_SESSION['strikes'][$currentPlayer], + 'his_strikes' => $_SESSION['strikes'][$opponent] + ) + ); + $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); + $anwserPlayerJson=$anwserPlayer['responseArr']; + if($wantFullLogs){ + $fullLogs.='Arena send to '.$currentBot['name'].''.htmlentities($anwserPlayer['messageSend']).'
+ HTTP status: '.htmlentities($anwserPlayer['httpStatus']).'
+ Bot anwser: '.htmlentities($anwserPlayer['response']).'
'; + }else{ + $fullLogs.=""; + } + + + if ((!isset($anwserPlayerJson['play'])) + OR (!preg_match('/^[0-9]+,[0-9]+$/',$anwserPlayerJson['play']))){ + echo json_encode(array( + 'target' => '', + 'logs' => $fullLogs.$currentBot['name']." a fait une réponse non conforme, il perd.")); + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); + die; + } + list($x,$y)=explode(",",$anwserPlayerJson['play']); + + //check if shot is under map's limits + if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ + echo json_encode(array( + 'target' => '', + 'logs' => $fullLogs.$currentBot['name']." a fait un tir en dehors des limites de la carte. ".$x.",".$y." C'est interdit par les conventions de Geneve. Il perd" + )); + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); + die; + } + + //put previous strikes in a one dimmension array ; + $previousStrikes=array(); + foreach( $_SESSION['strikes'][$currentPlayer] as $strikes){ + $previousStrikes[]=$strikes['target']; + } + + //do this strike hit a boat? + $continue=1; + $result=''; + + for( $shipIndex = 0; $shipIndex < count( $_SESSION['ships'][$opponent]); $shipIndex ++){ + $ennemyBoat = $_SESSION['ships'][$opponent][$shipIndex]; + + if(in_array($x.",".$y, $ennemyBoat)){ + $result='hit'; + //sunk? + $sunk=true; + foreach($ennemyBoat as $boatCase){ + if((!in_array($boatCase,$previousStrikes)) && ($boatCase <> $x.",".$y)) { + $sunk=false; + break; + } + } + if($sunk){ + $result="hit and sunk"; + //remove the ship + unset($_SESSION['ships'][$opponent][$shipIndex]); + $_SESSION['ships'][$opponent] = array_values($_SESSION['ships'][$opponent]); + //var_dump($_SESSION['ships'][$opponent]); + //win the game? + if(count($_SESSION['ships'][$opponent]) == 0){ + $result="hit sunk and win"; + $continue=0; + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$currentPlayer); + } + } + + break; + } + } + + //remember this shot + $_SESSION['strikes'][$currentPlayer][]=array( + 'target' => $x.",".$y, + 'result' => $result + ); + + //send message for the arena's ajax web page + echo json_encode(array( + 'opponent'=> $opponent, + 'target' => $x.",".$y, + 'logs' => $fullLogs.$currentBot['name']." tire en ".$x.",".$y." ".$result, + 'continue' => $continue + )); + + die; + break; + default: + break; } \ No newline at end of file diff --git a/src/arenas/Battleship/doc-en.html b/src/arenas/Battleship/doc-en.html index 0c26435..545cb32 100644 --- a/src/arenas/Battleship/doc-en.html +++ b/src/arenas/Battleship/doc-en.html @@ -1,173 +1,62 @@ -

- Battleship is played in two stages : -

+

Fonctionnement de la bataille navale

+

Elle se joue en deux phases

-

- At each turn, the arena made HTTP(s) queries containing POST parameters, to your bots.
- They must respond to the specifications below. -

-

Descriptif des paramètres envoyés par l'arène

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterDescription
game - String, will always "Battleship".
- Can be used if your url is used for several games. -
match_id - String. Match the following regular expression : ^[0-9]+-(1|2)$
- The first number (digits before the hyphen) identified the game.
- The number after the hyphen indicates whether you are the first or second bot in the order to play.
- It will serve you if your AI makes statistics on games. -
act - Can take two values :
-
    -
  • "init" : We start the game, you must place your ships
  • -
  • "fight" : You send a shot
  • -
-
opponent - String identifying your opponent.
- So you can grow up delirium by developping an algorithm that adapts depending on the opponent and the history of fighting with it. -
widthInteger, between 1 and 100, inclusive, indicates the width of the map.
heightInteger, between 1 and 100, inclusive, indicates the height of the map.
ship1Integer, between 0 and 10, inclusive, indicates the number of boats with length of 1 box to set.
ship2Integer, between 0 and 10, inclusive, indicates the number of boats with length of 2 box to set.
......
ship6Integer, between 0 and 10, inclusive, indicates the number of boats with length of 6 box to set.
your_strikes -

- String, representing an array in JSON format.
- This parameter is only sent when the game is in shooting phase (act=fight).
- It tells you the shots you've already made and their results.
- In the first round of play, it is an empty array. -

-

- [ ] -

-

- In the second round of game, it contains the previous shot and the result : -

-

- [{"target":"2,0","result":""}] -

-

- In the third round of play, the two previous shots : -

-

- [{"target":"2,0","result":"hit"},{"target":"5,1","result":"hit"}] -

-

- Each shot is a sub array for which : -

-
    -
  • The index target indicates the coordinates of the target shooting x,y
  • -
  • - result may be : -
      -
    • Empty "" means that the shot did not hit anything
    • -
    • "hit" An enemy ship has been hit
    • -
    • "hit and sunk" An enemy ship was hit and sunk
    • -
    -
  • -
-
his_strikesSame except that this is the shot of the opponent.
-

What must return your bot

-

During initialization of the game

-

- Lors de l'initialisation d'une partie StupidIA VS StupidsIA, l'arène a envoyé au bot les parametres POST suivants : - During initialization of part StupidIA VS StupidIA, the arena send to your bot the following parameters in POST : -

-
-    game=Battleship&match_id=828-1&act=init&opponent=stupidIA&width=10&height=10&ship1=0&ship2=1&ship3=2&ship4=1&ship5=1&ship6=0
-
-

- Or, more readable : -

-
-    [game] => Battleship
-    [match_id] => 828-1
-    [act] => init
-    [opponent] => stupidIA
-    [width] => 10
-    [height] => 10
-    [ship1] => 0
-    [ship2] => 1
-    [ship3] => 2
-    [ship4] => 1
-    [ship5] => 1
-    [ship6] => 0
-
-

- The HTTP page that must generate your bot contains the position of ships. -

-

- You return a character string that is a JSON array with as many records as ships.
- Each ship is defined by the coordinates of its ends. -

+

Communications entre l'arène et votre bot

+

Pour communiquer, l'arène (le serveur hébergeant botsarena) fait des requetes http(s) de type POST vers les bots. Le message est dans le corps de la requête au format JSON.

+

Votre bot répond par un array au format JSON.

+

Message d'initialisation de votre partie

+ l'arène envoie le message suivant: +
{"game-id":1609,"game":"battleship","action":"init","players":2,"player-index":0,"board":{"opponent":"stupidIA","width":"10","height":"10","ship1":"0","ship2":"1","ship3":"2","ship4":"1","ship5":"1","ship6":"0"}}
+

Si on décompose le tableau pour l'expliquer:

+ +

Votre bot doit retourner le nom de votre bot et le placement de vos bateaux au format JSON:

+
+  {"name":"gnieark","boats":["4,2-4,6","3,3-3,0","2,3-2,1","7,9-5,9","6,8-6,7"]}
+  
+ -

Placement example of 5 boats with respective sizes 5, 4, 3, 3, 2 boxes :

+

Exemple de placement de 5 bateaux tailles respectives 5, 4, 3, 3, 2 cases :

     ["3,3-3,7","2,1-2,4","0,1-0,3","7,3-7,1","8,8-7,8"]
 

- Of course if your boat overlap, or if their number and length does not match the demand of the arena, you lose the game. + Bien évidemment si vos bateaux se chevauchent, ou si leur nombre et leur longueur ne correspond pas à la demande de l'arène, vous perdez la partie.

- The order of the boats does not matter.
- Similarly, for a boat, the order of its points does not matter either. + L'ordre des bateaux n'a pas d'importance.
+ De la même manière, pour un bateau, l'ordre de ses points n'importe pas non plus.

- Seen on the grid, the example above would be : + Vu sur la grille, l'exemple précédent donnerait :

@@ -314,65 +203,70 @@
-

During the fight

-

- Examples of parameters sent by the arena. -

-

First round (your_strikes and his_strikes are empty)

-
-    [game] => Battleship
-    [match_id] => 834-1
-    [act] => fight
-    [opponent] => stupidIA
-    [width] => 10
-    [height] => 10
-    [ship1] => 0
-    [ship2] => 1
-    [ship3] => 2
-    [ship4] => 1
-    [ship5] => 1
-    [ship6] => 0
-    [your_strikes] => []
-    [his_strikes] => []
-
-

Second round

-
-    [game] => Battleship
-    [match_id] => 834-1
-    [act] => fight
-    [opponent] => stupidIA
-    [width] => 10
-    [height] => 10
-    [ship1] => 0
-    [ship2] => 1
-    [ship3] => 2
-    [ship4] => 1
-    [ship5] => 1
-    [ship6] => 0
-    [your_strikes] => [{"target":"4,6","result":""}]
-    [his_strikes] => [{"target":"7,8","result":""}]
-
-

Third round

-
-    [game] => Battleship
-    [match_id] => 834-1
-    [act] => fight
-    [opponent] => stupidIA
-    [width] => 10
-    [height] => 10
-    [ship1] => 0
-    [ship2] => 1
-    [ship3] => 2
-    [ship4] => 1
-    [ship5] => 1
-    [ship6] => 0
-    [your_strikes] => [{"target":"4,6","result":""},{"target":"3,9","result":"hit"}]
-    [his_strikes] => [{"target":"7,8","result":""},{"target":"7,8","result":""}]
-
-

You simply need to return the address of the box where you want to shoot in the form of x,y

-
-    6,9
-
-

- To shoot on the coordinates x=6 y=9 -

\ No newline at end of file + +

Message vous demandant de jouer (seulement un tour)

+

L'arène vous envoie par exemple le message suivant:

+
{"game":"Battleship","game-id":1615,"action":"play-turn","player-index":1,"board":{"opponent":"stupidIA","width":"10","height":"10","ship1":"0","ship2":"1","ship3":"2","ship4":"1","ship5":"1","ship6":"0","your_strikes":[{"target":"4,3","result":""},{"target":"9,8","result":""}],"his_strikes":[{"target":"2,2","result":""},{"target":"0,6","result":""},{"target":"7,0","result":""}]}}
+ +

la map

+

Elle est représentée par les éléments d'écrits à l'étape précédente et par deux sous tableaux your_strikes et his strikes

+ +

your_strikes et his_strikes

+ +

Chaîne de caractères représentant un array au format JSON.
+ Ce parametre n'est envoyé que lors de la phase de tirs du jeu (act=fight).
+ Il vous indique les tirs que vous avez déjà effectués et leur résultats.
+ Lors du premier tour de jeu, il représente un array vide: +

+
[ ]
+

+ Lors du deuxième tour de jeu, il contient le tir précédent et son résultat : +

+
[{"target":"2,0","result":""}]
+

+ Lors du troisième tour de jeu, les deux tirs précédents : +

+
[{"target":"2,0","result":"hit"},{"target":"5,1","result":"hit"}]
+

+ Chaque tir est un sous array pour lesquels: +

+ + +

Réponse de votre bot

+

Il doit répondre par les coordonnées de la case dans laquelle il souhaite effectuer un tir.

+
{"play":"1,8"}
+

x,y

+

Outils pour développer et tester votre bot

+ +

Script Botsarena en cours de développement

+

Faire entrer votre bot dans cette arène

+

Le formulaire d'inscription de votre bot est sur la page d'accueil du site.

\ No newline at end of file diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index ce3650b..545cb32 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -1,155 +1,45 @@ -

- La bataille navale se joue en deux phases : -

+

Fonctionnement de la bataille navale

+

Elle se joue en deux phases

-

- A chaque tour de jeu l'arène fait des requetes http(s) contenant des paramètres de type POST, vers vos bots.
- Ces derniers doivent répondre selon les spécifications ci dessous. -

-

Descriptif des paramètres envoyés par l'arène

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParamètreDescription
game - Chaîne de caractères, sera toujours "Battleship".
- Peut servir si votre url sert à plusieurs jeux. -
match_id - Chaîne de caractères. Répond à l'expression régulière suivante: ^[0-9]+-(1|2)$
- Le premier nombre (digits avant le tiret) identifie le match.
- Le numéro après le tiret vous indique si vous êtes le bot 1 ou le bot 2 dans l'ordre de jeu.
- Ça vous servira si votre IA fait des statistiques sur les matchs. -
act - Peut prendre deux valeurs :
-
    -
  • "init" : On démarre la partie, vous devez placer vos bateaux
  • -
  • "fight" : Vous envoyez un tir
  • -
-
opponent - Chaîne de caractères identifiant votre adversaire.
- Ainsi, vous pouvez pousser le délire jusqu'à faire un algorythme qui s'adapte en fonction de l'adversaire et de l'historique des combats avec ce dernier. -
widthEntier, compris entre 1 et 100, bornes incluses, vous indique la largeur de la map.
heightEntier, compris entre 1 et 100, bornes incluses, vous indique la hauteur de la map.
ship1Entier, compris entre 0 et 10, bornes incluses, vous indique le nombre de bateaux de longeur 1 case à placer.
ship2Entier, compris entre 0 et 10, bornes incluses, vous indique le nombre de bateaux de longeur 2 cases à placer.
......
ship6Entier, compris entre 0 et 10, bornes incluses, vous indique le nombre de bateaux de longeur 6 cases à placer.
your_strikes -

- Chaîne de caractères représentant un array au format JSON.
- Ce parametre n'est envoyé que lors de la phase de tirs du jeu (act=fight).
- Il vous indique les tirs que vous avez déjà effectués et leur résultats.
- Lors du premier tour de jeu, il représente un array vide. -

-

- [ ] -

-

- Lors du deuxième tour de jeu, il contient le tir précédent et son résultat : -

-

- [{"target":"2,0","result":""}] -

-

- Lors du troisième tour de jeu, les deux tirs précédents : -

-

- [{"target":"2,0","result":"hit"},{"target":"5,1","result":"hit"}] -

-

- Chaque tir est un sous array pour lesquels: -

-
    -
  • L'index target indique les coordonnées du tir x,y
  • -
  • - result peut être : -
      -
    • Vide "" signifie que le tir n'a rien touché
    • -
    • "hit" Un navire ennemi a été touché
    • -
    • "hit and sunk" Un navire ennemi a été touché et coulé
    • -
    -
  • -
-
his_strikesIdem sauf qu'il s'agit du tir de l'adversaire.
-

Ce que doit retourner votre bot

-

Lors de l'initialisation de la partie

-

- Lors de l'initialisation d'une partie StupidIA VS StupidsIA, l'arène a envoyé au bot les parametres POST suivants : -

-
-    game=Battleship&match_id=828-1&act=init&opponent=stupidIA&width=10&height=10&ship1=0&ship2=1&ship3=2&ship4=1&ship5=1&ship6=0
-
-

- Soit, sous forme plus lisible : -

-
-    [game] => Battleship
-    [match_id] => 828-1
-    [act] => init
-    [opponent] => stupidIA
-    [width] => 10
-    [height] => 10
-    [ship1] => 0
-    [ship2] => 1
-    [ship3] => 2
-    [ship4] => 1
-    [ship5] => 1
-    [ship6] => 0
-
-

- La page http que doit générer votre bot contient la position des navires. -

-

- Vous retournez une chaine de caractères qui est un tableau JSON ayant autant d'enregistrements que de navires.
- Chaque navire est défini par les coordonnées de ses extrémités. -

+

Communications entre l'arène et votre bot

+

Pour communiquer, l'arène (le serveur hébergeant botsarena) fait des requetes http(s) de type POST vers les bots. Le message est dans le corps de la requête au format JSON.

+

Votre bot répond par un array au format JSON.

+

Message d'initialisation de votre partie

+ l'arène envoie le message suivant: +
{"game-id":1609,"game":"battleship","action":"init","players":2,"player-index":0,"board":{"opponent":"stupidIA","width":"10","height":"10","ship1":"0","ship2":"1","ship3":"2","ship4":"1","ship5":"1","ship6":"0"}}
+

Si on décompose le tableau pour l'expliquer:

+ +

Votre bot doit retourner le nom de votre bot et le placement de vos bateaux au format JSON:

+
+  {"name":"gnieark","boats":["4,2-4,6","3,3-3,0","2,3-2,1","7,9-5,9","6,8-6,7"]}
+  
+
\ No newline at end of file diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css index 15e9060..1f65098 100644 --- a/src/arenas/Battleship/style.css +++ b/src/arenas/Battleship/style.css @@ -4,6 +4,7 @@ article p select {} td{min-width: 15px; height: 15px;} #fightResult{display:table;} #logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;} +#logs em {color: grey; font-size: 70%; test-transform:italic;} .battleshipGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} .nofloat{float: none;} .battleshipGrid tr{} diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index d5399a0..eecc903 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -1,4 +1,14 @@ players Int indicating the number of players in the game, still 2 on connect Four.
  • board The map, i'll explain it at next chapter
  • you String, Your bot's character on the grid
  • -
  • player-index Int The order of your bot in turns. The first player is 0, second is 2.
  • +
  • player-index Int The order of your bot in turns. The first player is 0, second is 1.
  • The map

    It is represented by a sub-array, on the "board" parameter.
    Exemple:

    diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php index 09b1f14..da11a98 100644 --- a/src/arenas/connectFour/functions.php +++ b/src/arenas/connectFour/functions.php @@ -1,4 +1,15 @@ diff --git a/src/arenas/tictactoe/act.php b/src/arenas/tictactoe/act.php index 45c73d7..8bfccdc 100644 --- a/src/arenas/tictactoe/act.php +++ b/src/arenas/tictactoe/act.php @@ -1,4 +1,14 @@ $_POST['bot1'],'bot2' => $_POST['bot2']); } - - - - -/* -function get_Bots_Array(){ - //Recupérer la liste des Bots - $bots=array(); - $botsList=explode("\n",file_get_contents(__DIR__."/listOfBots.txt")); - - foreach($botsList as $botLigne){ - if(preg_match("/\ (http|https):\/\//", $botLigne)){ - list($name,$url)=explode(" ",$botLigne); - $bots[]=array("name" => $name, "url" =>$url); - } - } - return $bots; -} -*/ diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php index 07acf45..a3261a1 100644 --- a/src/arenas/tictactoe/public.php +++ b/src/arenas/tictactoe/public.php @@ -1,4 +1,15 @@ "tictactoe", diff --git a/src/config.php.empty b/src/config.php.empty index b5f2fe4..f5e4a53 100644 --- a/src/config.php.empty +++ b/src/config.php.empty @@ -1,4 +1,15 @@ "http://botsarena.tinad.fr/"); $mysqlParams=array( 'host' => 'localhost', diff --git a/src/editBot.php b/src/editBot.php index d35fd89..8f9120a 100644 --- a/src/editBot.php +++ b/src/editBot.php @@ -1,4 +1,15 @@