rendered paste body private void learn()
{
int iteration = 0;
double myDelt;
do {
myDelt = 0;
for(int i=0; i<v.length; i++ )
for( int j=0; j<v[i].length; j++ )
{
if( v[i][j] == null ) continue;
if( !track.onTrack(new Point(i,j)) )
{
v[i][j] = null; //no sense in updating invalid points, this will decrease storage and CPU
continue;
}
if( track.finalState(new State(i,j,0,0)) ) //final state, don't let it update the score.
{
continue;
}
for( int k=0; k<v[i][j].length; k++ )
for( int l=0; l<v[i][j][k].length; l++)
{ //for each state [i][j][k][l]
double temp = v[i][j][k][l];
State now = new State(i,j,k+Speed.MIN_SPEED,l+Speed.MIN_SPEED);
//figure out the best action to take, if we can.
double maxScore = sentinal;
State maxState = null;
for( int m=0; m<Action.ALL_ACTIONS.length; m++ )
{
State next = track.NextState(now, Action.ALL_ACTIONS[m], false);
if( maxScore < v[next.p.xpos][next.p.ypos][next.s.xmod()][next.s.ymod()] )
{
maxScore = v[next.p.xpos][next.p.ypos][next.s.xmod()][next.s.ymod()];
maxState = next;
}
}
//figure out what would happen if we mess up
Action a = new Action(0,0);
State next = track.NextState(now, a, false);
double whoops = v[next.p.xpos][next.p.ypos][next.s.xmod()][next.s.ymod()];
//update V(state)
v[i][j][k][l] = 0.9 * (discount*maxScore + Utilities.Reward(maxState, track) )+
0.1 * (discount*whoops + Utilities.Reward(next, track) );
//v[i][j][k][l] = discount * ( 0.9*maxScore + 0.1*whoops );
//check the delta on that
if( Math.abs(temp - v[i][j][k][l]) > myDelt )
{
myDelt = Math.abs(temp - v[i][j][k][l]);
}
}
}
if( iteration++ % 1000 == 0 && DEBUG ) System.out.println("This round's delta: " + myDelt );
} while ( myDelt > delta );
return;
}