From 4c52df803fe82ee81b44dc91d5c037581a116e51 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Tue, 23 Feb 2021 17:49:22 +0100 Subject: [PATCH] Adding equals --- src/othello/State.java | 14 +++++++++++++- src/othello/players/NegamaxPlayer.java | 9 +++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/othello/State.java b/src/othello/State.java index 818bc6d..92de7d1 100644 --- a/src/othello/State.java +++ b/src/othello/State.java @@ -146,5 +146,17 @@ public class State { } return str.toString(); } - + @Override + public boolean equals(Object state) { + boolean bool; + bool = ( state instanceof State); + bool = bool && (this.getCurrentPlayer() == ((State) state).getCurrentPlayer()) && (this.player1 == ((State) state).player1) && (this.player2 == ((State) state).player2); + bool = bool && (this.n1 == ((State)state).n1)&& (this.n2 == ((State)state).n2); + for (int i = 0; i < this.board.length; i++) { + for (int y = 0; y < this.board.length; y++){ + bool = bool && (this.board[i][y] == ((State)state).board[i][y]); + } + } + return bool; + } } diff --git a/src/othello/players/NegamaxPlayer.java b/src/othello/players/NegamaxPlayer.java index 0e68390..ac90df6 100644 --- a/src/othello/players/NegamaxPlayer.java +++ b/src/othello/players/NegamaxPlayer.java @@ -16,7 +16,7 @@ public class NegamaxPlayer extends Player { Pair bestMove = null; for(Pair move : game.getMove(game.getCurrentPlayer())) { State nextState = game.play(move); - int value = -negamax(nextState, this.depth,Integer.MIN_VALUE,Integer.MAX_VALUE); + int value = -negamax(nextState, this.depth); if (value > bestValue) { bestValue = value; bestMove = move; @@ -25,7 +25,7 @@ public class NegamaxPlayer extends Player { return bestMove; } - private int negamax(State state, int depth,int alpha,int beta) { + private int negamax(State state, int depth) { if(depth == 0 || state.isOver()) { return evaluate(state); } @@ -33,10 +33,7 @@ public class NegamaxPlayer extends Player { int m = Integer.MIN_VALUE; for (Pair move : state.getMove(state.getCurrentPlayer())) { State nextState = state.play(move); - m= Math.max(m,-negamax(nextState,depth-1,alpha,beta)); - alpha = Math.max(alpha, m); - if(alpha >= beta) - break; + m= Math.max(m,-negamax(nextState,depth-1)); } return m; }