public override Action execute(Percept psPrime)
{
Object sPrime = ptsFunction.getState(psPrime);
// if GOAL-TEST(s') then return stop
if (goalTest(sPrime))
{
a = NoOpAction.NO_OP;
}
else
{
// if s' is a new state (not in H) then H[s'] <- h(s')
if (!H.containsKey(sPrime))
{
H.put(sPrime, getHeuristicFunction().h(sPrime));
}
// if s is not null
if (null != s)
{
// result[s, a] <- s'
result.put(s, a, sPrime);
// H[s] <- min LRTA*-COST(s, b, result[s, b], H)
// b (element of) ACTIONS(s)
double min = Double.MAX_VALUE;
foreach (Action b in actions(s))
{
double cost = lrtaCost(s, b, result.get(s, b));
if (cost < min)
{
min = cost;
}
}
H.put(s, min);
}
// a <- an action b in ACTIONS(s') that minimizes LRTA*-COST(s', b,
// result[s', b], H)
double min = Double.MAX_VALUE;
// Just in case no actions
a = NoOpAction.NO_OP;
foreach (Action b in actions(sPrime))
{
double cost = lrtaCost(sPrime, b, result.get(sPrime, b));
if (cost < min)
{
min = cost;
a = b;
}
}
}
// s <- s'
s = sPrime;
if (a.isNoOp())
{
// I'm either at the Goal or can't get to it,
// which in either case I'm finished so just die.
setAlive(false);
}
// return a
return a;
}