private double UpdateAgentPosition( ref int currentX, ref int currentY, int action )
{
// default reward is equal to moving reward
double reward = moveReward;
// moving direction
int dx = 0, dy = 0;
switch ( action )
{
case 0: // go to north (up)
dy = -1;
break;
case 1: // go to east (right)
dx = 1;
break;
case 2: // go to south (down)
dy = 1;
break;
case 3: // go to west (left)
dx = -1;
break;
}
int newX = currentX + dx;
int newY = currentY + dy;
// check new agent's coordinates
if (
( map[newY, newX] != 0 ) ||
( newX < 0 ) || ( newX >= mapWidth ) ||
( newY < 0 ) || ( newY >= mapHeight )
)
{
// we found a wall or got outside of the world
reward = wallReward;
}
else
{
currentX = newX;
currentY = newY;
// check if we found the goal
if ( ( currentX == agentStopX ) && ( currentY == agentStopY ) )
reward = goalReward;
}
return reward;
}