Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42b0ddd
refactor: ๋ถˆํ•„์š”ํ•œ import๋ฌธ ์‚ญ์ œ
haeseonlee Mar 12, 2026
1efb71c
refactor: Player ๋ถˆํ•„์š”ํ•œ ํ•„๋“œ & ๋ฉ”์„œ๋“œ ์‚ญ์ œ
haeseonlee Mar 12, 2026
bfcb4f2
docs: ๋ฐฐํŒ… ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๋ชฉ๋ก ์ž‘์„ฑ
haeseonlee Mar 13, 2026
85f5769
refactor: printDealerCardDrawnResult ์ถœ๋ ฅ ๋ฌธ๊ตฌ ์ˆ˜์ •
haeseonlee Mar 13, 2026
fca8b22
feat: ํ”Œ๋ ˆ์ด์–ด ๋ฐฐํŒ… ๊ธˆ์•ก ์ž…๋ ฅ ๊ธฐ๋Šฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
af2d198
docs: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ชฉ๋ก ์ˆ˜์ •
haeseonlee Mar 13, 2026
1c0939a
refactor: ๋ฐฐํŒ… ๊ธˆ์•ก ์ž…๋ ฅ ํƒ€์ž… ๋ณ€๊ฒฝ
haeseonlee Mar 13, 2026
318db5b
feat: ํ”Œ๋ ˆ์ด์–ด ๋ฐฐํŒ… ๊ธˆ์•ก ์ €์žฅ
haeseonlee Mar 13, 2026
3235007
feat: ๋ฐฐํŒ… ๊ธˆ์•ก ์ž…๋ ฅ๊ฐ’ ๊ฒ€์ฆ
haeseonlee Mar 13, 2026
ebd112a
test: ํ”Œ๋ ˆ์ด์–ด ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ ํ•ฉ์ด 21์ธ์ง€ ํŒ๋‹จํ•˜๋Š” ๋ฉ”์„œ๋“œ ํ…Œ์ŠคํŠธ
haeseonlee Mar 13, 2026
b0cf709
test: ํ”Œ๋ ˆ์ด์–ด ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ ํ•ฉ์ด 21์ด ์•„๋‹Œ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ถ”๊ฐ€
haeseonlee Mar 13, 2026
11bb5f7
feat: ํ”Œ๋ ˆ์ด์–ด ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ ํ•ฉ์ด 21์ธ์ง€ ํŒ๋‹จํ•˜๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
ce7705a
test: ํ”Œ๋ ˆ์ด์–ด ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ ํ•ฉ์ด 21์ด๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก์˜ 1.5๋ฐฐ ์ง€๊ธ‰ ํ…Œ์ŠคํŠธ
haeseonlee Mar 13, 2026
b3e49dc
feat: ํ”Œ๋ ˆ์ด์–ด ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ ํ•ฉ์ด 21์ด๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก์˜ 1.5๋ฐฐ ์ง€๊ธ‰ ๊ธฐ๋Šฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
2e3e0f2
test: ํ”Œ๋ ˆ์ด์–ด ์นด๋“œ ํ•ฉ 21 ๋„˜์–ด๊ฐ€๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก ์žƒ๋Š” ๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
e4824d7
test: ๋”œ๋Ÿฌ ์ดˆ๊ธฐ ์นด๋“œํ•ฉ 21์ด๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก ์žƒ๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ถ”๊ฐ€
haeseonlee Mar 13, 2026
1b492ba
feat: ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ์žƒ๋Š” ๊ฒฝ์šฐ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
9be7e57
docs: ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๊ทธ๋Œ€๋กœ ๋ฐ›๋Š” ๊ฒฝ์šฐ ๋ชฉ๋ก ์ถ”๊ฐ€
haeseonlee Mar 13, 2026
414e765
test: ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ ๋ชจ๋‘ ์ดˆ๊ธฐ ์นด๋“œํ•ฉ 21์ธ ๊ฒฝ์šฐ ๋ฐฐํŒ… ๊ธˆ์•ก ๋Œ๋ ค๋ฐ›๋Š” ๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
081cb1c
feat: ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ ๋ชจ๋‘ ์ดˆ๊ธฐ ์นด๋“œํ•ฉ 21์ธ ๊ฒฝ์šฐ ๋ฐฐํŒ… ๊ธˆ์•ก ๋Œ๋ ค๋ฐ›๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
61ef165
test: ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ๋ณด๋‹ค ์นด๋“œ ์ ์ˆ˜ ํ•ฉ์ด ํฌ๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก ๋Œ๋ ค๋ฐ›๋Š” ๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ
haeseonlee Mar 13, 2026
0f1a896
feat: ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ๋ณด๋‹ค ์นด๋“œ ์ ์ˆ˜ ํ•ฉ์ด ํฌ๋ฉด ๋ฐฐํŒ… ๊ธˆ์•ก ๋Œ๋ ค๋ฐ›๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
9f2eba0
feat: ์ตœ์ข… ์ˆ˜์ต ๊ฒฐ๊ณผ ์ถœ๋ ฅ ๊ตฌํ˜„
haeseonlee Mar 13, 2026
ca323a5
refactor: ์ˆ˜์ต ๊ฒฐ๊ณผ ๊ณ„์‚ฐ ๋ถ„๊ธฐ ๋กœ์ง ๋ฆฌํŒฉํ„ฐ๋ง
haeseonlee Mar 13, 2026
81dbce6
docs: ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋„์–ด์“ฐ๊ธฐ ์ˆ˜์ •
haeseonlee Mar 14, 2026
ca3350e
refactor: Participant ์ด๋ฆ„ String์—์„œ Name ๊ฐ์ฒด๋กœ ๋ณ€๊ฒฝ
haeseonlee Mar 14, 2026
72d918e
refactor: Participant ํด๋ž˜์„œ ๋ฉ”์„œ๋“œ ์œ„์น˜ ์กฐ์ • ๋ฐ ์ƒ์ˆ˜ ์„ค์ •
haeseonlee Mar 14, 2026
9d4143d
refactor: addCard ์ œ์•ฝ ์‚ฌํ•ญ ์„ค์ • ๋ฐ getCardNames stream ์‚ฌ์šฉ ๋ฆฌํŒฉํ„ฐ๋ง
haeseonlee Mar 14, 2026
2d0dfb1
refactor: BlackjackController์˜ calculateFinalScore ๋ฉ”์„œ๋“œ stream ์‚ฌ์šฉ ๋ฆฌํŒฉํ„ฐ๋ง
haeseonlee Mar 14, 2026
7caf5d0
test: BlackjackTest ์ฝ”๋“œ ๋งค์ง๋„˜๋ฒ„ ์ œ๊ฑฐ
haeseonlee Mar 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# java-blackjack

๋ธ”๋ž™์žญ ๋ฏธ์…˜ ์ €์žฅ์†Œ
## ๋ธ”๋ž™์žญ ๋ฏธ์…˜ ์ €์žฅ์†Œ

### ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก
- [x] ์นด๋“œ ์ ์ˆ˜ ๊ณ„์‚ฐ (์ˆซ์ž๋Š” ๊ทธ๋Œ€๋กœ, J,Q,K๋Š” 10์œผ๋กœ ๊ณ„์‚ฐ)
- [x] ์นด๋“œ ํ•ฉ๊ณ„ ๊ณ„์‚ฐ
- [x] Ace ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ
Expand All @@ -27,10 +28,32 @@
- [x] ๋งˆ์ง€๋ง‰ ์ฐธ๊ฐ€์ž๊ฐ€ ๋ฒ„์ŠคํŠธ๊ฐ€ ๋˜๊ฑฐ๋‚˜ ์นด๋“œ๋ฅผ ์•ˆ๋ฐ›์„ ๊ฒฝ์šฐ ๊ฒŒ์ž„ ์ข…๋ฃŒ
- [x] ์ „์ฒด ํ”Œ๋ ˆ์ด์–ด ์ŠนํŒจ ๊ฒฐ๊ณผ ๊ณ„์‚ฐ

-[x] ์ž…๋ ฅ
- [x] ์ž…๋ ฅ
- [x] ๊ฒŒ์ž„ ์ฐธ๊ฐ€์ž ์ด๋ฆ„ ์ž…๋ ฅ
- [x] ์นด๋“œ ๋”๋ฐ›๊ธฐ ์œ ๋ฌด ์ž…๋ ฅ

- [x] ์ถœ๋ ฅ
- [x] ๋ถ„๋ฐฐ ๋ฐ›์€ ์นด๋“œ ๋ชฉ๋ก ์ถœ๋ ฅ
- [x] ๋”œ๋Ÿฌ์™€ ์ฐธ๊ฐ€์ž ์นด๋“œ ํ•ฉ๊ณ„ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
- [x] ์ตœ์ข… ์ŠนํŒจ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
- [x] ์ตœ์ข… ์ŠนํŒจ ๊ฒฐ๊ณผ ์ถœ๋ ฅ

### ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ชฉ๋ก
- [x] ์ž…๋ ฅ
- [x] ์ฐธ์—ฌํ•˜๋Š” Player์˜ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

- [x] ๋ฐฐํŒ… ๊ธˆ์•ก
- [x] ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ๋Š” ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๊ฐ€์ง„๋‹ค.

- [x] Player & Dealer ๋ธ”๋ž™์žญ ํŒ๋‹จ
- [x] ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ์˜ ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ์˜ ํ•ฉ์ด 21์ธ์ง€ ํŒ๋‹จํ•œ๋‹ค.
- [x] ํ”Œ๋ ˆ์ด์–ด์—๊ฒŒ 1.5๋ฐฐ ์ง€๊ธ‰ํ•˜๋Š” ๊ฒ…์šฐ
- [x] ํ”Œ๋ ˆ์ด์–ด์˜ ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ์ด 21์ธ ๊ฒฝ์šฐ
- [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋ชจ๋‘ ์žƒ๋Š” ๊ฒฝ์šฐ
- [x] ๋”œ๋Ÿฌ์˜ ์ดˆ๊ธฐ ์นด๋“œ 2์žฅ์ด 21์ธ ๊ฒฝ์šฐ
- [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฒ„์ŠคํŠธ์ธ ๊ฒฝ์šฐ
- [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฐฐํŒ…ํ•œ ๊ธˆ์•ก์„ ๊ทธ๋Œ€๋กœ ๋ฐ›๋Š” ๊ฒฝ์šฐ
- [x] ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด ๋ชจ๋‘ ์ดˆ๊ธฐ ์นด๋“œ ํ•ฉ์ด 21์ธ ๊ฒฝ์šฐ
- [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์นด๋“œ๋ฅผ ๊ณ„์† ๋ฝ‘์•„์„œ ๋”œ๋Ÿฌ๋ณด๋‹ค ์นด๋“œ ํ•ฉ์ด ๋†’์€ ๊ฒฝ์šฐ

- [x] ์ถœ๋ ฅ
- [x] ๋”œ๋Ÿฌ์™€ ์ฐธ๊ฐ€์ž์˜ ์ตœ์ข… ์ˆ˜์ต์„ ์ถœ๋ ฅํ•œ๋‹ค.
50 changes: 25 additions & 25 deletions src/main/java/blackjack/controller/BlackjackController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import blackjack.view.InputView;
import blackjack.view.OutputView;
Expand All @@ -23,27 +23,28 @@ public BlackjackController(CardDistributor cardDistributor) {

public void startGame() {
List<String> playerNames = getPlayerNames();
List<Participant> players = getPlayers(playerNames);

List<Participant> players = createPlayers(playerNames);
Participant dealer = Participant.createDealer();

setupInitialHand(players, dealer, playerNames);
processPlayersTurn(players);
playDealerTurn(dealer);

calculateFinalScore(players, dealer);
calculateFinalGameResult(players, dealer);
calculateFinalGameProfit(players, dealer);
}

private static List<String> getPlayerNames() {
String playerNamesStr = InputView.askPlayerNames();
return InputParser.splitPlayerNames(playerNamesStr);
private List<String> getPlayerNames() {
String names = InputView.askPlayerNames();
return InputParser.splitPlayerNames(names);
}

private List<Participant> getPlayers(List<String> playerNames) {
private List<Participant> createPlayers(List<String> playerNames) {
List<Participant> players = new ArrayList<>();
for (String playerName : playerNames) {
players.add(Participant.createPlayer(playerName));
String amountStr = InputView.askPlayerBettingAmount(playerName);
int amount = InputParser.convertNumber(amountStr);
players.add(Participant.createPlayer(playerName, new Money(amount)));
}
return players;
}
Expand Down Expand Up @@ -78,7 +79,9 @@ private void drawUntilPlayerStand(Participant player) {

private void playDealerTurn(Participant dealer) {
int additionalCount = game.dealerDrawsCardsUntilDone(dealer);
OutputView.printDealerCardDrawnResult(additionalCount);
if (additionalCount > 0) {
OutputView.printDealerCardDrawnResult(additionalCount);
}
}

private boolean isHit(Participant player) {
Expand All @@ -93,26 +96,23 @@ private boolean isHit(Participant player) {
}

private void calculateFinalScore(List<Participant> players, Participant dealer) {
List<ParticipantResult> playerResults = new ArrayList<>();
for (Participant player : players) {
ParticipantResult participantResult = new ParticipantResult(player.getName(), player.getCardNames(), player.calculateTotalScore());
playerResults.add(participantResult);
}
List<ParticipantResult> playerResults = players.stream()
.map(player -> new ParticipantResult(player.getName(), player.getCardNames(), player.calculateTotalScore()))
.collect(Collectors.toList());

ParticipantResult dealerResult = new ParticipantResult(dealer.getName(), dealer.getCardNames(), dealer.calculateTotalScore());
OutputView.printFinalCardScores(playerResults, dealerResult);
}

private void calculateFinalGameResult(List<Participant> players, Participant dealer) {
GameResult gameResult = dealer.judgeResult(players, dealer);
Map<ScoreCompareResult, Integer> dealerResult = gameResult.dealerResult();
Map<Participant, ScoreCompareResult> playerResult = gameResult.playerResults();
HashMap<String, ScoreCompareResult> playerNameResult = new HashMap<>();

for (Entry<Participant, ScoreCompareResult> entry : playerResult.entrySet()) {
playerNameResult.put(entry.getKey().getName(), entry.getValue());
public void calculateFinalGameProfit(List<Participant> players, Participant dealer) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateFinalGameProfit์ด public์œผ๋กœ ์„ ์–ธ๋˜์–ด ์žˆ๋„ค์š”~

๊ทธ๋ฆฌ๊ณ  HashMap์„ playersProfit์˜ ๊ตฌ์ฒด ํƒ€์ž…์œผ๋กœ ์„ ์–ธํ•˜๊ณ  ์žˆ๋Š”๋ฐ, Map ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ๊ณผ ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ์„๊นŒ์š”?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„๋„ private์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ๋Š”์ค„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.. ์ฃผ์˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

playersProfit์˜ ํƒ€์ž…๋„ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ ์–ธํ•˜๋„๋ก ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค. Map ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‚˜์ค‘์— ๊ตฌํ˜„์ฒด๋ฅผ ๋ฐ”๊พธ๋”๋ผ๋„ ์‹ค์ œ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋Š” ๊ณ ์น  ํ•„์š”๊ฐ€ ์—†์–ด์„œ ํ›จ์”ฌ ์œ ์—ฐํ•˜๋‹ค๋Š” ์ ์„ ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™œ์šฉํ•˜๋Š” ์ด์œ ๋ฅผ ๋‹ค์‹œ ํ•œ๋ฒˆ ์ƒ๊ฐํ•ด๋ณด๊ฒŒ ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

HashMap<String, Integer> playersProfit = new HashMap<>();
int totalPlayerProfit = 0;
for (Participant player : players) {
int profit = player.calculateFinalProfit(dealer);
playersProfit.put(player.getName(), profit);
totalPlayerProfit += profit;
}
OutputView.printFinalResult(dealerResult, playerNameResult);
int dealerProfit = -totalPlayerProfit;
OutputView.printFinalProfit(dealerProfit, playersProfit);
}

}
24 changes: 15 additions & 9 deletions src/main/java/blackjack/domain/Cards.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Cards {
private static final int BLACKJACK_SCORE = 21;
private static final int ACE_SCORE = 10;

private final List<Card> cards;

Expand All @@ -21,24 +24,27 @@ public int sumScore() {
totalScore += card.getScore();
}
int aceCount = (int) cards.stream().filter(Card::isAce).count();

while (totalScore > 21 && aceCount > 0) {
totalScore -= 10;
while (totalScore > BLACKJACK_SCORE && aceCount > 0) {
totalScore -= ACE_SCORE;
aceCount--;
}
return totalScore;
}

public void addCard(Card card) {
if (card == null || sumScore() > BLACKJACK_SCORE) {
throw new IllegalArgumentException("[ERROR] ์นด๋“œ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
cards.add(card);
}

public List<String> getCardNames() {
List<String> cardNames = new ArrayList<>();
for (Card card : cards) {
String cardName = card.getCardName();
cardNames.add(cardName);
}
return cardNames;
return cards.stream()
.map(Card::getCardName)
.collect(Collectors.toList());
}

public int getSize() {
return cards.size();
}
}
14 changes: 14 additions & 0 deletions src/main/java/blackjack/domain/Money.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package blackjack.domain;

public class Money {

private final int bettingMoney;

public Money(int bettingMoney) {
this.bettingMoney = bettingMoney;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Money์— ๊ฒ€์ฆ ๋กœ์ง์ด ์—†์–ด์„œ ์Œ์ˆ˜๋‚˜ 0์›์œผ๋กœ๋„ ๋ฐฐํŒ…์ด ๊ฐ€๋Šฅํ•œ ์ƒํƒœ์ธ๋ฐ์š”. ๊ฐ’ ๊ฐ์ฒด๋กœ์„œ ์ž๊ธฐ ์ž์‹ ์˜ ์œ ํšจ์„ฑ์„ ๋ณด์žฅํ•ด์ฃผ๋Š” ๊ฒŒ ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๋ฐฐํŒ… ๊ธˆ์•ก์ด int ํƒ€์ž…์ธ๋ฐ, 21์–ต์„ ๋„˜๋Š” ๊ธˆ์•ก์ด ์ž…๋ ฅ๋˜๋ฉด Integer.parseInt์—์„œ NumberFormatException์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด์š”. long ํƒ€์ž…๋„ ๊ณ ๋ คํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Money ํด๋ž˜์Šค์— 0์ด๋‚˜ ์Œ์ˆ˜๊ฐ€ ์ž…๋ ฅ๋  ๊ฒฝ์šฐ ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!

๋ฒ ํŒ… ๊ธˆ์•ก์€ ์–ต ๋‹จ์œ„๋ฅผ ๋„˜์–ด๊ฐˆ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ์ ์„ ๊ณ ๋ คํ•˜์ง€ ๋ชปํ•˜๊ณ  int ํƒ€์ž…์„ ์‚ฌ์šฉํ–ˆ์—ˆ๋Š”๋ฐ, ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ˜์˜ํ•˜์—ฌ ๋” ํฐ ๊ธˆ์•ก๋„ ์ˆ˜์šฉ ๊ฐ€๋Šฅํ•œ long ํƒ€์ž…์œผ๋กœ ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

}

public int getBettingMoney() {
return bettingMoney;
}
}
20 changes: 20 additions & 0 deletions src/main/java/blackjack/domain/Name.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package blackjack.domain;

public class Name {
private final String name;

public Name(String name) {
validate(name);
this.name = name;
}

private void validate(String name) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("[ERROR] ์ด๋ฆ„์„ ์ •ํ™•ํ•˜๊ฒŒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.");
}
}

public String getName() {
return name;
}
}
41 changes: 26 additions & 15 deletions src/main/java/blackjack/domain/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@

public abstract class Participant {

protected final String name;
private static final int BLACKJACK_SCORE = 21;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLACKJACK_SCORE์™€ BLACKJACK_SIZE๊ฐ€ Participant์™€ Cards ์–‘์ชฝ์— ์ค‘๋ณต์œผ๋กœ ์„ ์–ธ๋˜์–ด ์žˆ๋Š”๋ฐ์š”. ์ด์ „์— ์ƒ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ์˜๋ฏธ๋ฅผ ์ž˜ ๋“œ๋Ÿฌ๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ณณ์— ์œ„์น˜ํ•˜๋Š” ๊ฒŒ ์‘์ง‘๋„๋ฅผ ๋†’์ด๋Š” ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ์ด์•ผ๊ธฐ ๋‚˜๋ˆด์—ˆ๋Š”๋ฐ์š”~

๋ธ”๋ž™์žญ ์ ์ˆ˜ 21์ด๋ผ๋Š” ๊ฐœ๋…์€ ์นด๋“œ ํ•ฉ๊ณ„๋ฅผ ๋‹ค๋ฃจ๋Š” Cards๊ฐ€ ๊ฐ€์žฅ ์ž˜ ์•Œ๊ณ  ์žˆ๋Š” ๊ฐ’์ด ์•„๋‹๊นŒ์š”? ํ•œ์ชฝ์—์„œ ๊ด€๋ฆฌํ•˜๊ณ  ํ•„์š”ํ•œ ๊ณณ์—์„œ๋Š” ๋ฉ”์„œ๋“œ, ํ˜น์€ ๋ณ€์ˆ˜ ์ฐธ์กฐ๋ฅผ ํ†ตํ•ด ๋ฌผ์–ด๋ณด๋Š” ๋ฐฉ์‹์„ ๊ณ ๋ คํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

private static final int BLACKJACK_SIZE = 2;

protected final Name name;
protected final Cards drawnCards;

protected Participant(String name) {
this.name = name;
this.name = new Name(name);
this.drawnCards = new Cards();
}

public String getName() {
return name;
}

public boolean isDealerNotDone() {
return false;
}

public static Participant createPlayer(String name) {
return new Player(name);
public static Participant createPlayer(String name, Money money) {
return new Player(name, money);
}

public static Participant createDealer() {
Expand All @@ -33,19 +28,35 @@ public void receiveOneCard(Card card) {
drawnCards.addCard(card);
}

public List<String> getCardNames() {
return drawnCards.getCardNames();
public boolean isDealerNotDone() {
return false;
}

public boolean isBust() {
return drawnCards.sumScore() > 21;
return drawnCards.sumScore() > BLACKJACK_SCORE;
}

public boolean isBlackjack() {
return drawnCards.sumScore() == BLACKJACK_SCORE && drawnCards.getSize() == BLACKJACK_SIZE;
}

public int calculateTotalScore() {
return drawnCards.sumScore();
}

public int calculateFinalProfit(Participant dealer) {
return 0;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateFinalProfit์ด ์ถ”์ƒ ํด๋ž˜์Šค์—์„œ ๊ธฐ๋ณธ๊ฐ’ 0์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”. ์ด๊ฑด ์˜๋„ํ•˜์‹  ๊ฑด๊ฐ€์š”? ๊ผญ ์ด๋ž˜์•ผ๋งŒ ํ•˜๋Š”๊ฑธ๊นŒ์š”?

์ถ”์ƒ ํด๋ž˜์Šค์— ๊ธฐ๋ณธ ๊ตฌํ˜„์„ ๋‘๋ฉด ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ์˜ค๋ฒ„๋ผ์ด๋“œ๋ฅผ ๊นœ๋นกํ•ด๋„ ์ปดํŒŒ์ผ ์—๋Ÿฌ๊ฐ€ ๋‚˜์ง€ ์•Š์•„์„œ ์‹ค์ˆ˜๋ฅผ ์žก๊ธฐ ์–ด๋ ค์›Œ์งˆ ์ˆ˜ ์žˆ์–ด์š”. judgeResult๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ธ๋ฐ์š”, ๋นˆ HashMap์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ธฐ๋ณธ ๊ตฌํ˜„์ด ์žˆ์œผ๋ฉด ์˜ค๋ฒ„๋ผ์ด๋“œ๋ฅผ ๋น ๋œจ๋ ค๋„ ์กฐ์šฉํžˆ ๋„˜์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ๋ฉ”์„œ๋“œ๋กœ ์ œ๊ณตํ•ด์•ผํ• ๋•Œ์™€ ์ถ”์ƒ๋ฉ”์„œ๋“œ๋กœ ์ œ๊ณตํ•ด์•ผํ• ๋•Œ๋ฅผ ์–ด๋–ป๊ฒŒ ๊ตฌ๋ถ„ํ•˜์…จ๋‚˜์š”?


public GameResult judgeResult(List<Participant> players, Participant dealer) {
return new GameResult(new HashMap<>(), new HashMap<>());
}

public String getName() {
return name.getName();
}

public List<String> getCardNames() {
return drawnCards.getCardNames();
}
}
21 changes: 16 additions & 5 deletions src/main/java/blackjack/domain/Player.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package blackjack.domain;

public class Player extends Participant {
private final String name;

public Player(String name) {
private final Money money;

public Player(String name, Money money) {
super(name);
this.name = name;
this.money = money;
}

public String getName() {
return name;
@Override
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฆฌ๋ทฐ ์š”์ฒญ ์ฃผ์‹  ๋‘ ๋ฒˆ์งธ ์งˆ๋ฌธ์— ๋Œ€ํ•œ ์˜๊ฒฌ์ธ๋ฐ์š”, ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ž์‹ ์˜ ์ˆ˜์ต์„ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ ์ž์ฒด๋Š” ๋‚˜์˜์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ์ž๊ธฐ ์นด๋“œ ์ƒํƒœ๋„ ์•Œ๊ณ  ์žˆ์œผ๋‹ˆ๊นŒ์š”.

๋‹ค๋งŒ ์ง€๊ธˆ ๊ตฌ์กฐ์—์„œ๋Š” dealer๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์•„์„œ ๋”œ๋Ÿฌ์˜ ์ƒํƒœ๋ฅผ ์ง์ ‘ ์กฐํšŒํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”. ์ด๋Ÿฌ๋ฉด ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋”œ๋Ÿฌ์˜ ๋‚ด๋ถ€ ์ƒํƒœ(๋ธ”๋ž™์žญ ์—ฌ๋ถ€, ๋ฒ„์ŠคํŠธ ์—ฌ๋ถ€, ์ ์ˆ˜)๋ฅผ ๋„ˆ๋ฌด ๋งŽ์ด ์•Œ์•„์•ผ ํ•˜๋Š” ๊ตฌ์กฐ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

๋ฐ˜๋Œ€๋กœ ๋”œ๋Ÿฌ์—๊ฒŒ "์ด ํ”Œ๋ ˆ์ด์–ด์™€ ๋น„๊ตํ•ด์„œ ๊ฒฐ๊ณผ๋ฅผ ์•Œ๋ ค์ค˜"๋ผ๊ณ  ๋ฌผ์–ด๋ณด๊ณ , ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ˆ˜์ต์„ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ์‹์€ ์–ด๋–จ๊นŒ์š”? ์ด์ „ ๋‹จ๊ณ„์—์„œ dealer.judgeResult๋กœ ์ŠนํŒจ๋ฅผ ํŒ์ •ํ•˜๋Š” ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด๋‘์…จ๋Š”๋ฐ, ์ด๊ฑธ ํ™œ์šฉํ•ด๋ณผ ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์•„์š”~

public int calculateFinalProfit(Participant dealer) {
if (isBlackjack() && dealer.isBlackjack()) {
return money.getBettingMoney();
}
if (isBlackjack()) {
return (int) (money.getBettingMoney() * 1.5);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด์ „๋‹จ๊ณ„์—์„œ ๋ฆฌ๋ทฐ๋ฅผ ์•ˆ๋“œ๋ ธ์—ˆ๋‚˜ ์‹ถ์€๋ฐ์š”
(int) (money.getBettingMoney() * 1.5) ์—์„œ 1.5๋ผ๋Š” ๋งค์ง ๋„˜๋ฒ„๊ฐ€ ๋“ฑ์žฅํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”. ๋ธ”๋ž™์žญ ๋ฐฐ๋‹น๋ฅ ์ด๋ผ๋Š” ๋„๋ฉ”์ธ ์˜๋ฏธ๋ฅผ ๋‹ด์€ ์ƒ์ˆ˜๋กœ ํ‘œํ˜„ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

๊ทธ๋ฆฌ๊ณ  ์ˆ˜์ต ๊ณ„์‚ฐ์„ Money๊ฐ€ ์•„๋‹Œ int๋กœ ์ง์ ‘ ๋‹ค๋ฃจ๊ณ  ์žˆ๋Š”๋ฐ, Money ๊ฐ์ฒด์—๊ฒŒ ๊ณฑ์…ˆ์ด๋‚˜ ๋ถ€ํ˜ธ ๋ฐ˜์ „ ๊ฐ™์€ ์—ฐ์‚ฐ์„ ๋งก๊ฒจ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? ์ง€๊ธˆ์€ Money๊ฐ€ ๋‹จ์ˆœ getter๋งŒ ์ œ๊ณตํ•˜๊ณ  ์žˆ์–ด์„œ ์›์‹œ๊ฐ’ ํฌ์žฅ์˜ ์ด์ ์„ ์ถฉ๋ถ„ํžˆ ์‚ด๋ฆฌ์ง€ ๋ชปํ•˜๊ณ  ์žˆ๋Š”๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งค์ง ๋„˜๋ฒ„ ์ƒ์ˆ˜ํ™”๋Š” ์ด์ „ ๋ฆฌ๋ทฐ์—์„œ ํ™•์ธ ํ›„ ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•˜์˜€๋Š”๋ฐ, ์ด ์ˆซ์ž๋Š” ์ œ๊ฐ€ ๋†“์นœ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค... ์ด ๋ถ€๋ถ„๋„ ์ƒ์ˆ˜ํ™”ํ•˜์—ฌ ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค!

์ €๋„ Money ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ๋‹จ์ˆœํžˆ ๊ฐ’๋งŒ ๋‹ด๊ณ  ์žˆ๋‹ค ๋ณด๋‹ˆ ๊ตณ์ด ํ•„์š”ํ•œ ํด๋ž˜์Šค์ผ๊นŒ ์ƒ๊ฐํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ˜์˜ํ•ด์„œ Money ๊ฐ์ฒด ์•ˆ์—์„œ ๊ณฑ์…ˆ์ด๋‚˜ ๋ถ€ํ˜ธ ๋ฐ˜์ „ ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๋ฒ ํŒ… ๊ฒฐ๊ณผ ๊ธˆ์•ก๋„ Money ๊ฐ์ฒด๋กœ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋ฆฌํŒฉํ„ฐ๋งํ–ˆ์Šต๋‹ˆ๋‹ค.

}
if (isBust() || dealer.isBlackjack() || (calculateTotalScore() < dealer.calculateTotalScore() && !dealer.isBust())) {
return -money.getBettingMoney();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์กฐ๊ฑด์ด ํ•œ ์ค„์— ๋„ˆ๋ฌด ๋งŽ์€ ํŒ๋‹จ์„ ๋‹ด๊ณ  ์žˆ์–ด์„œ ์ฝ๊ธฐ๊ฐ€ ์‰ฝ์ง€ ์•Š์€๊ฒƒ ๊ฐ™์•„์š”. ๋ณ€๊ฒฝ๊ณผ ํ™•์žฅ์— ์œ ๋ฆฌํ•œ ๊ตฌ์กฐ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—†์„๊นŒ์š”?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ณต์žกํ•œ ์กฐ๊ฑด๋ฌธ์„ ์กฐ๊ธˆ ๋” ๊ฐ€๋…์„ฑ์žˆ๊ฒŒ ๋ถ„๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค!

ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฒ ํŒ… ๊ธˆ์•ก์„ ๋Œ๋ ค๋ฐ›๋Š” ๊ฒฝ์šฐ, 1.5๋ฐฐ์˜ ์ˆ˜์ต์„ ์–ป๋Š” ๊ฒฝ์šฐ, ๋ฒ ํŒ… ๊ธˆ์•ก์„ ์žƒ๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฐ๊ฐ ๋ถ„๋ฆฌํ•˜์—ฌ ํ•˜๋‚˜์˜ ์กฐ๊ฑด๋ฌธ์ด ๋„ˆ๋ฌด ๋งŽ์€ ํŒ๋‹จ์„ ๋‹ด์ง€ ์•Š๋„๋ก ๋ฆฌํŒฉํ„ฐ๋ง ํ–ˆ์Šต๋‹ˆ๋‹ค.

}
return money.getBettingMoney();
}
}
5 changes: 0 additions & 5 deletions src/main/java/blackjack/service/Game.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package blackjack.service;

import blackjack.domain.*;
import blackjack.view.InputView;
import blackjack.view.OutputView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Game {

Expand Down
1 change: 0 additions & 1 deletion src/main/java/blackjack/service/RandomCardPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomCardPicker implements CardPicker {
private final NumberGenerator numberGenerator;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/blackjack/utils/InputParser.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package blackjack.utils;

import java.util.List;
import java.util.stream.Stream;

public class InputParser {

public static List<String> splitPlayerNames(String input) {
if (input == null || input.trim().isEmpty()) {
throw new IllegalArgumentException("[ERROR] ํ”Œ๋ ˆ์ด์–ด ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.");
throw new IllegalArgumentException("[ERROR] ์ด๋ฆ„์„ ์ •ํ™•ํ•˜๊ฒŒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.");
}
String[] names = input.split(",");
for (String name : names) {
validateNameEmpty(name);
}
return List.of(names).stream()
return Stream.of(names)
.map(String::trim)
.toList();
}

private static void validateNameEmpty(String name) {
if (name.trim().isEmpty()) {
throw new IllegalArgumentException("[ERROR] ํ”Œ๋ ˆ์ด์–ด ์ด๋ฆ„์€ ๊ณต๋ฐฑ์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
public static int convertNumber(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("[ERROR] ์ˆซ์ž ์ด์™ธ์˜ ๊ฐ’์€ ์ž…๋ ฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/blackjack/view/InputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public static String askHitOrStand(String playerName) {
System.out.printf(ASK_HIT_OR_STAND, playerName);
return scanner.nextLine();
}

public static String askPlayerBettingAmount(String playerName) {
System.out.printf("%n%s์˜ ๋ฐฐํŒ… ๊ธˆ์•ก์€?%n", playerName);
return scanner.nextLine();
}
}
Loading