-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.java
More file actions
executable file
·90 lines (81 loc) · 1.5 KB
/
Copy pathHand.java
File metadata and controls
executable file
·90 lines (81 loc) · 1.5 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
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
public class Hand
{
private LinkedList<Card> cardList;
public Hand()
{
this.cardList = new LinkedList<Card>();
}
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append('[');
int i = 0;
for(Card c : this.cardList)
{
if(i != this.cardList.size() - 1)
sb.append(c+", ");
else
sb.append(c);
i++;
}
i = 0;
sb.append("] : [");
for(int value : this.count())
{
if(i != this.count().size() - 1)
sb.append(value+", ");
else
sb.append(value);
i++;
}
return sb.append(']').toString();
}
public void add(Card card)
{
this.cardList.add(card);
}
public void clear()
{
this.cardList.clear();
}
public List<Integer> count()
{
List<Integer> resultat = new ArrayList<Integer>();
resultat.add(0);
for(Card c : this.cardList)
{
int size = resultat.size();
for(int i = 0; i < size; i++)
{
int val = resultat.get(i);
resultat.set(i, val+c.getPoints());
if(c.getPoints() == 1)
resultat.add(val+11);
}
}
return resultat;
}
public int best()
{
List<Integer> resultat = new ArrayList<Integer>();
resultat = this.count();
int bestScore = 0;
for(int score : resultat)
{
if(score > bestScore && score <= 21)
bestScore = score;
}
if(bestScore == 0)
for(int score : resultat)
if(score > bestScore)
bestScore = score;
return bestScore;
}
public List<Card> getCardList()
{
return this.cardList;
}
}