-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDealer.java
More file actions
40 lines (31 loc) · 1.02 KB
/
Dealer.java
File metadata and controls
40 lines (31 loc) · 1.02 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
package blackjack.domain.gameplayer;
import java.util.List;
public class Dealer extends GamePlayer {
private static final String DEALER = "딜러";
private static final int DEALER_BOUND = 16;
private static final String DealerResult = "%d승 %d패";
public Dealer() {
this(new Name(DEALER));
}
public Dealer(final Name name) {
super(name);
}
@Override
public boolean isLowerThanBound() {
return getScore() <= DEALER_BOUND;
}
@Override
public String getGameResult(List<GamePlayer> players) {
int winCount = 0;
if (isContinue()) {
winCount = findWinCount(getScore(), players);
}
int loseCount = players.size() - winCount;
return String.format(DealerResult, winCount, loseCount);
}
private int findWinCount(int dealerScore, List<GamePlayer> players) {
return (int) players.stream()
.filter(player -> player.isContinue() && player.getScore() < dealerScore)
.count();
}
}