From e09df4e89b13b7d1b097c4e58b27b76e8e94909a Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Wed, 16 Feb 2022 00:12:10 +0100 Subject: [PATCH] Add AiPlayer --- src/main/java/AIPlayer.java | 13 +++++++++++++ src/main/java/Game.java | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/main/java/AIPlayer.java diff --git a/src/main/java/AIPlayer.java b/src/main/java/AIPlayer.java new file mode 100644 index 0000000..f6aa6cb --- /dev/null +++ b/src/main/java/AIPlayer.java @@ -0,0 +1,13 @@ +import java.util.ArrayList; + +public class AIPlayer extends Player{ + + public AIPlayer(String name, int startPos, int startHome, int jumpToHome) { + super(name, startPos, startHome, jumpToHome); + } + + @Override + public int choose(ArrayList usableFigures) { + return (int) (Math.random() * usableFigures.size()); + } +} diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 85d7a61..eb1c66e 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -48,9 +48,9 @@ public class Game { gb.initGameboard(); players = new ArrayList<>(); players.add(new Player("Rot",0, 40, 39)); - players.add(new Player("Blau",10, 44, 9)); - players.add(new Player("Gelb",20, 48, 19)); - players.add(new Player("Grün",30, 52, 29)); + players.add(new AIPlayer("Blau",10, 44, 9)); + players.add(new AIPlayer("Gelb",20, 48, 19)); + players.add(new AIPlayer("Grün",30, 52, 29)); } public String printGameboard(Game g, Player p, int dice) {