// Cloned by milesj2 on 26 Nov 2018 from Mind "New Mind" by milesj2
// Please leave this clone trail here.
function Mind()
{
var moves;
this.newRun = function()
{
};
this.getAction = function ( x )
{
var ai = x[0];
var aj = x[1];
var ei = x[2];
var ej = x[3];
var grid = x[4];
var corner = this.getCorner(ei, ej);
grid[corner[0]][corner[1]] = 9;
this.traverse(grid, ai, aj, []);
console.log(this.moves);
console.log(grid);
if (this.moves[0] < ai){
return ACTION_LEFT;
}
else if (this.moves[0] > ai){
return ACTION_RIGHT;
}
else if (this.moves[1] < aj){
return ACTION_UP;
}
else if (this.moves[1] > aj){
return ACTION_DOWN;
}
else{
return AB.randomIntAtoB(0, 4);
}
return;
};
// Find furthest corner away from Enemy
this.getCorner = function(ei, ej){
var corner_1 = [[1, 1], this.getDistance([1, 1], ei, ej)];
var corner_2 = [[1, gridsize - 2], this.getDistance([1, gridsize - 2], ei, ej)];
var corner_3 = [[gridsize - 2, 1], this.getDistance([gridsize - 2, 2], ei, ej)];
var corner_4 = [[gridsize - 2, gridsize - 2], this.getDistance([gridsize - 2, gridsize - 2], ei, ej)];
var corner_list = [corner_1, corner_2, corner_3, corner_4];
var min = Math.min(corner_1[1], corner_2[1], corner_3[1], corner_4[1]);
for (var i = 0; i < corner_list.length; i++){
if (min == corner_list[i][1]){
return corner_list[i][0];
}
}
};
// Get distance from enemy to corner cords
this.getDistance = function(corner, ei, ej){
var info_a= corner[0] - ei;
var info_b = corner[1] = ej;
var corner_distance = Math.sqrt(info_a*info_a + info_b*info_b);
return Math.abs(corner_distance);
};
// Find shortest path
this.traverse = function(grid, col, row, array) {
if(grid[col][row] == 9) {
for (var i = 0; i < array.length; i++){
var xx = moves[i][0];
var yy = moves[i][1];
grid[xx][yy] = 8;
}
this.moves = array[0]; // this is fucking undefined now for some reason
console.log(this.moves);
}
else if(grid[col][row] == 1) {
grid[col][row] = 3;
if(col < grid.length - 1) {
array.push([col + 1, row])
this.traverse(grid, col + 1, row, array)
}
if(row < grid[col].length - 1) {
array.push([col, row + 1])
this.traverse(grid, col, row + 1, array)
}
if(col > 0) {
array.push([col - 1, row])
this.traverse(grid, col - 1, row, array)
}
if(row > 0) {
array.push([col, row - 1])
this.traverse(grid, col, row - 1, array)
}
}
return array;
};
this.endRun = function()
{
};
}