Negamax
This commit is contained in:
parent
4c52df803f
commit
57c31435f0
@ -7,8 +7,8 @@ public class Main {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Player p1 = new NegamaxPlayer(4);
|
||||
Player p2 = new NegamaxPlayer(4);
|
||||
Player p1 = new NegamaxPlayer(3);
|
||||
Player p2 = new NegamaxPlayer(2);
|
||||
Player[][] board = initialize(p1, p2);
|
||||
State game = new State(board, p1, p2);
|
||||
System.out.println("joueur 1: " + p1);
|
||||
@ -22,6 +22,7 @@ public class Main {
|
||||
System.out.println(game.getWinner() + " a gagné la partie");
|
||||
System.out.println(game.getScore(p1));
|
||||
System.out.println(game.getScore(p2));
|
||||
|
||||
}
|
||||
|
||||
public static Player[][] initialize(Player p1, Player p2){
|
||||
|
@ -107,18 +107,19 @@ public class State {
|
||||
return currentPlayer;
|
||||
}
|
||||
|
||||
public void setCurrentPlayer(Player currentPlayer) {
|
||||
this.currentPlayer = currentPlayer;
|
||||
public void setCurrentPlayer(Player player) {
|
||||
this.currentPlayer = player;
|
||||
}
|
||||
|
||||
public State copy () {
|
||||
State copy = new State(this.board, this.player1, this.player2);
|
||||
State copy = new State(new Player[7][7], this.player1, this.player2);
|
||||
for (int i = 0; i < this.board.length; i++) {
|
||||
System.arraycopy(this.board[i], 0, copy.board[i], 0, this.board.length);
|
||||
System.arraycopy(this.board[i], 0, copy.board[i], 0, this.board[i].length);
|
||||
}
|
||||
copy.setCurrentPlayer(this.currentPlayer);
|
||||
copy.setCurrentPlayer(this.getCurrentPlayer());
|
||||
copy.n1 = n1;
|
||||
copy.n2 = n2;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -150,7 +151,8 @@ public class State {
|
||||
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.getCurrentPlayer().equals(((State) state).getCurrentPlayer()));
|
||||
bool = bool && (this.player1.equals(((State) state).player1)) && (this.player2.equals(((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++){
|
||||
|
@ -43,8 +43,12 @@ public class NegamaxPlayer extends Player {
|
||||
if(winner == null)
|
||||
return 0;
|
||||
else if(winner == game.getCurrentPlayer())
|
||||
return 1;
|
||||
return -1;
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof NegamaxPlayer);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user