-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฐฐํ )] ๋ฌ์ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soohyun1904
wants to merge
23
commits into
woowacourse:soohyun1904
Choose a base branch
from
soohyun1904:step2
base: soohyun1904
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4ac5d7e
test: ํ
์คํธ ํฌํผ ๋์
๋ฐ ๋
๋ฆฝ์ฑ ๊ฐ์
soohyun1904 0892bb1
refactor: ๋๋ฉ์ธ ์ฑ
์ ๋ถ๋ฆฌ ๋ฐ ์บก์ํ ๊ฐ์
soohyun1904 dd583b7
test: ๋๋ฉ์ธ ๋ฉ์๋ ๋ช
์์ ์ผ๋ก ์ธํ ์์
soohyun1904 cc021f7
refactor: Dealer์ Player ๊ณต๋๋ก์ง ๋ถ๋ฆฌ
soohyun1904 ee94a94
refactor: ์ปจํธ๋กค๋ฌ๊ณผ ๋๋ฉ์ธ ๊ฒฐํฉ๋ ์ ๊ฑฐ
soohyun1904 af30a63
feat: ์์ต ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 00cb413
test: ์์ต ๊ธฐ๋ฅ ํ
์คํธ ์ถ๊ฐ
soohyun1904 0086a19
refactor: BlackjackGame ๋๋ฉ์ธ ์์
soohyun1904 551af63
test: BlackjackGame ํ
์คํธ ์ถ๊ฐ
soohyun1904 85b4915
refactor: View ๊ฐ์ฒด์ static ๋ฉ์๋๋ฅผ ์ธ์คํด์ค ๋ฉ์๋๋ก ๋ณ๊ฒฝ
soohyun1904 c380883
feat: AppConfig ์ถ๊ฐ๋ก ๊ฐ์ฒด ์์ฑ๊ณผ ์์กด์ฑ ์กฐ๋ฆฝ ๋ถ๋ฆฌ
soohyun1904 0fda59f
feat: StringUtils ์ ํธ ํด๋์ค ์ถ๊ฐ
soohyun1904 a044615
feat: ์ถ๋ ฅ ๋๋ฝ ์ถ๊ฐ
soohyun1904 afb261e
refactor: AppConfig ๋ถํ์ํ ๋ฉ์๋ ์ ๊ฑฐ
soohyun1904 a7f4d17
refactor: BlackjackGame ๋ถํ์ํ ๋ฉ์๋ ์ ๊ฑฐ
soohyun1904 a2cd51d
refactor: ๋ฏธ์ฌ์ฉ ๋ฉ์๋ ์ญ์ ๋ฐ ๋ฉ์๋๋ช
์์
soohyun1904 71e1006
refactor: TrumpCard CARDS ์์ ์์
soohyun1904 1a064a0
refactor: ๋๋ฌ ์ฒซ ์นด๋ ๊ณต๊ฐ ๋ก์ง์ Dealer ๋๋ฉ์ธ์ผ๋ก ์ด๋
soohyun1904 de1afb6
fix: ๋ธ๋์ญ ํ๋จ ๋ก์ง ์์
soohyun1904 2001f0e
test: TrumpCard ALL_CARD ์์ ์ผ๋ก ์ธํ ํ
์คํธ ์์
soohyun1904 1fda9e3
refactor: Bet ์ธ์คํด์ค ๋ณ์ int -> BigDecimal๋ก ์์
soohyun1904 92e61ec
test: Bet ์ธ์คํด์ ๋ณ์ ์์ ์ผ๋ก ์ธํ ํ
์คํธ ์์
soohyun1904 0049204
refactor: Deck์์ ์นด๋๊ฐ ์์๋ ์์ธ์ฒ๋ฆฌ ์์
soohyun1904 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.config.AppConfig; | ||
| import blackjack.controller.BlackjackController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| BlackjackController blackjackController = new BlackjackController(); | ||
| AppConfig config = new AppConfig(); | ||
| BlackjackController blackjackController = config.blackjackController(); | ||
| blackjackController.run(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package blackjack.config; | ||
|
|
||
| import blackjack.controller.BlackjackController; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| public class AppConfig { | ||
| public BlackjackController blackjackController(){ | ||
| return new BlackjackController(new InputView(), new OutputView()); | ||
| } | ||
| } | ||
97 changes: 36 additions & 61 deletions
97
src/main/java/blackjack/controller/BlackjackController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,85 +1,60 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import blackjack.domain.MatchResult; | ||
| import blackjack.domain.Player; | ||
| import blackjack.domain.BlackjackGame; | ||
| import blackjack.domain.vo.GameResult; | ||
| import blackjack.dto.DealResultDto; | ||
| import blackjack.dto.GameResultDto; | ||
| import blackjack.dto.PlayerHandDto; | ||
| import blackjack.domain.BlackjackGame; | ||
| import blackjack.util.Parser; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static blackjack.util.Parser.splitDelimiter; | ||
| import static blackjack.view.InputView.readPlayNames; | ||
| import static blackjack.view.InputView.readYesOrNo; | ||
| import static blackjack.view.OutputView.printCurrentPlayerHand; | ||
| import static blackjack.view.OutputView.printDealResult; | ||
| import static blackjack.view.OutputView.printDealerDrawMessage; | ||
| import static blackjack.view.OutputView.printEmptyLine; | ||
| import static blackjack.view.OutputView.printFinalResult; | ||
| import static blackjack.view.OutputView.printGameResult; | ||
|
|
||
| public class BlackjackController { | ||
| public void run() { | ||
| List<String> names = inputNames(); | ||
| BlackjackGame blackjackGame = BlackjackGame.create(names, Collections::shuffle); | ||
|
|
||
| DealResultDto dealResultDto = deal(blackjackGame); | ||
| printDealResult(dealResultDto); | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| playPlayerTurn(blackjackGame); | ||
| playDealerTurn(blackjackGame); | ||
|
|
||
| GameResultDto gameResultDto = blackjackGame.generateGameResult(); | ||
| printGameResult(gameResultDto); | ||
|
|
||
| Map<Player, MatchResult> playerFinalResult = blackjackGame.getPlayerFinalResult(); | ||
| Map<String, Long> dealerFinalResult = blackjackGame.getDealerFinalResult(playerFinalResult); | ||
| printFinalResult(playerFinalResult, dealerFinalResult); | ||
| public BlackjackController(InputView inputView, OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| private List<String> inputNames() { | ||
| String input = readPlayNames(); | ||
| Parser.notEmpty(input); | ||
| return splitDelimiter(input); | ||
| } | ||
| public void run() { | ||
| List<String> names = inputNames(); | ||
| outputView.printEmptyLine(); | ||
| BlackjackGame game = BlackjackGame.create(names, Collections::shuffle); | ||
|
|
||
| private DealResultDto deal(BlackjackGame blackjackGame) { | ||
| blackjackGame.deal(); | ||
| return DealResultDto.from(blackjackGame.getPlayers(), blackjackGame.getDealer()); | ||
| } | ||
| game.betPlayers(name -> { | ||
| String amount = inputView.readBetAmount(name); | ||
| outputView.printEmptyLine(); | ||
| return amount; | ||
| }); | ||
|
|
||
| private void playPlayerTurn(BlackjackGame blackjackGame) { | ||
| for (int i = 0; i < blackjackGame.playerCount(); i++) { | ||
| playTurn(blackjackGame, i); | ||
| } | ||
| } | ||
| game.deal(); | ||
| outputView.printDealResult(DealResultDto.from(game)); | ||
|
|
||
| private void playTurn(BlackjackGame blackjackGame, int index) { | ||
| while (blackjackGame.canPlayerHit(index) && wantsToHit(blackjackGame, index)) { | ||
| hitAndPrintHand(blackjackGame, index); | ||
| } | ||
| printEmptyLine(); | ||
| } | ||
| game.playPlayerTurns( | ||
| name -> Parser.parseDrawInput(inputView.readYesOrNo(name)).isHit(), | ||
| outputView::printPlayerHand | ||
| ); | ||
| outputView.printEmptyLine(); | ||
|
|
||
| private boolean wantsToHit(BlackjackGame blackjackGame, int index) { | ||
| String answer = readYesOrNo(blackjackGame.playerNameByIndex(index)); | ||
| DrawCommand drawCommand = Parser.parseDrawInput(answer); | ||
| return drawCommand.isHit(); | ||
| } | ||
| game.playDealerTurn(); | ||
| outputView.printDealerDrawMessage(); | ||
|
|
||
| outputView.printGameResult(GameResultDto.from(game)); | ||
|
|
||
| private void hitAndPrintHand(BlackjackGame blackjackGame, int index){ | ||
| PlayerHandDto playerHandDto = PlayerHandDto.from(blackjackGame.playerDraw(index)); | ||
| printCurrentPlayerHand(playerHandDto); | ||
| List<GameResult> gameResults = game.calculatePlayerProfits(); | ||
| BigDecimal dealerProfit = game.calculateDealerProfit(gameResults); | ||
| outputView.printFinalResult(gameResults, dealerProfit); | ||
| } | ||
|
|
||
| private void playDealerTurn(BlackjackGame blackjackGame){ | ||
| while (blackjackGame.canDealerHit()) { | ||
| printDealerDrawMessage(); | ||
| blackjackGame.dealerDraw(); | ||
| } | ||
| private List<String> inputNames() { | ||
| String input = inputView.readPlayNames(); | ||
| return splitDelimiter(input); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| public class Bet { | ||
| private final BigDecimal amount; | ||
|
|
||
| private Bet(BigDecimal amount) { | ||
| validate(amount); | ||
| this.amount = amount; | ||
| } | ||
|
|
||
| private void validate(BigDecimal amount) { | ||
| Objects.requireNonNull(amount, "๋ฐฐํ ๊ธ์ก์ null์ผ ์ ์์ต๋๋ค."); | ||
| if (amount.compareTo(BigDecimal.ZERO) < 0) { | ||
| throw new IllegalArgumentException("๋ฐฐํ ๊ธ์ก์ ์์๊ฐ ๋์ฌ ์ ์์ต๋๋ค."); | ||
| } | ||
| } | ||
|
|
||
| public static Bet init(){ | ||
| return new Bet(BigDecimal.ZERO); | ||
| } | ||
|
|
||
| public static Bet of(String amount){ | ||
| return new Bet(new BigDecimal(amount)); | ||
| } | ||
|
|
||
| public BigDecimal getAmount() { | ||
| return amount; | ||
| } | ||
|
|
||
| @Override | ||
| public final boolean equals(Object o) { | ||
| if (!(o instanceof Bet bet)) return false; | ||
| return Objects.equals(amount, bet.amount); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(amount); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package blackjack.domain; | ||
|
|
||
| @FunctionalInterface | ||
| public interface BetDecision { | ||
| String decideBet(String name); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR๋ก ๋จ๊ธด ์ง๋ฌธ์ ๋ํ ๋ต๋ณ์ ์ฌ๊ธฐ์ ๋จ๊ฒจ๋ณผ๊ฒ์.
๊ธฐ์กด์๋ ์ปจํธ๋กค๋ฌ๊ฐ ์ธ๋ฑ์ค๋ก Players๋ฅผ ์ง์ ์ํํ๋ฉฐ ์กฐ์ํ๊ณ ์์์ต๋๋ค.
์ด๋ฅผ HitDecision, TurnDisplay, BetDecision ๊ฐ์ ํจ์ํ ์ธํฐํ์ด์ค๋ก ๋ฐ๊ฟ์
ํด ์ํ์ ๊ฒ์ ๋ก์ง์ Game ๋ด๋ถ๋ก ์ด๋์์ผฐ์ต๋๋ค.
์ด ๋ฐฉํฅ์ด ๋ง๋์ง, ์คํ๋ ค ์ธํฐํ์ด์ค๊ฐ ๋์ด๋๋ฉด์ ๋ณต์กํด์ง ๊ฑด ์๋์ง ํผ๋๋ฐฑ ๋ถํ๋๋ฆฝ๋๋ค.
์ปจํธ๋กค๋ฌ๊ฐ Players๋ฅผ ์ง์ ์ํํ๋ฉฐ ๊ฒ์ ์งํ์ ์กฐ์ํ๋ ๊ตฌ์กฐ๋ณด๋ค, ํด ์งํ ์์ฒด๋ฅผ Game์ด ์ฑ ์์ง๋๋ก ์ฎ๊ธด ๋ฐฉํฅ์ ๋ ์์ฐ์ค๋ฝ๋ค๊ณ ๋ด ๋๋ค. ํนํ โ๋๊ฐ ์นด๋๋ฅผ ๋ ๋ฐ์ ์ ์๋์งโ, โํด์ ์ธ์ ์ข ๋ฃํ๋์งโ ๊ฐ์ ๊ท์น์ ๋๋ฉ์ธ์ ๊ฐ๊น์ด ์ฑ ์์ด๋ผ ์ปจํธ๋กค๋ฌ์ ๋จ์ ์์ผ๋ฉด ๊ด๋ จ ํ๋จ ์ฝ๋๊ฐ ์ฌ๋ฌ ํด๋์ค์ ํฉ์ด์ง ์ ์์ด์. (์ถํ ์ ์ง๋ณด์๊ฐ ์ด๋ ค์์ง๊ฒ ์ฃ ๐ฅฒ)
๋ค๋ง HitDecision, TurnDisplay, BetDecision์ฒ๋ผ ์ธํฐํ์ด์ค๊ฐ ๋์ด๋ ๋งํผ ์ถ์ํ ๋น์ฉ๋ ๋ถ๋ช ํ ์๊ธฐ๋๋ฐ, ๊ทธ๋์ ์ด ๊ตฌ์กฐ๊ฐ ์ค๋๋ ฅ์ ๊ฐ์ง๋ ค๋ฉด, ๋จ์ํ ์ปจํธ๋กค๋ฌ ์ฝ๋๋ฅผ ๋๋ฉ์ธ ๊ฐ์ฒด๋ก ๋ฐ์ด ๋ฃ์ ๊ฒ์ด ์๋๋ผ โ์ ๋ ฅ ๊ฒฐ์ โ๊ณผ โ๊ฒ์ ๊ท์นโ์ ๋ถ๋ฆฌํ๋ค๋ ์ ์ด ๋๋ฌ๋์ผ ํ๋ค๊ณ ์๊ฐํด์.
์ง๊ธ์ฒ๋ผ ์ธ๋ถ์์๋ ๊ฒฐ์ ๋ง ๋๊ธฐ๊ณ , ์ค์ ์งํ์ Game์ด ๋ด๋นํ๋ค๋ฉด ๋ฐฉํฅ ์์ฒด๋ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํด์!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hitํ ๋๋ง๋ค ์ค๊ฐ ์นด๋๋ฅผ ์ถ๋ ฅํด์ผ ํ๋ ์๊ตฌ์ฌํญ ๋๋ฌธ์ TurnDisplay ์ฝ๋ฐฑ์ ์ฌ์ฉํ์ต๋๋ค.
์ ๋ ฅ์ ์ฝ๋ฐฑ์ผ๋ก, ์ถ๋ ฅ์ ๊ฒฐ๊ณผ ๊ฐ์ฒด๋ฅผ ์ปจํธ๋กค๋ฌ๊ฐ ๋น๊ฒจ๊ฐ๋ ๋ฐฉ์์ด ๊น๋ํ๋ค๊ณ ์๊ฐํ์ง๋ง, ํด ์ค๊ฐ ์ถ๋ ฅ์ ๋น๊ฒจ๊ฐ ์ ์์ด์ ์ฝ๋ฐฑ์ผ๋ก ์ฒ๋ฆฌํ์ต๋๋ค.
๋ค๋ง ์ถ๋ ฅ ํ์์ด ๋ฐ๋๋ฉด ์ฝ๋ฐฑ ์๊ทธ๋์ฒ๋ ๋ฐ๋ ์ ์๋ค๋ ์ ์ด ๊ฑธ๋ฆฝ๋๋ค.
ํ์ฌ๋ (String name, List cardNames)๋ง ๋๊ธฐ๊ณ ์๋๋ฐ, ์ด ์ ๋๋ฉด ๊ด์ฐฎ์ ๊ฑด์ง, ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์๋์ง ์๊ฒฌ ๋ถํ๋๋ฆฝ๋๋ค.
์ค๊ฐ ์ถ๋ ฅ์ด ํ์ํ ์๊ตฌ์ฌํญ ๋๋ฌธ์ TurnDisplay ๊ฐ์ ์ฝ๋ฐฑ ์์ฒด๋ ํฉ๋ฆฌ์ ์ธ ์ ํ์ด๋ผ ์๊ฐํด์.
๋ค๋ง ๋ง์ํ์ ๊ฒ์ฒ๋ผ ํ์ฌ์ฒ๋ผ ์ถ๋ ฅ ์นํ์ ์ธ ๊ฐ๋ค์ ์ง์ ์๊ทธ๋์ฒ์ ๋ ธ์ถํ๋ฉด, ์ถ๋ ฅ ํ์ ๋ณ๊ฒฝ ์ ๋๋ฉ์ธ ๋ฉ์๋์ ์ฝ๋ฐฑ ์ธํฐํ์ด์ค๊ฐ ๊ฐ์ด ํ๋ค๋ฆด ์ ์์ด ๋ณด์ฌ์.
์ง๊ธ ์๊ตฌ์ฌํญ ๋ฒ์์์๋ name, cardNames ์ ๋๋ง ๋๊ธฐ๋ ๊ฒ๋ ์ถฉ๋ถํ ๋จ์ํ ์ ํ์ด์ง๋ง, ์ดํ ํ์ํ ์ ๋ณด๊ฐ ๋์ด๋ ๊ฐ๋ฅ์ฑ์ด ์๋ค๋ฉด ํด ์ํ๋ฅผ ๋ด๋ ๋ณ๋ ๊ฐ์ฒด๋ก ํ ๋ฒ ๊ฐ์ธ ๋๋ ๋ฐฉํฅ์ด ๋ ๋ณ๊ฒฝ์ ์ ์ฐํ ๊ฒ ๊ฐ์์. ๐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๋ผ๋ฏธํฐ, ๋ฐํ๊ฐ, ํ๋, ๋ด๋ถ ์์ฑ ๋ฑ ๋ฉ์๋ ์๊ทธ๋์ฒ์ ํ์ ์ด ๋ฑ์ฅํ๋ฉด ์์กด์ด ์๊ธฐ๋ ๊ฒ์ผ๋ก ์ดํดํ์ต๋๋ค.
์ด ๊ธฐ์ค์ผ๋ก Players์ ์๋ hitPlayer(int index, TrumpCard card) ๊ฐ์ ๋ฉ์๋๋ฅผ ์ ๊ฑฐํ๊ณ forEach(Consumer)๋ก ๋ฐ๊ฟจ์ต๋๋ค.
Players๋ TrumpCard์ ์ง์ ํ๋ ฅํ ์ด์ ๊ฐ ์๊ณ ์ ๋ฌ๋ง ํ๋ ์ค๊ฐ์์๊ธฐ ๋๋ฌธ์ ๋๋ค.
ํํธ BlackjackGame์ forEach ๋๋ค ์์์ player.hit(deck.deal())์ ํธ์ถํ๋๋ฐ, ์ด๋ TrumpCard๋ฅผ ์๋ ๊ฑด ๋๋ค๋ฅผ ์์ฑํ Game์ด์ง ์คํํ๋ Players๊ฐ ์๋๋ผ๊ณ ํ๋จํ์ต๋๋ค.
"์ง์ ํ๋ ฅํ๋ฉด ์์๋ ๋๊ณ , ์ ๋ฌ๋ง ํ๋ฉด ์ ํ์ ์๋ค"๋ ๊ธฐ์ค์ด ๋ง๋์ง ํผ๋๋ฐฑ ๋ถํ๋๋ฆฝ๋๋ค.
Players๊ฐ TrumpCard๋ฅผ ์ง์ ํด์ํ๊ฑฐ๋ ํ๋จํ์ง ์๊ณ ๋จ์ ์ ๋ฌ๋ง ํ๋ ๊ตฌ์กฐ์๋ค๋ฉด, ํด๋น ํ์ ์์กด์ ์ ๊ฑฐํ ๋ฐฉํฅ์ ํ๋นํด ๋ณด์ฌ์.
player.hit(deck.deal())์์ ์ค์ ๋ก TrumpCard์ ํ๋ ฅํ๋ ์ฃผ์ฒด๋ BlackjackGame๊ณผ Player์ด๋ฏ๋ก, Players๊ฐ ๊ทธ ํ์ ์ ๋ชฐ๋ผ๋ ๋๋ค๋ ํ๋จ์๋ ๋์ํฉ๋๋ค๋ง forEach(Consumer)๋ก ๋ฐ๊พธ๋ฉด์ ํ์ ์์กด์ ์ค์์ง๋ง ์ปฌ๋ ์ ์ ํ์๋ฅผ ์ธ๋ถ์์ ์กฐํฉํ๊ฒ ๋ ๋ฉด๋ ์์ด, ์ผ๊ธ ์ปฌ๋ ์ ์ ์ฑ ์๊น์ง ๊ฐ์ด ์ฝํด์ง์ง ์์๋์ง๋ ํจ๊ป ์๊ฐํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hand์ isBust()๋ฅผ Player๊ฐ ์์ํ๋๋ก ๋ฆฌํฉํ ๋งํ๋๋ฐ, ๊ทธ๋๋ Hand์ ํ์๊ฐ ๋ฐ๋๋ฉด PlayerTest, DealerTest์ canHit() ํ ์คํธ๋ ํจ๊ป ๊นจ์ง๋๋ค. ์์์ ํ๋๋ผ๋ ํ์ ๊ฐ์ฒด์ ํ์ ์์ฒด๊ฐ ๋ฐ๋๋ฉด ์์ ํ ์คํธ๋ ์ํฅ์ ๋ฐ๊ธฐ ๋๋ฌธ์ ๋๋ค.
ํ์ ๋ณ๊ฒฝ์ด ์ง์ ์์กดํ๋ ์์ ํ ์คํธ๊น์ง ๊นจ๋จ๋ฆฌ๋ ๊ฒ ์์ฐ์ค๋ฌ์ด ๊ฑด์ง, ์๋๋ฉด ์์ ํ ์คํธ๊ฐ ์ ๊นจ์ง๋๋ก ์ค๊ณํ ์ ์๋ ๊ฑด์ง ๊ถ๊ธํฉ๋๋ค.
์ด๋๊น์ง ๊นจ์ง๋ ๊ฒ ์ ์์ด๊ณ ์ด๋๋ถํฐ๊ฐ ์ค๊ณ ๋ฌธ์ ์ ์ ํธ์ธ์ง ๊ธฐ์ค์ด ์์๊น์?
์๊ฐ ์ ๋ฆฌ์ค
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ์ฌ hit ๊ฐ๋ฅ ์ฌ๋ถ๋ฅผ canHit()์ if๋ฌธ์ผ๋ก ํ๋จํ๊ณ ์๋๋ฐ, ์ํ ํจํด์ ์ ์ฉํ๋ฉด Player์ ์ํ(ํํ ์ค, ์คํ ์ด, ๋ฒ์คํธ, ๋ธ๋์ญ)์ ๋ฐ๋ผ ํ์๋ฅผ ๋ถ๋ฆฌํ ์ ์๋ค๊ณ ๋ค์ ๋จ๊ณ์ ์ ํ ์์์ต๋๋ค.
์ด ๋ฏธ์ ์ ์ํ ํจํด์ ์ ์ฉํ๋ค๋ฉด ์ด๋ค ๊ตฌ์กฐ๊ฐ ์ข์์ง ๋ฐฉํฅ์ ์ก๊ณ ์ถ์ด์ ์กฐ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
์ํ ํจํด ์์ฒด๊ฐ ๋ธ๋์ญ ๋ฏธ์ ์ ํ์ ์๊ตฌ์ฌํญ์ ์๋ ๊ฒ์ผ๋ก ์๊ณ ์๊ณ ,
๋ค์ ๋จ๊ณ์ ์ ํ ์์์ต๋๋ค<< ๋ค์ ๋จ๊ณ๊ฐ ๋ฌด์์ ๋ง์ํ์๋ ๊ฑด์ง ์กฐ๊ธ ํท๊ฐ๋ฆฌ๋๋ฐ์.๋ธ๋์ญ ๋ฏธ์ ์ด ์ฌ์ดํด2๊น์ง ์์ด๋ณด์ฌ์,
๋ค์ ๋จ๊ณ์ ์๋ฏธ๋ฅผ ์ ๋ชจ๋ฅด๊ฒ ์ด์. ๐ค์ถ๊ฐ์ ์ผ๋ก ์ํํจํด์ ๋์ ํ๋ ๊ฒ ๊น์ง๋ ๋ฌ์๊ฐ ํด๋ณด๊ณ ์ถ๋ค๋ฉด ์ถ๊ฐ๋ก ์งํํด๋ด๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค...๋ง!
์ง๋ฌธ์ด ์กฐ๊ธ ์๋ชป๋๋ค๊ณ ์๊ฐํด์.
๋ฐฉํฅ์ ์ ๊ฐ ๋จผ์ ์ค๊ณ๋ฅผ ํด๋๋ฆฌ๋๊ฒ ์ข์ ๋ฐฉํฅ์ ์๋๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ ์ด๋ ๋ฌ์๊ฐ ์๊ฐํ๋ ์ํ ํจํด ๋์ ๋ฐฉํฅ(or ์ฝ๋)์ ๊ณ ๋ฏผ์ ๋ฐ์ํด๋ณด์ ๋ค, ํผ๋๋ฐฑ์ ์์ฒญํ์ ๋ค๋ฉด ๊ทธ์๋ํด์ ์ ๊ฐ ๋ฐฉํฅ์ ๊ฐ์ด ํ์ธํด๋ณผ ์ ์๊ฒ ์ง๋ง, ์ฒ์๋ถํฐ ์ ๊ฐ ๋ฐฉํฅ์ ์ ์ํด์ฃผ๋ ๋ฐฉ์์ ์ฐํ ์ฝ ์ทจ์ง์๋ ์กฐ๊ธ ๋ฒ์ด๋ฌ๋ค๊ณ ์๊ฐํด์. ๐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฐฐํ ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋๋ฉด์ ๊ธฐ์กด MatchResult์ ์ญํ ์ด ์ ๋งคํด์ก์ต๋๋ค. ์นํจ ํ์ ์ ์ฌ์ ํ ํ์ํ์ง๋ง ์ถ๋ ฅ์๋ ์์ต ๊ธ์ก๋ง ๋์ค๊ณ ,
์์ต ๊ณ์ฐ์ ์ํด์๋ MatchResult + ๋ฐฐํ ๊ธ์ก์ด ํจ๊ป ํ์ํฉ๋๋ค.
๊ธฐ์กด MatchResult๋ฅผ ์์ ํด์ ์์ต ๊ณ์ฐ๊น์ง ๋ด๋นํ๊ฒ ํ ์ง, ๋ณ๋์ ์์ต ๊ณ์ฐ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ผ ํ ์ง, ๊ทธ๋ฆฌ๊ณ ๊ธฐ์กด matchResults()๋ฅผ ํธ์ถํ๋ ์ปจํธ๋กค๋ฌ์ View๋ ํจ๊ป ๋ฐ๊ฟ์ผ ํ๋๋ฐ ์ด๋ฐ ์ฐ์ ์์ ์ ์ต์ํํ๋ ค๋ฉด ์ด๋ป๊ฒ ์ค๊ณํ๋ ๊ฒ ์ข์์ง ๊ถ๊ธํฉ๋๋ค.
์ ๋ ๋ณ๋์ ์์ต ๊ณ์ฐ ๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ธด ํ์ต๋๋ค.
๊ด๋ จ ์ฝ๋ฉํธ๋ ํด๋น ์ฝ๋ฉํธ์์ ๋จ๊ฒจ๋์๋๋ฐ์.
์ ๋ ์นํจ๊ฒฐ๊ณผ์ ๋ฐฐ๋น๋ฅ (?)์ด 1:1๋ก ๋งค์นญ๋๋ค๊ณ ์๊ฐํด์ ๋ฐฐ๋น๋ฅ ์ด๋ผ๋ ๊ฐ๋ ์ ๋ณ๋ enum์ด ์๋๋ผ ์นํจ๊ฒฐ๊ณผ์ ์ํ๋ก ๋์์ ๊ฒ ๊ฐ์์. ๐
๋ฌ์๊ฐ ์งํํ์ ๋ฐฉํฅ๋ ์๊ฐํด๋ณด๋ฉด Payoff๊ฐ ์ค์ง์ ์ผ๋ก WIN,DRAW, LOSE๋ฅผ ๊ฐ ์์๋ก ๊ฐ๊ณ ์๊ธฐ ๋๋ฌธ์ ์๊ฐํด๋ณด๋ฉด ๊ธฐ์กด์ MatchResult์ ์ ์ฌํด๋ณด์ด์ง ์๋์? ๐
์ ๋ ๊ธฐ์กด MatchResult๋ฅผ ์์ ํ๋๋ผ๋ ๊ณ์ฐ์ ๋ด๋นํ๊ฒํ์ง๋ ์์ ๊ฒ ๊ฐ์์.
์์ต ๊ณ์ฐ ๊ฐ์ฒด๋ฅผ ๋ง๋ค ์๋ ์์ ๊ฒ ๊ฐ๊ณ ๊ณ์ฐ์ ๋ณ๋๋ก ์์ต์ ๊ณ์ฐํ๋ ์ญํ ์ํ๋ ๊ฐ์ฒด๋ฅผ ๋ ๊ฒ ๊ฐ๊ธฐ๋ํฉ๋๋ค. ๐ค
์ ๋ผ๋ฉด
GameResult๋ฅผMap<Player, MatchResult>์ ์ผ๊ธ์ปฌ๋ ์ ์ผ๋ก ๋๊ณ์ด ์ผ๊ธ ์ปฌ๋ ์ ๊ฐ์ฒด์๊ฒ ์์ต์ ๊ณ์ฐํ๋ ์ญํ ์ ์์ํ์ ๊ฒ ๊ฐ์์. ๐ค
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๋ฒ์ ๋ค์ด๋ฐ ๋ณ๊ฒฝ + ์ฑ ์ ๋ถ๋ฆฌ + ํจ์ํ ์ธํฐํ์ด์ค ๋์ ์ ๋์์ ์งํํ๋ค ๋ณด๋ ๋ณ๊ฒฝ ๋ฒ์๊ฐ ๋์ด์ ธ์ ํ ์ปค๋ฐ์ ๋ง์ ํ์ผ์ด ๋ฐ๋์์ต๋๋ค. ํ๋๋ฅผ ๊ณ ์น๋ฉด ์ฐ์์ ์ผ๋ก ๋ค๋ฅธ ๊ณณ๋ ์์ ํด์ผ ํ์ต๋๋ค.
๋์ด์ผ๋ณด๋ฉด "๋ค์ด๋ฐ ๋จผ์ โ ์ฑ ์ ๋ถ๋ฆฌ โ ์ธํฐํ์ด์ค ๋์ " ์์๋ก ๋๋ด์ผ๋ฉด ์ข์์ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ฐ ์ํฉ์์ ์ปค๋ฐ์ ์ด๋ป๊ฒ ๋๋๋ ๊ฒ ์ข์์ง ์กฐ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
์ปค๋ฐ ๋จ์๋ฅผ ์์์ ์ผ๋ก ๋ณด๋ ํธ์ด๋ผ, ์กฐ๊ธ ์ ๋์ ์ธ ๊ฒ ๊ฐ์์.
๋ฉ์ธ ์์ ์ ์ค์ ์ ์ผ๋ก ์ปค๋ฐ๋จ์๋ก ๋ณผ ๊ฒ ๊ฐ๊ณ , ๋ค์ด๋ฐ ๋ณ๊ฒฝ, ๋ฆฌํฉํฐ๋ง ์์ ์ ์ผ๋จ ๋ถ๋ฆฌํ๋ ๋ฐฉํฅ์ผ๋ก ์์ ํ๋
๋ฉ์ธ ์์ ์์ฒด์ ์ปค๋ฐ๋จ์๊ฐ ์๋ค๋ฉด ๋ค์ด๋ฐ ๋ณ๊ฒฝ, ๋ฆฌํฉํฐ๋ง
์ฌ์ค ์๊ฐํด๋ณด๋ฉด ๋ค์ด๋ฐ ๋ณ๊ฒฝ, ๋ฆฌํฉํฐ๋ง์ ๊ฒฝ์ฐ์๋ ํฌ๊ฒ ๋ณ๊ฒฝ๋๋ ๊ฒ์ด ์๋๋ผ๋ฉด ๋ฉ์ธ์์ ๊ณผ ํจ๊ป ์งํํด๋ฒ๋ฆฌ๊ธฐ๋ ํฉ๋๋ค. ๐ค
๋ง์ํ์ ๊ฒ์ฒ๋ผ ์ปค๋ฐ๋จ์๋ฅผ ์ชผ๊ฐฐ์ ๋, ์ ๋ฐฉ์์ด ์๋ฏธ๊ฐ์์ผ๋ ค๋ฉด ๋ฆฌ๋ทฐ์ด๋ ์ปค๋ฐ ๋จ์๋ก ์ฝ๋๋ฅผ ์ดํด๋ณด๋ ๊ฒฝ์ฐ์๋ ์๋ฏธ๊ฐ์์ ๊ฒ ๊ฐ์ผ๋, PR ๋จ์๋ก ๋ณด๋ ๊ฒฝ์ฐ์๋ ์ปค๋ฐ ์์๊ฐ ํฐ ์๋ฏธ๊ฐ์์ ๊ฒ ๊ฐ๋ค์. ๐
์ด์จ๊ฑฐ๋ ์ปค๋ฐ ๋จ์๋ ์๊ฒ ์ ์งํ๋ ๊ฒ์ด ์ฅ์ ์ด ํฌ๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์
ํต์ฌ์ ์ปค๋ฐ๋จ์๋ฅผ ์๊ฒ ์ ์งํ๋ ๊ฒ์ด ์ค์ํ๋ค๊ณ ์๊ฐํด์. ๐
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์ฌ์ดํด ํผ๋๋ฐฑ ์ค ๋ฐ์ํ์ง ๋ชปํ ๋ถ๋ถ์ด ์์ ์ ์์ด์, ๋ฆฌ๋ทฐ ํ ํ์ธํ์ฌ ๋ฐ์ํ๊ฒ ์ต๋๋ค.
์ถ๊ฐ๋ก ์ฌ์ดํด 1์์ Suit, Rank ๊ด๋ จ ์ฝ๋ฉํธ์ ์๋น์ค ๋ ์ด์ด ๊ด๋ จ ์ง๋ฌธ์ ๋ํด ์์ง ๋ต๋ณ์ ๋ฐ์ง ๋ชปํด์ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
DM์ผ๋ก ์ด์ ํผ๋๋ฐฑ์ด ์ด๋๋ถ๋ถ์ ๋ง์ํ์ ๊ฑด์ง ๋ฌธ์๋๋ ธ์๋๋ฐ์..!
์๋ง๋ ์๋ 2๊ฐ ์ฝ๋ฉํธ์ ๋ํด์ ๋ต๋ณ์ ์๋๋ฆฐ ๊ฒ ๊ฐ์์.
๊ฐ ์ง๋ฌธ์ด ์ด๋๋ฅผ ๋ง์ํ์ ๊ฒ์ธ์ง, ๋งํฌ ๊ณต์ ํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐ฅฒ
์ฝ๋ฉํธ์ ๋ฌปํ์ ์ฐพ๊ธฐ๊ฐ ์ฝ์ง ์๋ค์.
(์ ๋ฐ์ดํธ)
์ฐพ์ผ์ ๊ฒ์ฒ๋ผ ์ ๋ ์ง๊ธ์ ๊ฒฝ์ฐ ๋ฆฌ์์ค๋ฅผ ์ฐพ์ง ๋ชปํ์ ๋๋
NoSuchElementException์ ์์ธ๋ก ๋์ ธ์ฃผ๋๊ฒ ์กฐ๊ธ ๋ ์ ์ ํ๋ค๊ณ ์๊ฐํ์ด์.try-catch๋ก ๊ฐ์ผ ๋ฐฉ์์ ์์๋ก ๋ค์ด์ฃผ์ จ๋๋ฐ...!
์ ๋จ์ํ ์๋์ ๊ฐ์ด IllegalArgumentExceptuon ๋์ ์ NoSuchElementException์ ๋์ง๋ฉด ๋๋ค๊ณ ์๊ฐํ์ด์. ๐
์ ๋ ์ด ์ฝ๋๋ฅผ ๋ค์ ์ ์ฌํ ์ดํด๋ณด๋ฉฐ ์๊ฐํด๋ณด๋ ๋ง์ํ์ ํด์์ ์ ๋ ๋์ํ๋ ๊ฒ ๊ฐ์์!
of ๋ฉ์๋ ํธ์ถ ์์ ์ ๋ฌธ์ ๋ฅผ ๋ณด๋ฉด, ์กด์ฌํ์ง ์๋ ๊ฐ์ ์กฐํํ๋ค๊ธฐ๋ณด๋ค ์ ํจํ์ง ์์ ์ธ์๋ฅผ ์ ๋ฌํ ์ํฉ์ด๋ผ IllegalArgumentException์ด ๋ ์ ์ ํด ๋ณด์ด๋๊ฒ ๋ง๋ ๊ฒ ๊ฐ์์.
์ ๊ฐ ๋จ๊ธด ์ฝ๋ฉํธ๋ โํ์ค ์์ธ๋ฅผ ํ ๋ฒ ๋ ๊ฒํ ํด๋ณด๋ฉด ์ข๊ฒ ๋คโ๋ ์ทจ์ง์๋๋ฐ, ๋ค์ ์ดํด๋ณด๋ ์ด๋ฒ ์ผ์ด์ค์์๋ IllegalArgumentException์ผ๋ก ์ ์งํ๋ ํ๋จ์ด ํ๋นํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๐๐
ํ๋จํ์ ๊ตฌ์ฒด์ ์ธ ๋ฐฐ๊ฒฝ์ด๋ ํ๋ก์ ํธ ์ปจ๋ฒค์ ์ ์ ๊ฐ ์๊ธฐ๋ก๋ ์ด๋ฐ ์ ์๊ฐ ์๊ฐ๋ณด๋ค ๋ช ํํ์ง๋ ์์ ๊ฒ ๊ฐ์์.์ด๋ฒ ํ๋จ์ ๊ฐ์ธ์ ์ผ๋ก ์ด๋ฐ ์ผ์ด์ค๊ฐ ์์ํ ๊ณ์ธต์์ ์ฐพ์์ค๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค๋ณด๋ ์ต๊ด์ ์ผ๋ก NoSuchElementException์ ๋จผ์ ๋ ์ฌ๋ ธ๋ ๊ฒ ๊ฐ์์. ๐ค
์๋น์ค๋ฅผ โํ๋ฆ ์ ์ด ๋ ์ด์ดโ๋ก ๋ณด๊ณ , BlackjackGame์ ์ํ์ ๊ท์น์ ํจ๊ป ๊ฐ์ง๋ฏ๋ก ๋๋ฉ์ธ์ผ๋ก ํ๋จํ๋ค๋ ์ค๋ช ์ ์ถฉ๋ถํ ๋ฉ๋๋๊ณ ๋ ํ์ฌ ๊ตฌ์กฐ์์ ์๋น์ค๊ฐ ๋จ์ ํจ์ค์ค๋ฃจ๊ฐ ๋ ์ ์์ผ๋ ๋์ง ์๊ฒ ๋ค๋ ํ๋จ๋ ํฉ๋ฆฌ์ ์ด๋ผ ์๊ฐํด์.
๋ค๋ง ์๋น์ค/๋๋ฉ์ธ ๊ตฌ๋ถ ๊ธฐ์ค์ ๋จ์ํ ์ํ ์ ๋ฌด๋ณด๋ค
์ ์ค์ผ์ด์ค ์กฐ์จ์ธ์ง, ๋๋ฉ์ธ ์์ฒด ํํ์ธ์ง๋ก ๊ฐ์ ธ๊ฐ๋ฉด ๋ ๋จ๋จํ ์ค๋ช ์ด ๋ ๊ฒ ๊ฐ๊ณ , ๊ทธ๋ฐ ์๋ฏธ์์ BlackjackGame์ ๋๋ฉ์ธ ์ชฝ์ ๋ ๊ฐ๊น์ ๋ณด์ ๋๋ค. ํจํค์ง ์์น๋ ๊ทธ ์๋์ ๋ง๊ฒ ์ ๋ฆฌ๋๋๊ฒ ์ข๋ค๊ณ ์๊ฐํ์ด์. ๐ (์์ ํด์ฃผ์ ๊ฒ๋ ํ์ธํ์ต๋๋ค. ๐)