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

View File

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

View File

@ -6,12 +6,12 @@ import othello.State;
public abstract class Player { public abstract class Player {
protected final int id; protected final int depth;
public Player(int id) { public Player(int depth) {
this.id = id; 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 @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); LinkedList<Pair<Point, Point>> moves = game.getMove(this);
return moves.get(random.nextInt(moves.size())); return moves.get(random.nextInt(moves.size()));
} }