/
ReflexVacuumAgent.java
40 lines (36 loc) · 1.25 KB
/
ReflexVacuumAgent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package aima.core.environment.vacuum;
import aima.core.agent.Action;
import aima.core.agent.impl.SimpleAgent;
import static aima.core.environment.vacuum.VacuumEnvironment.*;
import java.util.Optional;
/**
* Artificial Intelligence A Modern Approach (3rd Edition): Figure 2.8, page 48.<br>
* <br>
* <pre>
* function REFLEX-VACUUM-AGENT([location, status]) returns an action
* if status = Dirty then return Suck
* else if location = A then return Right
* else if location = B then return Left
* </pre>
* Figure 2.8 The agent program for a simple reflex agent in the two-state
* vacuum environment. This program implements the action function tabulated in
* Figure 2.3.
*
* @author Ciaran O'Reilly
* @author Ruediger Lunde
*/
public class ReflexVacuumAgent extends SimpleAgent<VacuumPercept, Action> {
public ReflexVacuumAgent() {
super(percept -> {
Action action = null;
if (LocationState.Dirty == percept.getCurrState())
action = ACTION_SUCK;
else if (LOCATION_A.equals(percept.getCurrLocation()))
action = ACTION_MOVE_RIGHT;
else if (LOCATION_B.equals(percept.getCurrLocation()))
action = ACTION_MOVE_LEFT;
// Note: Empty should not be returned if the environment is correct
return Optional.ofNullable(action);
});
}
}