function Mind()
{
this.compare_Lists = function(a1, a2)
{
return (a1[0] === a2[0]) && (a1[1] === a2[1])
}
this.in_array = function(big, small)
{
i = 0
while (i < big.length)
{
if (this.compare_Lists(big[i], small))
{return true}
i += 1
}
return false
}
this.distance = function(object1, object2)
{
xdistance = object2[0]-object1[0]
if (xdistance < 0)
xdistance = -xdistance
ydistance = object2[1]-object1[1]
if (ydistance < 0)
ydistance = -ydistance
return xdistance+ydistance
};
this.sort_Potential_Destinations = function(destinations)
{
i = 0
while (i < destinations.length)
{
maxi = i
j = i
while (j < destinations.length)
{
if (destinations[j][0] > destinations[maxi][0])
maxi = j;
j += 1
}
tmp = destinations[maxi]
destinations[maxi] = destinations[i]
destinations[i] = tmp
i += 1
}
}
this.newRun = function()
{
console.log("newRun")
this.previous_Agent_Position = [0, 0]
this.previous_Enemy_Position = [0, 0]
this.intended_Position = [0, 0]
this.blocks = [[0,0]]
};
this.getAction = function ( state )
{
console.log("######### GET ACTION #########")
agent_x = state[0]
agent_y = state[1]
enemy_x = state[2]
enemy_y = state[3]
current_Agent_Position = [state[0], state[1]]
current_Enemy_Position = [state[2], state[3]]
console.log("Current Agent Position = " + current_Agent_Position)
console.log("Current Enemy Position = " + current_Enemy_Position)
console.log(this.intended_Position)
console.log(current_Agent_Position)
if (this.compare_Lists(this.previous_Agent_Position, current_Agent_Position) && (!this.compare_Lists(this.previous_Enemy_Position, this.intended_Position)) && !this.in_array(this.blocks, this.intended_position))
{console.log("AGENT STALL")
this.blocks.push(this.intended_Position)
}
console.log("as;fnw;oignwe;io")
potential_Moves_To_Destinations =
{
0:[agent_x-1, agent_y],
1:[agent_x+1, agent_y],
2:[agent_x, agent_y+1],
3:[agent_x, agent_y-1],
4:[agent_x, agent_y]
}
a = []
i = 0
/*
while (i < 5)
{
move = potential_Moves_To_Destinations[i]
console.log(this.blocks)
if (this.in_array(this.blocks, move) === false)
{
d = this.distance(move, current_Enemy_Position)
//Index 0 of each move is the distance between the Agent and Enemy at that position. Index 1 is the move (0...4) to bring the Agent to the position
a.push([d, i])
}
i += 1
}*/
if (a.length < 2)
this.blocks.push(current_Agent_Position)
this.sort_Potential_Destinations(a)
console.log(a)
this.previous_Agent_Position = current_Agent_Position
this.previous_Enemy_Position = current_Enemy_Position
this.intended_position = potential_Moves_To_Destinations[a[0][1]]
console.log("chosen move = " + a[0][1])
return a[0][1]
};
this.endRun = function()
{
console.log("endRun")
};
}