-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
168 lines (122 loc) · 3.29 KB
/
Copy pathPlayer.java
File metadata and controls
168 lines (122 loc) · 3.29 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Alua Zhanuzakova
* az2879
* Player.java simulates a human player of video poker.
*/
import java.util.ArrayList;
public class Player {
private ArrayList<Card> hand; // the player's cards
private double bankroll; // the player's balance
private double bet; // number of tokens player bets
/**
* Instantiates a Player with an empty hand and a bankroll
* with 10 tokens.
*/
public Player(){
hand = new ArrayList<>();
bankroll = 10.0;
bet = -1;
}
/**
* Adds a card to the player's hand
*
* @param c The card being added to the hand
*/
public void addCard(Card c){
// add the card c to the player's hand
hand.add(c);
}
/**
* Removes a card to the player's hand
*
* @param c The card to be removed from the hand
*/
public void removeCard(Card c){
// remove the card c from the player's hand
hand.remove(c);
}
/**
* Subtracts the player's bet from their bankroll
*
* @param amt The number of tokens the player bets
*/
public void bets(double amt){
bet = amt;
bankroll -= amt;
}
/**
* Adds the player's winnings to their bankroll
*
* @param odds The number of tokens won by the player
*/
public void winnings(double odds){
bankroll += odds;
}
/**
* Returns an array of integers where indices 1-4
* represent the 4 different possible suits. The
* value at each index is incremented by 1 for every
* card in the hand that has the corresponding suit.
*
* @return An array representing how many cards of
each suit are present in the hand.
*/
public int[] getSuitCounts() {
// will leave index 0 empty
int[] suitCounts = new int[5];
// for each suit in the hand, increment the
// corresponding index in the counts array by 1
for (Card c : hand) {
suitCounts[c.getSuit()]++;
}
return suitCounts;
}
/**
* Returns an array of integers where indices 1-13
* represent the 13 different possible ranks. The
* value at each index is incremented by 1 for every
* card in the hand that has the corresponding rank.
*
* @return An array representing how many cards of
each rank are present in the hand.
*/
public int[] getRankCounts() {
// will leave index 0 empty
int[] rankCounts = new int[14];
// for each rank in the hand, increment the
// corresponding index in the counts array by 1
for (Card c : hand) {
rankCounts[c.getRank()]++;
}
return rankCounts;
}
/**
* Returns the player's current bankroll
*
* @return Number of tokens in the bankroll
*/
public double getBankroll(){
return bankroll;
}
/**
* Returns the player's current hand
*
* @return The player's hand
*/
public ArrayList<Card> getHand() {
return hand;
}
/**
* Returns a string representation of the hand
*
* @return A string showing the player's hand
*/
public String handToString() {
return hand.toString();
}
/**
* Empties all cards in the player's hand
*/
public void clearHand() {
hand.clear();
}
}