From 8ed7093d2dde0f453422a24f28225ef54b4c38ba Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Wed, 18 Oct 2017 23:09:40 +0200 Subject: [PATCH] Added simulation method. Implementing #8 --- src/game/Game.java | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/game/Game.java b/src/game/Game.java index 9fbf3ae..dcd9b27 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -69,19 +69,34 @@ public class Game { this.gameOn = false; } - // /** - // * Simulates n games. - // * - // * @param runs The number of games to simulate. - // */ - // public static void simulate(int runs) { - // Player p1 = new MaurizioAI(); - // Player p2 = new MalteAI(); - // for (int i = 0; i < runs; i++) { - // Game g = new Game(p1, p2); - // g.start - // } - // } + /** + * Simulates n games. + * Simulates the games and prints statistical output to stdout. + * + * @param runs The number of games to simulate. + */ + public static void simulate(int runs) { + Player p1 = new MaurizioAI(); + Player p2 = new MalteAI(); + // 0 - Draw + // 1 - p1 wins + // 2 - p2 wins + int[] statistic = new int[3]; + for (int i = 0; i < runs; i++) { + int result = new Game(p1, p2).start(false, true); + // TODO: Improve IDs + 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("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"); + + } /** * Start a game.