[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ์ ์ด์ฝฅ ๋ฏธ์ ์ ์ถํฉ๋๋ค.#1119
[๐ ์ฌ์ดํด2 - ๋ฏธ์
(๋ธ๋์ญ ๋ฒ ํ
)] ์ ์ด์ฝฅ ๋ฏธ์
์ ์ถํฉ๋๋ค.#1119khcho96 wants to merge 98 commits intowoowacourse:khcho96from
Conversation
โฆํ๋๋ก ๊ตฌํ ์์
โฆialScore() ๋ฉ์๋ ๊ตฌํ
โฆmeManager ๋ฉ์๋๋ช ๋ณ๊ฒฝ
โฆ์๋ ๋ฐ calculatePlayerProfit()๋ฅผ BlackjackJudge๋ก ์ด๋
โฆult(), calculatePlayerProfit()๋ฅผ BlackjackJudge๋ก ์ด๋
โฆult๊ฐ ์ฑ ์์ง๋๋ก ์์
Gomding
left a comment
There was a problem hiding this comment.
์๋
ํ์ธ์ ์ ์ด์ฝฅ!
์ ์ฒด์ ์ผ๋ก ์ ์์ ํด์ฃผ์
จ๋ค์ :)
์ถ๊ฐ๋ก ์ฝ๋ฉํธ ๋จ๊ฒผ์ผ๋ ํ์ธ๋ถํ๋๋ ค์!
๊ถ๊ธํ ์ ์์ผ๋ฉด ์ธ์ ๋ DM ์ด๋ ์ฝ๋ฉํธ ๋จ๊ฒจ์ฃผ์ธ์~
| } | ||
|
|
||
| public boolean isBlackjack() { | ||
| return calculateInitialScore() == BLACKJACK_SCORE; |
There was a problem hiding this comment.
์ฌ์ค Blackjack ์ด๋ผ๋ ์ ์๋ ์กฐ๊ธ ํน์ดํ ๊ท์น์ ๊ฐ์ง๊ณ ์์ต๋๋ค
๋จ์ 21์ ๊ณผ Blackjack ์ด๋ผ๋ ์ ์ ์ํ๋ ์ํจ์ ์ํ๊ฐ ๋ค๋ฆ ๋๋ค
๋ธ๋์ญ์ ํจ๊ฐ 2์ฅ + 21์ ์ผ ๋ ๋ฅผ ๋ธ๋์ญ์ด๋ ์ํ๋ก ๋ณด๊ณ ์์ด์~
There was a problem hiding this comment.
ํ์ฌ calculateInitialScore()๊ฐ ์ฒ์ ๋ฐ์ 2์ฅ์ด 21์ผ ๋๋ฅผ Blackjack์ผ๋ก ๋ณด๊ณ ์๋๋ฐ, ๊ทธ๋ฅ calculateTotalScore() == BLACKJACK_SCORE์ด๋ฉด์ cards.size() == 2์ธ ๊ฒ์ ๋ณด๋๊ฒ ์ ํํ๊ฒ ๊ตฐ์!
ํด๋น๋ถ๋ถ ์์ ๊ฐ์ด ์์ ํ์ต๋๋ค!
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class BlackjackResultDtoTest { |
There was a problem hiding this comment.
Dto ๋ ํ
์คํธ ๋์์ด ๋ง์์ง ๊ณ ๋ฏผํด๋ณด๋ฉด ์ข๊ฒ ์ด์!
ํ
์คํธ๋ฅผ ์์ฑํ๋ ์ด์ ์ ๋น์ทํ ๊ฒ ๊ฐ๋ค์ :)
์ ๋ ํ
์คํธ๊ฐ ์์ผ๋ฉด ์ข๊ธดํ์ง๋ง DTO ๋ ๋จ์ ๊ฐ์ ๋ด๋ ๊ฐ์ฒด์ด๋ ๊ผญ ํ์ํ๊ฐ? ๋ผ๋ ์
์ฅ์ด๊ธด ํฉ๋๋ค ๐
๊ทธ ์๊ฐ์ ๋ค๋ฅธ ์ค์ํ ํด๋์ค์ ํ
์คํธ ์์ฑ์ ์๊ฐ์ ๋ ์ฌ์ฉํ๋๊ฒ ์ข๋ค๊ณ ์๊ฐํด์์!
There was a problem hiding this comment.
ํ ๋ก ์๊ฐ์ ์ ํ ๊ท์น์ด "getter, setter, ๊ทธ๋ฆฌ๊ณ ๋จ์ ๋ฉ์๋ ํธ์ถ๋ง ํ๋ ๋ฉ์๋๋ฅผ ์ ์ธํ public ๋ฉ์๋๋ ๋ชจ๋ ํ ์คํธํ๋ค"์ฌ์ Dto ๋ํ ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ์ต๋๋ค.
๊ทผ๋ฐ ์์ฑํ๋ฉด์๋ "์ด๊ฑธ ํด์ผํ๋.." ์ถ์๋๋ฐ, ๋ช ํํ ์ง์ด์ฃผ์ ์ ๋์ฑ ํ ์คํธ๋ฅผ ์ํด๋ ๋๊ฒ ๋ค๋ ํ์ ์ด ์๊ธฐ๋ค์๐
Dto ํ ์คํธ๋ ์ญ์ ํ์ต๋๋ค!
| if (player.isBlackjack() && dealer.isBlackjack()) { | ||
| return Result.DRAW; | ||
| } | ||
| if (player.isBlackjack()) { | ||
| return Result.BLACKJACK_WIN; | ||
| } |
There was a problem hiding this comment.
์ด๋ ๊ฒ ํ๋๊ฒ๋ ๊ฐ๋ฅํ ๊ฒ ๊ฐ๋ค์ ๐ค
| if (player.isBlackjack() && dealer.isBlackjack()) { | |
| return Result.DRAW; | |
| } | |
| if (player.isBlackjack()) { | |
| return Result.BLACKJACK_WIN; | |
| } | |
| if (player.isBlackjack()) { | |
| if (dealer.isBlackjack()) { | |
| return Result.DRAW; | |
| } | |
| return Result.BLACKJACK_WIN; | |
| } |
There was a problem hiding this comment.
๋ง์ต๋๋ค! ๊ทผ๋ฐ ์ด๋ฒ ๋ฏธ์ ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ์์ indent๋ฅผ 1๊น์ง๋ง ํ์ฉํ๋ค๋ ๊ท์น์ ์งํค๊ธฐ ์ํด ์ด๋ ๊ฒ ๊ตฌํํ์ต๋๋ค.
์ฌ์ค indent๊ฐ 2์ ๋์ฌ๋ ์ถฉ๋ถํ ๊ฐ๋
์ฑ์๊ณ ๊น๋ํ ์ฝ๋๋ผ๊ณ ์ ๋ ์๊ฐํ๋๋ฐ.. ํ๋ฆฌ์ฝ์ค ๋ฏธ์
์์๋ indent๋ 2๊น์ง ํ์ฉ์ด์๊ตฌ์!
indent 1์ ์ ์งํ๋ ค๋ค๋ณด๋ ์คํ๋ ค ๋ ๊ฐ๋
์ฑ์ด ์์ด์ง๋ ์ฝ๋๊ฐ ๋์ค๋ ๋๋์
๋๋ค..๐
์ฐฐ๋ฆฌ๋ ์ด ์๊ตฌ์ฌํญ์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ๊ถ๊ธํฉ๋๋ค!
| public BlackjackGameManager() { | ||
| this.cardMachine = new CardMachine(); | ||
| this.blackjackJudge = new BlackjackJudge(); | ||
| } |
There was a problem hiding this comment.
ํ์ํ ์์กด์ ์์ฑ์ ์ธ์๋ก ๋ฐ๋๊ฒ์ด ๋ ์ ์ฐํ ๊ตฌ์กฐ๋ผ๊ณ ์๊ฐํ๋๋ฐ
์ด๋ฏธ ๊ตฌํํ์ BlackjackControllerFactory ๋ผ๋๊ฒ๋ ์์ผ๋ BlackjackGameManager ๋ ๊ณ ๋ฏผํด๋ณผ ์ ์๊ฒ ๋ค์
| public void createParticipants(List<PlayerName> playerNames, List<BetAmount> betAmounts) { | ||
| participants = Participants.of(playerNames, betAmounts); |
There was a problem hiding this comment.
์์ฑ์์์ ํ๋ ์ด์ด๋ค์ ๋ฐ์ง์๊ณ ๋ณ๋๋ก ์์ฑํ๋๊ฒ๋ ๊ณ ๋ฏผํด๋ณด๋ฉด ์ข๊ฒ ์ด์~
|
|
||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
| private final BlackjackGameManager blackjackGameManager; |
There was a problem hiding this comment.
์ด๋ถ๋ถ๋ ์ฌ์ดํด1์์ ํผ๋๋ฐฑ์ ๋ชป๋๋ ธ๋๋ฐ
Controller ๊ฐ BlackjackGameManager ๋ผ๋๊ฒ์ ์ํ๋ก ๊ฐ์ ธ๋ ๊ด์ฐฎ์๊น์?
Controller ๋ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ๊ฒ ์ข๋ค๊ณ ์๊ฐํด์
์ ์ด์ฝฅ์ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
| public void drawInitialCards(Supplier<Card> cardSupplier) { | ||
| dealer.addCard(cardSupplier.get()); | ||
| dealer.addCard(cardSupplier.get()); | ||
| players.drawInitialCards(cardSupplier); | ||
| } | ||
|
|
||
| public void drawCardsByDealer(Supplier<Card> cardSupplier) { | ||
| dealer.addCard(cardSupplier.get()); | ||
| } | ||
|
|
||
| public Player drawCardsByPlayer(String name, Supplier<Card> cardSupplier) { | ||
| players.addCard(name, cardSupplier.get()); | ||
| return players.getPlayer(name); | ||
| } |
There was a problem hiding this comment.
ํ ์คํธ ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ก ๋ง๋ค์ด์ฃผ์ ์ ์ข๋ค์! ๐ ๐ ๐
+) ํ ์คํธ์ ์ด๋ ค์์ด๋ผ๋ฉด ์๋ ๊ธ๋ ํ์ตํด๋ณด์๋ฉด ์ข๊ฒ ์ด์~
| private Integer calculateBaseScore() { | ||
| return cards.stream() | ||
| .map(Card::getScore) | ||
| .reduce(0, Integer::sum); | ||
| } | ||
|
|
||
| private Integer calculateInitialBaseScore() { | ||
| return cards.subList(0, INITIAL_CARD_COUNT).stream() | ||
| .map(Card::getScore) | ||
| .reduce(0, Integer::sum); | ||
| } |
There was a problem hiding this comment.
์ฝ๋์ ์ค๋ณต๋๋ ๋ถ๋ถ์ด ์์ด์ ์ค๋ณต๋๋ ๋ถ๋ถ๋ง private ๋ฉ์๋๋ก ์ถ์ถํด๋ณผ ์ ์๊ฒ ๋ค์
There was a problem hiding this comment.
์์ ํผ๋๋ฐฑ ์ ์ฉ ๊ณผ์ ์์ calculateInitialBaseScore ๋ฉ์๋๊ฐ ์ญ์ ๋์์ต๋๋ค!
There was a problem hiding this comment.
๊ธฐ์ค์ด ๋ช
ํํ๋ค์ ๐ ๐ ๐
์ ์ฒด์ ์ผ๋ก ๋์ํฉ๋๋ค!
์ฒดํฌ ๋ฆฌ์คํธ
test๋ฅผ ์คํํ์ ๋, ๋ชจ๋ ํ ์คํธ๊ฐ ์ ์์ ์ผ๋ก ํต๊ณผํ๋์?์ด๋ค ๋ถ๋ถ์ ์ง์คํ์ฌ ๋ฆฌ๋ทฐํด์ผ ํ ๊น์?
์ฌ์ดํด1 ๋ง์ง๋ง ์ฝ๋ฉํธ์์ ๋ฐ์ํ ๋ด์ฉ
์ง๋ฌธ
์๋๋ ์ค๋ณต์ ๋ง๋ค๊ธฐ๋ ํ๋ค๋ ์ฌ์ค์ ์ถฉ๊ฒฉ์ ์ด๋ค์ ๐ฎ
"์ค๋ณต"์ ๋ํด 100% ๋ถ์ ์ ์ผ๋ก ๋ฐ๋ผ๋ดค์๋๋ฐ, ๊ทธ๋ ์ง ์์ ์๋ ์๋ค๋ ์ฌ์ค์ ์ธ์งํ๊ณ ์ ์ฐํ๊ฒ ์๊ฐํด๋ด์ผ๊ฒ ์ต๋๋ค!
ํ ๊ฐ์ง ๊ถ๊ธํ ์ ์ด ์๋๋ฐ, ์ฐฐ๋ฆฌ๋ constant ํจํค์ง๋ฅผ ์ฌ์ฉํ์๋ ํธ์ธ๊ฐ์?
๋ง์ฝ ์ฌ์ฉํ์ ๋ค๋ฉด ์ด๋ค ๊ฒฝ์ฐ์, ์ด๋ค ํด๋์ค๋ฅผ ๊ณตํต์ผ๋ก ๊ด๋ฆฌํ๋ constant ํจํค์ง๋ก ๋ถ๋ฆฌํ์๋์?
์ ๊ฐ ์๊ฐํ์ ๋ ํ์ฌ ์น๋ฌดํจ ํ๋จ์ ํ๋ ๋ฉ์๋๋ BlackjackGameManager ํด๋์ค์ getBlackjackStatistics ๋ฉ์๋ ๋ก์ง์ธ๋ฐ, ํนํ ํด๋น ๋ฉ์๋ ๋ด ์๋ 3์ค์ ๋ก์ง์ธ ๋ฏ ํฉ๋๋ค.
์ด ๋ก์ง์ ๊ฐ์ง๋ ๊ฐ์ฒด(A๋ผ๊ณ ์ง์นญํ๊ฒ ์ต๋๋ค)๋ฅผ ๋ฐ๋ก ๋ง๋ ๋ค๋ฉด A๋ judgePlayerResult ๋ฉ์๋์ calculatePlayerProfit ๋ฉ์๋๋ฅผ ํด๋์ค ๋ด์์ ๊ฐ์งํ ๋ฐ, ์ด๋ ๋ณด์๋ ๊ฒ์ฒ๋ผ ๋ฉ์๋์ ์ธ์๋ก Dealer์ Player๊ฐ ๋ค์ด๊ฐ๊ธฐ๋๋ฌธ์ A๊ฐ Dealer์ Player์๊ฒ ์์กดํ๊ฒ ๋๊ณ , ๊ฒฐํฉ๋๊ฐ ์ปค์ง๊ฒ ๋์ง ์์๊น๋ผ๋ ๋ถ๋ถ์ด ์ผ๋ ค๋ฉ๋๋ค. ๊ฒฐํฉ๋๊ฐ ์ปค์ง๋ฉด ์์ ๋ฒ์๊ฐ ์ปค์ง๊ฒ ๋๋ ๋จ์ ์ด ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ด ๋ถ๋ถ์ ๋ํ ์ฐฐ๋ฆฌ์ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค!
Rank ํด๋์ค์์ score์ ์์๊ฐ ํฌ์ฅ์ ๋ํด ๋ง์ํด์ฃผ์ จ๋๋ฐ, ๋จ์ํ ์์๋ฅผ ์ ์ฅํ๊ณ ์๊ณ ๋ธ๋์ญ ์ ์ ๊ท์น์ ๋ํ ๋ด์ฉ์ ๋ค๋ฅธ ๊ฐ์ฒด์์ ๋ฉ์๋๋ก ๊ตฌํํ๊ธฐ๋๋ฌธ์ score์์ ์ด๋ค ์ถ๊ฐ์ ์ธ ๊ท์น์ ๊ฒ์ฆํ๊ฑฐ๋ ๋ค๋ฃฐ์ง ์์ด๋์ด๊ฐ ๋ ์ค๋ฅด์ง ์๋ค์๐
ํน์ ์ฐฐ๋ฆฌ ์ ์ฅ์์ score๋ฅผ ์์๊ฐ ํฌ์ฅํ๋ค๋ฉด ์ด๋ค์์ผ๋ก ๊ตฌํํ์ค์ง ๊ถ๊ธํฉ๋๋ค!
1์ฐจ ํผ๋๋ฐฑ ์์ ์์