From 5df378e315210f2ba7bec1a484390fb95a8b0ee8 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Wed, 18 Oct 2017 23:13:29 +0200 Subject: [PATCH] Fixing things --- src/game/Game.java | 13 +++++++------ src/player/Player.java | 2 +- src/player/malte/MalteAI.java | 6 +++++- src/player/maurizio/MaurizioAI.java | 5 +++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/game/Game.java b/src/game/Game.java index dcd9b27..a2c0a88 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -4,6 +4,7 @@ import java.util.Random; import player.Player; import player.maurizio.MaurizioAI; +import player.malte.MalteAI; /** * Represents a game of Connect Four. @@ -76,8 +77,8 @@ public class Game { * @param runs The number of games to simulate. */ public static void simulate(int runs) { - Player p1 = new MaurizioAI(); - Player p2 = new MalteAI(); + Player p1 = new MaurizioAI("Maurizio"); + Player p2 = new MalteAI("Malte"); // 0 - Draw // 1 - p1 wins // 2 - p2 wins @@ -88,13 +89,13 @@ public class Game { statistic[result]++; } System.out.println("Draws : " + statistic[0]); - System.out.println("Maurizio: " + statistic[1] + " wins"); - System.out.println("Malte : " + statistic[2] + " wins"); + System.out.println(p1.getName() + ": " + statistic[1] + " wins"); + System.out.println(p2.getName() + ": " + statistic[2] + " wins"); System.out.println("PERCENTAGE:"); System.out.println("Draws : " + (statistic[0] / runs * 100.0) + "%"); - System.out.println("Maurizio: " + (statistic[1] / runs * 100.0) + "% wins"); - System.out.println("Malte : " + (statistic[2] / runs * 100.0) + "% wins"); + System.out.println(p1.getName() + ": " + (statistic[1] / runs * 100.0) + "% wins"); + System.out.println(p2.getName() + ": " + (statistic[2] / runs * 100.0) + "% wins"); } diff --git a/src/player/Player.java b/src/player/Player.java index 414d4e1..c9d6fbb 100644 --- a/src/player/Player.java +++ b/src/player/Player.java @@ -4,5 +4,5 @@ public interface Player { public int move(int[][] game); public String getName(); - public setPlayerID(int id); + public void setPlayerID(int id); } diff --git a/src/player/malte/MalteAI.java b/src/player/malte/MalteAI.java index 1211ed8..645ae89 100644 --- a/src/player/malte/MalteAI.java +++ b/src/player/malte/MalteAI.java @@ -11,13 +11,17 @@ public class MalteAI implements Player{ private String name; private Random ran; - private int id = 2; + private int id; public MalteAI(String name){ this.name = name; this.ran = new Random(); } + public void setPlayerID(int id) { + this.id = id; + } + public int move(int[][] board){ Set options = new HashSet<>(Arrays.asList(0,1,2,3,4,5,6)); for (Integer i: copySet(options)) { diff --git a/src/player/maurizio/MaurizioAI.java b/src/player/maurizio/MaurizioAI.java index 6a9d904..a73ddce 100644 --- a/src/player/maurizio/MaurizioAI.java +++ b/src/player/maurizio/MaurizioAI.java @@ -8,12 +8,17 @@ public class MaurizioAI implements Player { private String name; private Random ran; + private int id; public MaurizioAI(String name){ this.name = name; this.ran = new Random(); } + public void setPlayerID(int id) { + this.id = id; + } + public int move(int[][] board){ int choice = ran.nextInt(7); while (board[choice][0] != 0) {