Removing "id" from player class and subclasses

This commit is contained in:
Arthur 2021-02-22 21:23:03 +01:00
parent c7f1d52352
commit d41a3c4584
4 changed files with 10 additions and 11 deletions

View File

@ -2,14 +2,13 @@ package othello;
import othello.players.NegamaxPlayer;
import othello.players.Player;
import othello.players.RandomPlayer;
public class Main {
public static void main(String[] args) {
Player p1 = new NegamaxPlayer(1);
Player p2 = new RandomPlayer(-1);
Player p2 = new NegamaxPlayer(100);
Player[][] board = initialize(p1, p2);
State game = new State(board, p1, p2);
System.out.println("joueur 1: " + p1);
@ -17,7 +16,7 @@ public class Main {
while(!game.isOver()) {
Player player = game.getCurrentPlayer();
System.out.println(game.toString());
game = game.play(player.play(game,100));
game = game.play(player.play(game));
}
System.out.println(game.toString());
System.out.println(game.getWinner() + " a gagné la partie");

View File

@ -6,12 +6,12 @@ import othello.State;
public class NegamaxPlayer extends Player {
public NegamaxPlayer(int id) {
super(id);
public NegamaxPlayer(int depth) {
super(depth);
}
@Override
public Pair<Point, Point> play(State game,int depth) {
public Pair<Point, Point> play(State game) {
int bestValue = Integer.MIN_VALUE;
Pair<Point, Point> bestMove = null;
for(Pair<Point, Point> move : game.getMove(game.getCurrentPlayer())) {

View File

@ -6,12 +6,12 @@ import othello.State;
public abstract class Player {
protected final int id;
protected final int depth;
public Player(int id) {
this.id = id;
public Player(int depth) {
this.depth = depth;
}
public abstract Pair<Point, Point> play(State board,int depth);
public abstract Pair<Point, Point> play(State board);
}

View File

@ -17,7 +17,7 @@ public class RandomPlayer extends Player {
}
@Override
public Pair<Point, Point> play(State game, int depth) {
public Pair<Point, Point> play(State game) {
LinkedList<Pair<Point, Point>> moves = game.getMove(this);
return moves.get(random.nextInt(moves.size()));
}