diff options
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java | 83 |
1 files changed, 77 insertions, 6 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java b/src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java index 59152a0..210e4ae 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java +++ b/src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java @@ -4,7 +4,7 @@ package de.fhswf.in.inf.java1.aufgabe7; /** - * TODO Add comment here + * Calculates the the success rate of different players. * * @author $Author: $ * @version $Revision: $, $Date: $ UTC @@ -12,25 +12,96 @@ package de.fhswf.in.inf.java1.aufgabe7; public final class Simulation { + private static Spieler[] spieler; + + private static Spiel spiel; + + private static int[] spielerProp; + /** - * TODO Add constructor comment here + * Prevents instantiation of the utility class. * */ private Simulation() { - // TODO Auto-generated constructor stub } /** - * TODO Add method comment here + * Initializes everything. + * + */ + private static void aufsetzen() + { + spieler = new Spieler[3]; + + spieler[0] = new GleichSpieler(); + spieler[1] = new WechselSpieler(); + spieler[2] = new Spieler(true, 50); + + spiel = new Spiel(); + + } + + /** + * Makes anzahl games. + * + * @param anzahl + * How often the game will be run. + */ + private static void nDurchlaufeAusfuehren(int anzahl) + { + aufsetzen(); + + boolean[][] erfolgreich = new boolean[spieler.length][anzahl]; + for (int i = 0; i < spieler.length; i++) + { + for (int j = 0; j < anzahl; j++) + { + erfolgreich[i][j] = spiel.spielDurchlauf(spieler[i]); + } + } + + wahrscheinlichkeitErrechnen(erfolgreich); + + } + + /** + * Calculates the success rate of every player. + * + * @param erfolg + * An array with the last game stats. + */ + private static void wahrscheinlichkeitErrechnen(boolean[][] erfolg) + { + spielerProp = new int[erfolg.length]; + for (int i = 0; i < spielerProp.length; i++) + { + spielerProp[i] = 0; + for (int j = 0; j < erfolg[i].length; j++) + { + if (erfolg[i][j]) + { + spielerProp[i]++; + } + } + spielerProp[i] = (int) (((double) spielerProp[i] / erfolg[i].length) * 100); + } + } + + /** + * Main method of the package. * * @param args * Command line arguments */ public static void main(String[] args) { - // TODO Auto-generated method stub - + nDurchlaufeAusfuehren(100000); + for (int i = 0; i < spielerProp.length; i++) + { + System.out.println("Spieler " + spieler[i].getClass().getName() + + ". war " + spielerProp[i] + "% erfolgreich."); + } } } |
