diff --git a/Makefile b/Makefile index 35b4308..e134f54 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ BUILDFILES=$(OBJECTS) $(FXMLS_BUILD) MAIN=game.Main +N=100 + all: $(CLASSES) $(FXMLS_BUILD) $(JAVAC) $(JAVAC_OPTIONS) -cp $(CLASSPATH):$(LIBARIES) $(CLASSES) -d $(BUILDS) @@ -35,6 +37,9 @@ all: $(CLASSES) $(FXMLS_BUILD) run: $(CLASSES) $(JAVA) -cp $(BUILDS):$(LIBARIES) $(MAIN) +simulate: $(CLASSES) + $(JAVA) -cp $(BUILDS):$(LIBARIES) $(MAIN) $(N) + doc: $(CLASSES) $(JAVADOC) $(JAVADOC_OPTIONS) -cp $(CLASSPATH):$(LIBARIES) $(CLASSES) -d $(DOC) diff --git a/src/game/Game.java b/src/game/Game.java index a2c0a88..6b84c57 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -88,14 +88,18 @@ public class Game { // TODO: Improve IDs statistic[result]++; } + double[] percents = new double[3]; + for (int i = 0; i < statistic.length; i++) { + percents[i] = ((double)statistic[i]) / runs * 100.0; + } System.out.println("Draws : " + statistic[0]); 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(p1.getName() + ": " + (statistic[1] / runs * 100.0) + "% wins"); - System.out.println(p2.getName() + ": " + (statistic[2] / runs * 100.0) + "% wins"); + System.out.println("Draws : " + percents[0] + "%"); + System.out.println(p1.getName() + ": " + percents[1] + "% wins"); + System.out.println(p2.getName() + ": " + percents[2] + "% wins"); } diff --git a/src/game/Main.java b/src/game/Main.java index bda92b4..69c5bb6 100644 --- a/src/game/Main.java +++ b/src/game/Main.java @@ -7,8 +7,12 @@ import player.malte.MalteAI; public class Main { public static void main(String[] args) { - Player p1 = new MalteAI("Malte"); - Player p2 = new MaurizioAI("Maurizio"); - new Game(p1, p2).start(true, true); //1. param = output mode, 2. param = random beginner + if (args.length == 1) { + Game.simulate(Integer.parseInt(args[0])); + } else { + Player p1 = new MalteAI("Malte"); + Player p2 = new MaurizioAI("Maurizio"); + new Game(p1, p2).start(true, true); //1. param = output mode, 2. param = random beginner + } } }