77import com .baeldung .algorithms .mcts .tictactoe .Position ;
88
99public class State {
10- Board board ;
11- int playerNo ;
12- int visitCount ;
13- double winScore ;
10+ private Board board ;
11+ private int playerNo ;
12+ private int visitCount ;
13+ private double winScore ;
1414
1515 public State () {
1616 board = new Board ();
@@ -27,23 +27,23 @@ public State(Board board) {
2727 this .board = new Board (board );
2828 }
2929
30- public Board getBoard () {
30+ Board getBoard () {
3131 return board ;
3232 }
3333
34- public void setBoard (Board board ) {
34+ void setBoard (Board board ) {
3535 this .board = board ;
3636 }
3737
38- public int getPlayerNo () {
38+ int getPlayerNo () {
3939 return playerNo ;
4040 }
4141
42- public void setPlayerNo (int playerNo ) {
42+ void setPlayerNo (int playerNo ) {
4343 this .playerNo = playerNo ;
4444 }
4545
46- public int getOpponent () {
46+ int getOpponent () {
4747 return 3 - playerNo ;
4848 }
4949
@@ -55,11 +55,11 @@ public void setVisitCount(int visitCount) {
5555 this .visitCount = visitCount ;
5656 }
5757
58- public double getWinScore () {
58+ double getWinScore () {
5959 return winScore ;
6060 }
6161
62- public void setWinScore (double winScore ) {
62+ void setWinScore (double winScore ) {
6363 this .winScore = winScore ;
6464 }
6565
@@ -75,23 +75,23 @@ public List<State> getAllPossibleStates() {
7575 return possibleStates ;
7676 }
7777
78- public void incrementVisit () {
78+ void incrementVisit () {
7979 this .visitCount ++;
8080 }
8181
82- public void addScore (double score ) {
82+ void addScore (double score ) {
8383 if (this .winScore != Integer .MIN_VALUE )
8484 this .winScore += score ;
8585 }
8686
87- public void randomPlay () {
87+ void randomPlay () {
8888 List <Position > availablePositions = this .board .getEmptyPositions ();
8989 int totalPossibilities = availablePositions .size ();
9090 int selectRandom = (int ) (Math .random () * ((totalPossibilities - 1 ) + 1 ));
9191 this .board .performMove (this .playerNo , availablePositions .get (selectRandom ));
9292 }
9393
94- public void togglePlayer () {
94+ void togglePlayer () {
9595 this .playerNo = 3 - this .playerNo ;
9696 }
9797}
0 commit comments