fix State.play(move) + move and fix evaluate from Negamax and AlphaBeta to Player
This commit is contained in:
parent
ecf642de67
commit
f673ed86fb
@ -78,20 +78,22 @@ public class State {
|
|||||||
|
|
||||||
public State play(Pair<Point,Point> move) {
|
public State play(Pair<Point,Point> move) {
|
||||||
State copy = this.copy();
|
State copy = this.copy();
|
||||||
if(move!=null) {
|
boolean isJump = move.getLeft().isJump(move.getRight(), copy.board);
|
||||||
copy.board[move.getRight().getY()][move.getRight().getX()] = copy.currentPlayer;
|
copy.board[move.getRight().getY()][move.getRight().getX()] = copy.currentPlayer;
|
||||||
if (move.getLeft().isJump(move.getRight(), copy.board)) {
|
if (isJump) {
|
||||||
copy.board[move.getLeft().getY()][move.getLeft().getX()] = null;
|
copy.board[move.getLeft().getY()][move.getLeft().getX()] = null;
|
||||||
}
|
copy.board[(move.getLeft().getY() + move.getRight().getY()) / 2][(move.getLeft().getX() + move.getRight().getX()) / 2] = copy.currentPlayer;
|
||||||
|
} else {
|
||||||
for (int i = -1; i < 2; i++) {
|
for (int i = -1; i < 2; i++) {
|
||||||
for (int z = -1; z < 2; z++) {
|
for (int z = -1; z < 2; z++) {
|
||||||
try {
|
try {
|
||||||
|
if(copy.board[move.getRight().getY() + i][move.getRight().getX() + z] != null)
|
||||||
copy.board[move.getRight().getY() + i][move.getRight().getX() + z] = copy.currentPlayer;
|
copy.board[move.getRight().getY() + i][move.getRight().getX() + z] = copy.currentPlayer;
|
||||||
} catch (IndexOutOfBoundsException ignored) {
|
} catch (IndexOutOfBoundsException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ni = 0, nj = 0;
|
int ni = 0, nj = 0;
|
||||||
for (Player[] players : copy.board) {
|
for (Player[] players : copy.board) {
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
|
@ -39,12 +39,4 @@ public class AlphaBetaPlayer extends Player{
|
|||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int evaluate(State game){
|
|
||||||
Player winner = game.getWinner();
|
|
||||||
if(winner == null)
|
|
||||||
return 0;
|
|
||||||
else if(winner == game.getCurrentPlayer())
|
|
||||||
return -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,14 +38,6 @@ public class NegamaxPlayer extends Player {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int evaluate(State game){
|
|
||||||
Player winner = game.getWinner();
|
|
||||||
if(winner == null)
|
|
||||||
return 0;
|
|
||||||
else if(winner == game.getCurrentPlayer())
|
|
||||||
return -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
@ -14,4 +14,13 @@ public abstract class Player {
|
|||||||
|
|
||||||
public abstract Pair<Point, Point> play(State board);
|
public abstract Pair<Point, Point> play(State board);
|
||||||
|
|
||||||
|
protected int evaluate(State game){
|
||||||
|
Player winner = game.getWinner();
|
||||||
|
if(winner == null)
|
||||||
|
return 0;
|
||||||
|
else if(winner == game.getCurrentPlayer())
|
||||||
|
return 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user