-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
234 lines (210 loc) · 5.12 KB
/
Player.java
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import java.util.ArrayList;
public abstract class Player
{
protected Card[] tops;
protected Card[] bottoms;
protected Card[] privateCards;
protected Card[] enemyTops;
protected Card[] enemyBottoms;
protected Card[] enemyPrivateCards;
public int SUR;
public int numHands = 0;
public int numCards = 0;
public Player(Card[] tops, Card[] bottoms, Card[] privates, Card[] enemyTops, Card[] enemyBottoms, Card[] enemyPrivates)
{
this.tops = tops;
this.bottoms = bottoms;
privateCards = privates; //hehe
this.enemyTops = enemyTops;
this.enemyBottoms = enemyBottoms;
enemyPrivateCards = enemyPrivates; //hehe
numCards += tops.length + bottoms.length + privateCards.length;
}
protected void putNone(char c, int index)
{
getAccording(c)[index] = null;
}
protected Card[] getAccording(char c)
{
Card[] selected = null;
switch (c)
{
case 'T' : selected = tops; break;
case 'B' : selected = bottoms; break;
case 'P' : selected = privateCards; break;
}
return selected;
}
// protected char getAbbrev(Card[] arr)
// {
// if (arr == tops) {
// return "T";
// } else if (arr == bottoms) {
// return "B";
// } else if (arr == privateCards) {
// return "P";
// } else {
// return "?";
// }
// }
//moves then cards
public ArrayList[] getAllLegalMoves(Card placedCard)
{
ArrayList<String> moves = new ArrayList<String>();
ArrayList<Card> legalCards = new ArrayList<Card>();
ArrayList<String> suitMoves = null;
ArrayList<Card> suitLegalCards = null;
int playedSuit = -1;
boolean cardPresent = (placedCard != null);
if (cardPresent)
{
playedSuit = placedCard.suit();
suitMoves = new ArrayList<String>();
suitLegalCards = new ArrayList<Card>();
}
for (int i = 0; i < 6; i++)
{
if (tops[i] != null)
{
legalCards.add(tops[i]);
moves.add("T" + i);
if (cardPresent && tops[i].suit() == playedSuit)
{
suitLegalCards.add(tops[i]);
suitMoves.add("T" + i);
}
}
else if (bottoms[i] != null)
{
legalCards.add(bottoms[i]);
moves.add("B" + i);
if (cardPresent && bottoms[i].suit() == playedSuit)
{
suitLegalCards.add(bottoms[i]);
suitMoves.add("B" + i);
}
}
}
for (int i = 0; i < 3; i++)
{
if (privateCards[i] != null)
{
legalCards.add(privateCards[i]);
moves.add("P" + i);
if (cardPresent && privateCards[i].suit() == playedSuit)
{
suitLegalCards.add(privateCards[i]);
suitMoves.add("P" + i);
}
}
}
if (cardPresent && suitMoves.size() > 0)
{
return new ArrayList[] {suitMoves, suitLegalCards};
}
else
{
return new ArrayList[] {moves, legalCards};
}
}
public ArrayList[] getAllLegalMoves2(Card placedCard)
{
ArrayList<Object[]> moves = new ArrayList<Object[]>();
ArrayList<Card> legalCards = new ArrayList<Card>();
ArrayList<Object[]> suitMoves = null;
ArrayList<Card> suitLegalCards = null;
int playedSuit = -1;
boolean cardPresent = (placedCard != null);
if (cardPresent)
{
playedSuit = placedCard.suit();
suitMoves = new ArrayList<Object[]>();
suitLegalCards = new ArrayList<Card>();
}
Object[] mv;
for (int i = 0; i < 6; i++)
{
if (tops[i] != null)
{
legalCards.add(tops[i]);
mv = new Object[] {"T", i};
moves.add(mv);
if (cardPresent && tops[i].suit() == playedSuit)
{
suitLegalCards.add(tops[i]);
suitMoves.add(mv);
}
}
else if (bottoms[i] != null)
{
legalCards.add(bottoms[i]);
mv = new Object[] {"B", i};
moves.add(mv);
if (cardPresent && bottoms[i].suit() == playedSuit)
{
suitLegalCards.add(bottoms[i]);
suitMoves.add(mv);
}
}
if (i < 3 && privateCards[i] != null)
{
legalCards.add(privateCards[i]);
mv = new Object[] {"P", i};
moves.add(mv);
if (cardPresent && privateCards[i].suit() == playedSuit)
{
suitLegalCards.add(privateCards[i]);
suitMoves.add(mv);
}
}
}
if (cardPresent && suitMoves.size() > 0)
{
return new ArrayList[] {suitMoves, suitLegalCards};
}
else
{
return new ArrayList[] {moves, legalCards};
}
}
protected ArrayList<Card> getAllAvailable()
{
ArrayList<Card> availables = new ArrayList<Card>();
for (int i = 0; i < 6; i++)
{
if (tops[i] != null)
{
availables.add(tops[i]);
}
else if (bottoms[i] != null)
{
availables.add(bottoms[i]);
}
}
for (int i = 0; i < 3; i++)
{
if (privateCards[i] != null)
{
availables.add(privateCards[i]);
}
}
return availables;
}
public String toString()
{
String str = "\n\n";
str += "\t\t\t\tTHEM\n\n";
str += "Priv:\t\t\t" + Card.printSet(enemyPrivateCards) + "\t\n\n";
str += "Bots:\t\t" + Card.printSet(enemyBottoms) + "\n";
str += "Tops:\t\t" + Card.printSet(enemyTops) + "\n\n\n";
str += "Tops:\t\t" + Card.printSet(tops) + "\n";
str += "Bots:\t\t" + Card.printSet(bottoms) + "\n\n";
str += "Priv:\t\t\t" + Card.printSet(privateCards) + "\t\n\n";
str += "\t\t\t\tUS\n\n";
return str;
}
//Returns the call of sur
public abstract int getSurCall();
//Returns the chosen move, given that it is legal
public abstract String getMove(Card placedCard);
}