diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-11-12 15:29:01 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-11-12 15:29:01 +0100 |
| commit | 0a17d5dd687ced4dd501097e6d15376ccbb8b281 (patch) | |
| tree | bf378b0ed3842690bf43e2cedd298d68834b55f1 /src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java | |
| parent | 5a90d8002fc97a027c3d4afd48dc479b5f0b5441 (diff) | |
| download | Java1-0a17d5dd687ced4dd501097e6d15376ccbb8b281.tar.gz Java1-0a17d5dd687ced4dd501097e6d15376ccbb8b281.zip | |
Assignment No.7 after correction
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java b/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java index 23f2e7c..40c7254 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java +++ b/src/de/fhswf/in/inf/java1/aufgabe7/Spieler.java @@ -3,52 +3,35 @@ */ package de.fhswf.in.inf.java1.aufgabe7; -import java.util.Random; - /** * Represents a player that chooses a shell. * * @author $Author: $ * @version $Revision: $, $Date: $ UTC */ -public class Spieler +public abstract 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. + * The first shell the player chooses. * - * @param nutztWechselStrategy - * Choose initial strategy. - * @param wahrscheinlichkeit - * The probability of switching strategy. + * @return The first guess for a shell */ - public Spieler(boolean nutztWechselStrategy, int wahrscheinlichkeit) + public final int ersterTipp() { - if (wahrscheinlichkeit < 0 | wahrscheinlichkeit > 100) - { - throw new IllegalArgumentException( - "Only a probability between 0 and 100 is allowed."); - } - - this.wahrscheinlichkeit = wahrscheinlichkeit; - this.nutztWechselStrategy = nutztWechselStrategy; + ersterTipp = Spiel.RAND.nextInt(Spiel.MAXHUET); + return ersterTipp; } /** - * The first shell the player chooses. + * Getter for the first choice. * - * @return The first guess for a shell + * @return The first choice */ - public int ersterTipp() + public final int getErsterTipp() { - ersterTipp = rnd.nextInt(Spiel.MAXHUET); return ersterTipp; } @@ -59,21 +42,6 @@ public class Spieler * 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; - } - } + public abstract int zweiterTipp(int leeresHuetchen); } |
