/** * */ 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 { 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; } /** * The first shell the player chooses. * * @return The first guess for a shell */ public int ersterTipp() { 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; } } }