-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganism.java
More file actions
101 lines (93 loc) · 1.92 KB
/
Organism.java
File metadata and controls
101 lines (93 loc) · 1.92 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
public class Organism
{
public String[][] allele;
public int wins;
public Organism()
{
wins = 0;
allele = new String[21][11];
for (int r = 0; r < allele.length; r++)
{
for (int c = 0; c < allele[0].length; c++)
{
int temp = (int)(Math.random()*2) + 1;
if (temp == 1)
{
allele[r][c] = "h";
}
else
{
allele[r][c] = "s";
}
}
}
}
public Organism(String[][] array)
{
allele = array;
}
public void play(Blackjack game, int rounds)
{
while(rounds > 0)
{
String loop = game.result();
while (loop.equals(""))
{
int playerScore = game.getScore(game.getPlayerHand());
int shownDealerScore = game.getShownDealerCard().getRank();
if (shownDealerScore > 11)
shownDealerScore = 10;
String temp = allele[playerScore - 1][shownDealerScore - 1];
if (temp.equals("h"))
{
game.hit();
}
else
{
game.stand();
}
loop = game.result();
}
if (loop.equals("win"))
{
wins++;
}
rounds--;
}
}
public int getWins()
{
return wins;
}
public void resetWins()
{
wins = 0;
}
public Organism copy()
{
String[][] array = new String[allele.length][allele[0].length];
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array[0].length; j++)
{
//chance of mutation
if (Math.random() < 0.06)
array[i][j] = Math.random() < 0.5 ? "h" : "s";
else
array[i][j] = allele[i][j];
}
}
return new Organism(array);
}
public void printStrategy()
{
for (int r = 0; r < allele.length; r++)
{
for (int c = 0; c < allele[0].length; c++)
{
System.out.print(allele[r][c] + ",");
}
System.out.println("");
}
}
}