private double CalculateValue( GridWorldState state, IGridWorldPolicy policy, IGridWorldRewarder gridWorldRewarder) { var newValue = 0.0; foreach (var action in _world.AvailableActions(state)) { var nextState = _world.NextState(state, action); var reward = gridWorldRewarder.Reward(state, action); newValue += policy.PAction(state, action) * (reward + Value(nextState)); } return(newValue); }
private static GridWorldAction FindBestAction( GridWorld world, GridWorldState state, GridWorldValueTable gridWorldValueTable, IGridWorldRewarder gridWorldRewarder) { var max = double.MinValue; var maxAction = GridWorldAction.Down; foreach (var action in world.AvailableActions(state)) { var nextState = world.NextState(state, action); var nextStateValue = gridWorldValueTable.Value(nextState); var reward = gridWorldRewarder.Reward(state, action); if (reward + nextStateValue > max) { max = reward + nextStateValue; maxAction = action; } } return(maxAction); }