diff --git a/app/routes.php b/app/routes.php index 01d604b..4f5605b 100644 --- a/app/routes.php +++ b/app/routes.php @@ -4,7 +4,6 @@ use Chess\Heuristics\EvalFunction; use Chess\Heuristics\SanHeuristics; -use Chess\Variant\Classical\Board as ClassicalBoard; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\App; use Slim\Http\Response as Response; @@ -31,10 +30,8 @@ // TODO: Parameter validation - $board = new ClassicalBoard(); - $evalFunction = new EvalFunction(); - $heuristics = new SanHeuristics($params['movetext'], $board); + $heuristics = new SanHeuristics($params['movetext']); $json = [ 'evalNames' => $evalFunction->names(), diff --git a/public/main.js b/public/main.js index 8c34695..32dd6c2 100644 --- a/public/main.js +++ b/public/main.js @@ -1,7 +1,22 @@ const gameForm = document.getElementById('gameForm'); -gameForm.querySelector('button').onclick = (event) => { - // TODO: Send the data to the /api/heuristics endpoint - console.log(gameForm.querySelector('textarea').value); +gameForm.querySelector('button').onclick = async (event) => { event.preventDefault(); + await fetch(`http://localhost:8080/api/heuristics`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + movetext: gameForm.querySelector('textarea').value + }) + }) + .then(res => res.json()) + .then(res => { + // TODO + console.log(res); + }) + .catch(error => { + alert('Whoops! Something went wrong, please try again.'); + }); }