From af4d9d850467961edcad89810ba0bd9d13f0582f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 10 Feb 2021 12:19:22 +0100 Subject: [PATCH] added abstractPlayer and RandomPlayer --- src/othello/Main.java | 5 +---- src/othello/players/AbstractPlayer.java | 12 ++++++++++++ src/othello/players/RandomPlayer.java | 13 ++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/othello/players/AbstractPlayer.java diff --git a/src/othello/Main.java b/src/othello/Main.java index 7257b85..b125684 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -12,11 +12,8 @@ public class Main { while(!game.isOver()) { int player = game.getCurrentPlayer(); ArrayList> moves = game.getMove(player); + } - ArrayList a = new ArrayList<>(); - a.add(new Point(3,3)); - System.out.println(game.getMove(p1).toString()); - //System.out.println(a.get(0).toString()); } public static int[][] initialize(int p1, int p2){ diff --git a/src/othello/players/AbstractPlayer.java b/src/othello/players/AbstractPlayer.java new file mode 100644 index 0000000..6dd5a53 --- /dev/null +++ b/src/othello/players/AbstractPlayer.java @@ -0,0 +1,12 @@ +package othello.players; + +import java.util.ArrayList; + +import othello.Pair; +import othello.Point; + +public abstract class AbstractPlayer { + + public abstract Pair play(ArrayList> moves); + +} diff --git a/src/othello/players/RandomPlayer.java b/src/othello/players/RandomPlayer.java index 1196add..3510b6c 100644 --- a/src/othello/players/RandomPlayer.java +++ b/src/othello/players/RandomPlayer.java @@ -1,5 +1,16 @@ package othello.players; -public class RandomPlayer { +import java.util.ArrayList; +import java.util.Random; + +import othello.Pair; +import othello.Point; + +public class RandomPlayer extends AbstractPlayer { + + @Override + public Pair play(ArrayList> moves) { + return moves.get(new Random().nextInt(moves.size())); + } }