Skip to content

Commit 66eb833

Browse files
authored
Merge pull request aimacode#289 from rajatthakur/iss-fix2
Replaced '==' Fixes aimacode#288
2 parents 5da329a + 4a0b54b commit 66eb833

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

aima-core/src/main/java/aima/core/environment/tictactoe/TicTacToeState.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.List;
6+
import java.util.Objects;
67

78
import aima.core.util.datastructure.XYLocation;
89

@@ -29,7 +30,7 @@ public String getPlayerToMove() {
2930
}
3031

3132
public boolean isEmpty(int col, int row) {
32-
return board[getAbsPosition(col, row)] == EMPTY;
33+
return Objects.equals(board[getAbsPosition(col, row)], EMPTY);
3334
}
3435

3536
public String getValue(int col, int row) {
@@ -45,16 +46,16 @@ public void mark(XYLocation action) {
4546
}
4647

4748
public void mark(int col, int row) {
48-
if (utility == -1 && getValue(col, row) == EMPTY) {
49+
if (utility == -1 && Objects.equals(getValue(col, row), EMPTY)) {
4950
board[getAbsPosition(col, row)] = playerToMove;
5051
analyzeUtility();
51-
playerToMove = (playerToMove == X ? O : X);
52+
playerToMove = (Objects.equals(playerToMove, X) ? O : X);
5253
}
5354
}
5455

5556
private void analyzeUtility() {
5657
if (lineThroughBoard()) {
57-
utility = (playerToMove == X ? 1 : 0);
58+
utility = (Objects.equals(playerToMove, X) ? 1 : 0);
5859
} else if (getNumberOfMarkedPositions() == 9) {
5960
utility = 0.5;
6061
}
@@ -67,7 +68,7 @@ public boolean lineThroughBoard() {
6768
private boolean isAnyRowComplete() {
6869
for (int row = 0; row < 3; row++) {
6970
String val = getValue(0, row);
70-
if (val != EMPTY && val == getValue(1, row) && val == getValue(2, row)) {
71+
if (!Objects.equals(val, EMPTY) && Objects.equals(val, getValue(1, row)) && Objects.equals(val, getValue(2, row))) {
7172
return true;
7273
}
7374
}
@@ -77,7 +78,7 @@ private boolean isAnyRowComplete() {
7778
private boolean isAnyColumnComplete() {
7879
for (int col = 0; col < 3; col++) {
7980
String val = getValue(col, 0);
80-
if (val != EMPTY && val == getValue(col, 1) && val == getValue(col, 2)) {
81+
if (!Objects.equals(val, EMPTY) && Objects.equals(val, getValue(col, 1)) && Objects.equals(val, getValue(col, 2))) {
8182
return true;
8283
}
8384
}
@@ -87,11 +88,11 @@ private boolean isAnyColumnComplete() {
8788
private boolean isAnyDiagonalComplete() {
8889
boolean retVal = false;
8990
String val = getValue(0, 0);
90-
if (val != EMPTY && val == getValue(1, 1) && val == getValue(2, 2)) {
91+
if (!Objects.equals(val, EMPTY) && Objects.equals(val, getValue(1, 1)) && Objects.equals(val, getValue(2, 2))) {
9192
return true;
9293
}
9394
val = getValue(0, 2);
94-
if (val != EMPTY && val == getValue(1, 1) && val == getValue(2, 0)) {
95+
if (!Objects.equals(val, EMPTY) && Objects.equals(val, getValue(1, 1)) && Objects.equals(val, getValue(2, 0))) {
9596
return true;
9697
}
9798
return retVal;
@@ -138,7 +139,7 @@ public boolean equals(Object anObj) {
138139
if (anObj != null && anObj.getClass() == getClass()) {
139140
TicTacToeState anotherState = (TicTacToeState) anObj;
140141
for (int i = 0; i < 9; i++) {
141-
if (board[i] != anotherState.board[i]) {
142+
if (!Objects.equals(board[i], anotherState.board[i])) {
142143
return false;
143144
}
144145
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aima.core.environment.vacuum;
22

33
import java.util.LinkedHashSet;
4+
import java.util.Objects;
45
import java.util.Set;
56

67
import aima.core.agent.Action;
@@ -43,7 +44,7 @@ protected DynamicState updateState(DynamicState state,
4344
state.setAttribute(ATTRIBUTE_CURRENT_STATE,
4445
vep.getLocationState());
4546
// Keep track of the state of the different locations
46-
if (VacuumEnvironment.LOCATION_A == vep.getAgentLocation()) {
47+
if (Objects.equals(VacuumEnvironment.LOCATION_A, vep.getAgentLocation())) {
4748
state.setAttribute(ATTRIBUTE_STATE_LOCATION_A,
4849
vep.getLocationState());
4950
} else {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import aima.core.agent.impl.AbstractAgent;
77
import aima.core.agent.impl.NoOpAction;
88

9+
import java.util.Objects;
10+
911
/**
1012
* Artificial Intelligence A Modern Approach (3rd Edition): Figure 2.8, page 48.<br>
1113
* <br>
@@ -39,11 +41,11 @@ public Action execute(Percept percept) {
3941
.getLocationState()) {
4042
return VacuumEnvironment.ACTION_SUCK;
4143
// else if location = A then return Right
42-
} else if (VacuumEnvironment.LOCATION_A == vep
43-
.getAgentLocation()) {
44+
} else if (Objects.equals(VacuumEnvironment.LOCATION_A, vep
45+
.getAgentLocation())) {
4446
return VacuumEnvironment.ACTION_MOVE_RIGHT;
45-
} else if (VacuumEnvironment.LOCATION_B == vep
46-
.getAgentLocation()) {
47+
} else if (Objects.equals(VacuumEnvironment.LOCATION_B, vep
48+
.getAgentLocation())) {
4749
// else if location = B then return Left
4850
return VacuumEnvironment.ACTION_MOVE_LEFT;
4951
}

aima-core/src/main/java/aima/core/nlp/parsing/grammars/Rule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.List;
6+
import java.util.Objects;
67

78
/**
89
* A derivation rule that is contained within a grammar. This rule is probabilistic, in that it
@@ -65,7 +66,7 @@ public boolean derives( List<String> sentForm ) {
6566
return false;
6667
}
6768
for( int i=0; i < sentForm.size(); i++ ) {
68-
if( this.rhs.get(i) != sentForm.get(i)) {
69+
if(!Objects.equals(this.rhs.get(i), sentForm.get(i))) {
6970
return false;
7071
}
7172
}

0 commit comments

Comments
 (0)