// Cloned by Ali on 15 Nov 2020 from Mind "Complex Mind (clone by Ali) (clone by Ali)" by Ali
// Please leave this clone trail here.
// Cloned by Ali on 14 Nov 2020 from Mind "Complex Mind (clone by Ali)" by Ali
// Please leave this clone trail here.
// Cloned by Ali on 14 Nov 2020 from Mind "Complex Mind" by Starter user
// Please leave this clone trail here.
// =================================================================================================
// Sample Mind for more complex 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
// Ali codes for Agent behaviour
function steps_count(pos, direction) {
var cur_pos = [pos[0], pos[1]];
var steps = -1;
do {
cur_pos[0] += direction[0];
cur_pos[1] += direction[1];
steps += 1;
} while(!occupied(cur_pos[0], cur_pos[1]));
return steps;
}
AB.mind.getAction = function ( x ) // x is an array of [ ai, aj, ei, ej ]
{
var ai = x[0];
var aj = x[1];
var ei = x[2];
var ej = x[3];
var action = null, direction = null;
var maxDist = null, dist;
var directions = [
[1, 0], // right
[-1, 0], // left
[0, 1], // top
[0, -1] // bottom
];
var actions = [
ACTION_RIGHT,
ACTION_LEFT,
ACTION_UP,
ACTION_DOWN
];
var cur_action = 0;
directions.forEach(cur_direction => {
var dest = [ai + cur_direction[0], aj + cur_direction[1]];
var cur_pos = [ai, aj];
if(!occupied(dest[0], dest[1])) {
dist = Manhattan_Distance(dest, [ei, ej])
if(action === null
|| (dist > maxDist)
|| (dist === maxDist && steps_count(cur_pos, cur_direction) > steps_count(cur_pos, direction))
) {
action = actions[cur_action];
maxDist = dist;
direction = cur_direction;
}
}
cur_action++;
})
return action === null ? ACTION_UP : action;
};