commit
c383ac8c57
|
@ -9,17 +9,14 @@
|
|||
# http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
||||
#
|
||||
# -- END LICENSE BLOCK -----------------------------------------
|
||||
//démmarrer une session php
|
||||
|
||||
@session_start();
|
||||
|
||||
require_once("../src/functions.php");
|
||||
|
||||
|
||||
|
||||
$arenas=get_arenas_list();
|
||||
$lang=get_language_array();
|
||||
|
||||
|
||||
if(isset($_GET['arena'])){
|
||||
//check if arena is list
|
||||
$currentArena = false;
|
||||
|
@ -38,21 +35,17 @@ if(isset($_GET['arena'])){
|
|||
$currentArena = "";
|
||||
}
|
||||
|
||||
|
||||
//form submitting
|
||||
if (isset($_POST['xd_check'])){
|
||||
//vérifier le numero de formulaire
|
||||
if (($_SESSION['xd_check']!=$_POST['xd_check']) AND ($_POST['xd_check'] !="")){
|
||||
erreur ('Something wrong has appen');
|
||||
error (400, 'Something wrong has appen');
|
||||
die;
|
||||
}
|
||||
//call the good act.php
|
||||
if(($currentArena <> "") && (file_exists("../src/arenas/".$currentArena."/act.php"))){
|
||||
require_once("../src/arenas/".$currentArena."/act.php");
|
||||
}else{
|
||||
require_once("../src/arenas/".$currentArena."/act.php");
|
||||
}
|
||||
|
||||
}
|
||||
//title
|
||||
if($currentArena == ""){
|
||||
|
@ -65,9 +58,7 @@ if($currentArena == ""){
|
|||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="ROBOTS" content="INDEX, FOLLOW" />
|
||||
|
@ -78,17 +69,15 @@ if($currentArena == ""){
|
|||
@import url(/style.css);
|
||||
</style>
|
||||
<?php
|
||||
//script js de l'arene
|
||||
//arena specific script js (if needed)
|
||||
if(isset($currentArenaArr['jsFile'])){
|
||||
echo '<script type="text/javascript"><!--';
|
||||
echo '<script type="text/javascript"><!--'."\n";
|
||||
echo file_get_contents("../src/arenas/".$currentArena."/".$currentArenaArr['jsFile']);
|
||||
echo '--></script>';
|
||||
echo "\n--></script>";
|
||||
}
|
||||
?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<h1><?php echo $siteTitle; ?></h1>
|
||||
<nav id="languages"><a href="-fr">fr</a> <a href="-en">en</a></nav>
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
require_once(__DIR__."/functions.php");
|
||||
switch ($_POST['act']){
|
||||
|
||||
case "fight":
|
||||
$bots=get_Bots_Array();
|
||||
//clean $_POST vars
|
||||
$postParams=get_Post_Params(count($bots));
|
||||
if(!$postParams){
|
||||
error(400,"wrong parameters send");
|
||||
die;
|
||||
}else{
|
||||
$bot1=$postParams['bot1'];
|
||||
$bot2=$postParams['bot2'];
|
||||
}
|
||||
//init map
|
||||
$map=array(
|
||||
'0-0' => '','0-1' => '','0-2' => '',
|
||||
'1-0' => '','1-1' => '','1-2' => '',
|
||||
'2-0' => '','2-1' => '','2-2' => '');
|
||||
|
||||
$end=false;
|
||||
$playerPlayingNow=1;
|
||||
while($end==false){
|
||||
switch($playerPlayingNow){
|
||||
case 1:
|
||||
$playerURL=$bots[$bot1]['url'];
|
||||
$playerCHAR='X';
|
||||
$playerName=$bots[$bot1]['name'];
|
||||
break;
|
||||
case 2:
|
||||
$playerURL=$bots[$bot2]['url'];
|
||||
$playerCHAR='O';
|
||||
$playerName=$bots[$bot2]['name'];
|
||||
break;
|
||||
|
||||
default:
|
||||
error(500,"oups");
|
||||
die;
|
||||
}
|
||||
$playerResponse=get_IA_Response($playerCHAR,$playerURL,$map);
|
||||
//tester la validité de la réponse
|
||||
if((isset($map[$playerResponse])) && ($map[$playerResponse]=="")){
|
||||
//reponse conforme
|
||||
echo "<p>".$playerName." joue en ".$playerResponse." la nouvelle grille est <br/>";
|
||||
$map[$playerResponse]=$playerCHAR;
|
||||
echo "<table>";
|
||||
for($j=0;$j<3;$j++){
|
||||
echo "<tr>";
|
||||
for($i=0;$i<3;$i++){
|
||||
echo '<td class="cellj'.$j.' celli'.$i.'">'.$map[$j.'-'.$i].'</td>';
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
//tester si trois caracteres allignés
|
||||
if(
|
||||
(($map['0-0']==$map['0-1'])&&($map['0-1']==$map['0-2'])&&($map['0-2']!==""))
|
||||
OR (($map['1-0']==$map['1-1'])&&($map['1-1']==$map['1-2'])&&($map['1-2']!==""))
|
||||
OR (($map['2-0']==$map['2-1'])&&($map['2-1']==$map['2-2'])&&($map['2-2']!==""))
|
||||
OR (($map['0-0']==$map['1-0'])&&($map['1-0']==$map['2-0'])&&($map['2-0']!==""))
|
||||
OR (($map['0-1']==$map['1-1'])&&($map['1-1']==$map['2-1'])&&($map['2-1']!==""))
|
||||
OR (($map['0-2']==$map['1-2'])&&($map['1-2']==$map['2-2'])&&($map['2-2']!==""))
|
||||
OR (($map['0-0']==$map['1-1'])&&($map['1-1']==$map['2-2'])&&($map['2-2']!==""))
|
||||
OR (($map['0-2']==$map['1-1'])&&($map['1-1']==$map['2-0'])&&($map['2-0']!==""))
|
||||
){
|
||||
echo "<p>".$playerName." ".$playerCHAR." a gagné.</p>";
|
||||
$end=true;
|
||||
break;
|
||||
}
|
||||
//tester si toutes les cases ne seraient pas prises
|
||||
$full=true;
|
||||
foreach($map as $char){
|
||||
if($char==""){
|
||||
$full=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($full){
|
||||
echo "<p>Match nul</p>";
|
||||
$end=true;
|
||||
break;
|
||||
}
|
||||
|
||||
//on change de joueur
|
||||
if($playerPlayingNow==1){
|
||||
$playerPlayingNow=2;
|
||||
}else{
|
||||
$playerPlayingNow=1;
|
||||
}
|
||||
}else{
|
||||
echo "<p>".$playerName." a fait une réponse non conforme. Il perd</p>";
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
die;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
function get_Post_Params(){
|
||||
function get_Post_Params($botsCount){
|
||||
$keysBots=array('bot1','bot2');
|
||||
foreach($keysBots as $botKey){
|
||||
if(!isset($_POST[$botKey])){
|
||||
|
@ -8,7 +8,7 @@ function get_Post_Params(){
|
|||
if(!is_numeric(($_POST[$botKey]))){
|
||||
|
||||
}
|
||||
if(($_POST[$botKey] < 0) OR ($_POST[$botKey] > count($bots))){
|
||||
if(($_POST[$botKey] < 0) OR ($_POST[$botKey] > $botsCount)){
|
||||
error(400,"wrong parameters");
|
||||
die;
|
||||
}
|
||||
|
|
|
@ -20,20 +20,7 @@ function tictactoe(bot1,bot2,xd_check){
|
|||
document.getElementById('fightResult').innerHTML = xhr.responseText;
|
||||
}
|
||||
}};
|
||||
xhr.open("POST", 'index.php', true);
|
||||
xhr.open("POST", '/tictactoe', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + ,xd_check);
|
||||
xhr.send('act=fight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check);
|
||||
}
|
||||
|
||||
function refreshBots(){
|
||||
var xhr = Ajx();
|
||||
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
||||
if(xhr.status == 200) {
|
||||
window.location.reload();
|
||||
}
|
||||
}};
|
||||
xhr.open("POST", 'index.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send('act=reDownloadBotsList');
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
require_once(__DIR__."/functions.php");
|
||||
|
||||
$bots=get_Bots_Array();
|
||||
$postParams=get_Post_Params();
|
||||
$postParams=get_Post_Params(count($bots));
|
||||
if(!$postParams){
|
||||
$bot1="";
|
||||
$bot2="";
|
||||
|
@ -40,6 +40,6 @@ if(!$postParams){
|
|||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p><input type="button" value="Fight!" onclick="tictactoe(document.getElementById('bot1').value,document.getElementById('bot2').value);"></p>
|
||||
<p><input type="button" value="Fight!" onclick="tictactoe(document.getElementById('bot1').value,document.getElementById('bot2').value,'<?php echo xd_check_input(2); ?>');"></p>
|
||||
</article>
|
||||
<article id="fightResult"></article>
|
|
@ -86,6 +86,14 @@ function error($code,$message){
|
|||
header("HTTP/1.0 404 Not Found");
|
||||
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8" /><title>Page Not found</title></head><body><p>'.$message.'</p></body></html>';
|
||||
die;
|
||||
case 400:
|
||||
header ("HTTP/1.0 400 Bad Request");
|
||||
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8" /><title>Bad request</title></head><body><p>'.$message.'</p></body></html>';
|
||||
die;
|
||||
case 500:
|
||||
header ("HTTP/1.0 500 Internal Server Error");
|
||||
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8" /><title>Bad request</title></head><body><p>'.$message.'</p></body></html>';
|
||||
die;
|
||||
default:
|
||||
|
||||
die;
|
||||
|
|
Loading…
Reference in New Issue
Block a user