Skip to content

Commit fd4db34

Browse files
committed
Minor simplifications.
1 parent f336688 commit fd4db34

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

aima-core/src/main/java/aima/core/agent/impl/aprog/SimpleReflexAgentProgram.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected SimpleReflexAgentProgram(Set<Rule<A>> rules) {
4343
this.rules = rules;
4444
}
4545

46-
// function SIMPLE-RELEX-AGENT(percept) returns an action
46+
// function SIMPLE-REFLEX-AGENT(percept) returns an action
4747
@Override
4848
public final Optional<A> apply(P percept) {
4949
DynamicState state = interpretInput(percept);

aima-core/src/main/java/aima/core/environment/vacuum/MazeVacuumEnvironment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public int getYDimension() {
7575
public VacuumPercept getPerceptSeenBy(Agent<?, ?> agent) {
7676
VacuumPercept result = super.getPerceptSeenBy(agent);
7777
String loc = getAgentLocation(agent);
78-
result.setAttribute(ATT_CAN_MOVE_LEFT, canMoveLeft(loc) ? "True" : "False");
79-
result.setAttribute(ATT_CAN_MOVE_RIGHT, canMoveRight(loc) ? "True" : "False");
80-
result.setAttribute(ATT_CAN_MOVE_DOWN, canMoveDown(loc) ? "True" : "False");
81-
result.setAttribute(ATT_CAN_MOVE_UP, canMoveUp(loc) ? "True" : "False");
78+
result.setAttribute(ATT_CAN_MOVE_LEFT, canMoveLeft(loc));
79+
result.setAttribute(ATT_CAN_MOVE_RIGHT, canMoveRight(loc));
80+
result.setAttribute(ATT_CAN_MOVE_DOWN, canMoveDown(loc));
81+
result.setAttribute(ATT_CAN_MOVE_UP, canMoveUp(loc));
8282
return result;
8383
}
8484

aima-core/src/main/java/aima/core/environment/vacuum/RandomWalkVacuumAgent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import aima.core.util.Util;
66
import static aima.core.environment.vacuum.MazeVacuumEnvironment.*;
77

8+
import java.util.Objects;
89
import java.util.Optional;
910

1011
/**
@@ -44,13 +45,13 @@ public Optional<Action> act(VacuumPercept percept) {
4445

4546
// avoid obstacles
4647
for (int i = 0; i < 2 ; i++) {
47-
if (action == ACTION_MOVE_UP && "False".equals(percept.getAttribute(ATT_CAN_MOVE_UP)))
48+
if (action == ACTION_MOVE_UP && Objects.equals(percept.getAttribute(ATT_CAN_MOVE_UP), false))
4849
action = ACTION_MOVE_LEFT;
49-
if (action == ACTION_MOVE_LEFT && "False".equals(percept.getAttribute(ATT_CAN_MOVE_LEFT)))
50+
if (action == ACTION_MOVE_LEFT && Objects.equals(percept.getAttribute(ATT_CAN_MOVE_LEFT), false))
5051
action = ACTION_MOVE_DOWN;
51-
if (action == ACTION_MOVE_DOWN && "False".equals(percept.getAttribute(ATT_CAN_MOVE_DOWN)))
52+
if (action == ACTION_MOVE_DOWN && Objects.equals(percept.getAttribute(ATT_CAN_MOVE_DOWN), false))
5253
action = ACTION_MOVE_RIGHT;
53-
if (action == ACTION_MOVE_RIGHT && "False".equals(percept.getAttribute(ATT_CAN_MOVE_RIGHT)))
54+
if (action == ACTION_MOVE_RIGHT && Objects.equals(percept.getAttribute(ATT_CAN_MOVE_RIGHT), false))
5455
action = ACTION_MOVE_UP;
5556
else
5657
break;

aima-core/src/main/java/aima/core/search/informed/AStarSearch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public AStarSearch(QueueSearch<S, A> impl, ToDoubleFunction<Node<S, A>> h) {
3838

3939
// f(n) = g(n) + h(n)
4040
public static <S, A> EvaluationFunction<S, A> createEvalFn(ToDoubleFunction<Node<S, A>> h) {
41-
return new EvaluationFunction<S, A>(h) {
41+
return new EvaluationFunction<>(h) {
4242
@Override
4343
public double applyAsDouble(Node<S, A> node) {
4444
return node.getPathCost() + this.h.applyAsDouble(node);

aima-core/src/main/java/aima/core/search/informed/GreedyBestFirstSearch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public GreedyBestFirstSearch(QueueSearch<S, A> impl, ToDoubleFunction<Node<S, A>
3535

3636
// f(n) = h(n)
3737
public static <S, A> EvaluationFunction<S, A> createEvalFn(ToDoubleFunction<Node<S, A>> h) {
38-
return new EvaluationFunction<S, A>(h) {
38+
return new EvaluationFunction<>(h) {
3939
@Override
4040
public double applyAsDouble(Node<S, A> node) {
4141
return this.h.applyAsDouble(node);

0 commit comments

Comments
 (0)