// =================================================================================================
// Sample Mind for simple starter WWM 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
function Mind() {
var wantedx = -1;
var wantedy = -1;
const gridsize = 50;
var GRID = new Array(gridsize);
for (var gi = 0; gi < gridsize ; gi++) {
GRID[gi] = new Array(gridsize); // each element is an array
for (var gj = 0; gj < gridsize ; gj++) {
GRID[gi][gj] = false;
}
}
for (var gia = 0; gia < gridsize; gia++) {
GRID[0][gia] = true;
GRID[gia][0] = true;
GRID[gridsize - 1][gia] = true;
GRID[gia][gridsize - 1] = true;
}
//--- public functions / interface / API ----------------------------------------------------------
this.newRun = function()
{
};
/*const ACTION_LEFT = 0;
const ACTION_RIGHT = 1;
const ACTION_UP = 2;
const ACTION_DOWN = 3;
const ACTION_STAYSTILL = 4;*/
this.getAction = function ( x ) // x is an array of [ ai, aj, ei, ej ]
{
if (wantedx != -1 && wantedy != -1 && wantedx == x[0] && wantedy == x[1]) {
GRID[wantedx][wantedy] = true;
}
if (x[0] > x[2] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
if (x[1] > x[3] && x[0] - x[2] > x[1] - x[3] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] + 1;
return 2;
}
else if (x[1] < x[3] && x[0] - x[2] > x[3] - x[1] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] - 1;
return 3;
}
else {
wantedx = x[0] + 1;
wantedy = x[1];
return 1
}
}
else if (x[0] < x[2] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
if (x[1] > x[3] && x[2] - x[0] > x[1] - x[3] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] + 1;
return 2;
}
else if (x[1] < x[3] && x[2] - x[0] > x[3] - x[1] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] - 1;
return 3;
}
else {
wantedx = x[0] - 1;
wantedy = x[1];
return 0;
}
}
else if (x[1] > x[3] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] + 1;
return 2;
}
else if (x[1] < x[3] && wantedx != x[0] && wantedy != x[1] && GRID[x[0]][x[1]] == false) {
wantedx = x[0];
wantedy = x[1] - 1;
return 3;
}
return ( randomintAtoB (0,4) ); // Ignore enemy. Just move randomly
};
this.endRun = function()
{
};
}