From 21ef944a87e0116713e73945469801f81d9df374 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 21 Sep 2019 19:49:56 +0200 Subject: Interactively set parameter to AI in interactor --- interactor/index.html | 20 +++++++++++++++++--- interactor/interactor.js | 25 +++++++++++++++++++++++-- player_mmbias.cpp | 10 ++++++++-- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/interactor/index.html b/interactor/index.html index 4593974..46df00f 100644 --- a/interactor/index.html +++ b/interactor/index.html @@ -10,7 +10,7 @@ var CVSH=500; var COLOURS=["#00F","#F00","#0CC"]; -var socket=io(); +var socket=io(location.href); var CELLSZ=~~(CVSH/(H+1)); var CVSW=CELLSZ*(W+1); var CELL0X=~~(CVSW/2-W/2*CELLSZ)+.5,CELL0Y=~~(CVSH/2-H/2*CELLSZ)+.5; @@ -184,6 +184,11 @@ function getusermove(){ setstatustext("Your turn!"); } +function newgameparameter(){ + var parameter=document.getElementById("parameter").value; + location.href=location.pathname+"?parameter="+encodeURIComponent(parameter); +} + function setstatustext(text){ var elem=document.getElementById("statustext"); elem.innerHTML=text; @@ -192,6 +197,11 @@ function setstatustext(text){ function assert(cond){if(!cond)throw new Error("Assertion failed");} +socket.on("ainame",function(name){ + var span=document.getElementById("ai_name"); + span.innerHTML=""; + span.appendChild(document.createTextNode(name)); +}); socket.on("emptyboard",function(){ bd=emptyboard(); }); @@ -223,6 +233,10 @@ socket.on("win",function(player){

Interactor for Chain Reaction


- +
+
+Current AI:
+Parameter setting: + - \ No newline at end of file + diff --git a/interactor/interactor.js b/interactor/interactor.js index 64684ae..ae38b29 100755 --- a/interactor/interactor.js +++ b/interactor/interactor.js @@ -69,7 +69,26 @@ function stopproc(proc){ mkdirp("logs"); +function validparameterchar(c){ + return 48<=c.charCodeAt(0)&&c.charCodeAt(0)<58; +} + io.on("connection",function(conn){ + // TODO: make nicer + var unsafe_parameter=conn.request._query.parameter; + var aicmd_here=aicmd; + if(unsafe_parameter!=null){ + var parameter=""; + for(var i=0;i