php-chess/html/index.php

37 lines
684 B
PHP
Raw Normal View History

2024-10-19 13:32:46 +00:00
<?php
require_once '../src/core.php';
use Game\Game;
use Game\Move;
2024-10-19 13:32:46 +00:00
session_start();
if (isset($_SESSION["game"])) {
$game = $_SESSION["game"];
2024-10-31 15:59:19 +00:00
$engine = $_SESSION["engine"];
} else {
$game = Game::fromStartPosition();
2024-10-31 15:59:19 +00:00
$engine = new \Engine\Random();
$_SESSION["game"] = $game;
2024-10-31 15:59:19 +00:00
$_SESSION["engine"] = $engine;
}
2024-10-19 13:32:46 +00:00
$content = function() use ($game) {
require '../src/View/fragments/game.php';
2024-10-19 13:32:46 +00:00
};
if (isset($_GET["move"])) {
$move = Move::fromJS($_REQUEST["move"]);
$game->applyInPlace($move);
2024-10-31 15:59:19 +00:00
$opponentMove = $engine->nextMove($game);
$game->applyInPlace($opponentMove);
$content();
} else {
require '../src/View/base.php';
}