// Cloned by seytan6161 on 12 Mar 2019 from Mind "Cloned Simple Mind" by Eoghan Murphy
// Please leave this clone trail here.
// Cloned by Eoghan Murphy on 5 Nov 2018 from Mind "Simple Mind" by Starter user
// Please leave this clone trail here.
// ==== Starter Mind ===============================================================================================
// (c) Ancient Brain Ltd. All rights reserved.
// This code is only for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// This code may not be copied, re-published or used on any other website.
// To include a run of this code on another website, see the "Embed code" links provided on the Ancient Brain site.
// ==================================================================================================================
// =================================================================================================
// Sample Mind for simple starter World
// =================================================================================================
// World tells us agent position and enemy position
// World does not tell us of existence of walls
// if return invalid move (not empty square) World just ignores it and we miss a turn
// 0 -x
// 1 +x
// 2 +y
// 3 -y
function Mind()
{
var enemyX;
var enemyY;
var lastMove = 0;
var lastPosition = 0;
var forbiddenSpots = Set();
var bestIndex = -1;
var myX;
var myY;
this.newRun = function()
{
};
this.getAction = function ( x )
{
//console.log(x);
myX = x[0];
myY = x[1];
enemyX = x[2];
enemyY = x[3];
var possible = newMoves(myX, myY);
var bestMove = [enemyX, enemyY];
for(i = 0; i < possible.length; i++){
//console.log(possible[i]);
if(value(possible[i], enemyX, enemyY) > value(bestMove, enemyX, enemyY) && possible[i] != lastMove && !forbiddenSpots.has(possible[i])){
bestMove = possible[i];
bestIndex = i;
}
}
//console.log(bestMove);
console.log("-----");
//console.log(forbiddenSpots);
console.log("-----");
console.log("this="+ [myX, myY] + " last=" + lastPosition);
if(myX == lastPosition[0] && myY == lastPosition[1]){
forbiddenSpots.add(lastMove);
}
lastPosition = [myX, myY];
lastMove = possible[bestIndex];
return(bestIndex);
};
this.endRun = function()
{
};
}
function newMoves(x,y){
var possiblemoves = []
possiblemoves.push([x-1,y]);
possiblemoves.push([x+1,y]);
possiblemoves.push([x,y+1]);
possiblemoves.push([x,y-1]);
return possiblemoves;
}
function value(coords, eX, eY){
var val = Math.pow((coords[0] - eX), 2) + Math.pow((coords[1] - eY), 2);
//console.log(coords, (coords[1] - eY), coords[1], eY, val);
val = Math.sqrt(val);
//console.log(val);
return val;
}