summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java68
1 files changed, 61 insertions, 7 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java b/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java
index 1bc86bb..23f2e7c 100644
--- a/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java
+++ b/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java
@@ -3,23 +3,77 @@
*/
package de.fhswf.in.inf.java1.aufgabe7;
+import java.util.Random;
+
/**
- * TODO Add comment here
+ * Represents a player that chooses a shell.
*
- * @author $Author: $
- * @version $Revision: $, $Date: $ UTC
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
*/
public class Spieler
{
+ private Random rnd = new Random();
+
+ private int ersterTipp = -1;
+
+ private int wahrscheinlichkeit = 0;
+
+ private boolean nutztWechselStrategy = false;
+
+ /**
+ * A player with a certain probability of switching its strategy.
+ *
+ * @param nutztWechselStrategy
+ * Choose initial strategy.
+ * @param wahrscheinlichkeit
+ * The probability of switching strategy.
+ */
+ public Spieler(boolean nutztWechselStrategy, int wahrscheinlichkeit)
+ {
+ if (wahrscheinlichkeit < 0 | wahrscheinlichkeit > 100)
+ {
+ throw new IllegalArgumentException(
+ "Only a probability between 0 and 100 is allowed.");
+ }
+
+ this.wahrscheinlichkeit = wahrscheinlichkeit;
+ this.nutztWechselStrategy = nutztWechselStrategy;
+ }
/**
- * TODO Add constructor comment here
+ * The first shell the player chooses.
*
+ * @return The first guess for a shell
*/
- public Spieler()
+ public int ersterTipp()
{
- // TODO Auto-generated constructor stub
-
+ ersterTipp = rnd.nextInt(Spiel.MAXHUET);
+ return ersterTipp;
+ }
+
+ /**
+ * After the first guess, the player must choose a second shell.
+ *
+ * @param leeresHuetchen
+ * The shell, the game showed as empty
+ * @return The second guess for the right shell
+ */
+ public int zweiterTipp(int leeresHuetchen)
+ {
+ if (rnd.nextInt(100) < wahrscheinlichkeit)
+ {
+ nutztWechselStrategy = !nutztWechselStrategy;
+ }
+
+ if (nutztWechselStrategy)
+ {
+ return Spiel.MAXHUET - ersterTipp - leeresHuetchen;
+ }
+ else
+ {
+ return ersterTipp;
+ }
}
}