blob: 23f2e7c7e87fc6a40215765c6672cf5ae508daf7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/**
*
*/
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;
}
}
}
|