summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2014-11-12 14:11:25 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2014-11-12 14:11:25 +0100
commit5a90d8002fc97a027c3d4afd48dc479b5f0b5441 (patch)
tree0ebb81e2c5cd34c767c3cd78965a0d49f687f261 /src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java
parent33a0c5ebe357f817d2e6929dc88a9873bbdc0ee1 (diff)
downloadJava1-5a90d8002fc97a027c3d4afd48dc479b5f0b5441.tar.gz
Java1-5a90d8002fc97a027c3d4afd48dc479b5f0b5441.zip
Assignment No.7 implemented classes
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe7/Simulation.java83
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.");
+ }
}
}