-
Notifications
You must be signed in to change notification settings - Fork 550
[π μ¬μ΄ν΄2 - λ―Έμ (λΈλμ λ°°ν )] 루λ΄μ€ λ―Έμ μ μΆν©λλ€. #1138
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
Merged
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
036f626
feat(README): κΈ°λ₯ μꡬμ¬ν λ° λ‘μ§ μΆκ°
poketopa dfb5e4b
feat(dto): μΆλ ₯μ© DTO μΆκ°
poketopa fdc2dc0
feat(dto): μμ΅ μΆλ ₯ DTO μΆκ°
poketopa a89cc86
refactor(domain): λ§€μ§ λλ² μ κ±°
poketopa c706e85
refactor(domain): μ€λ³΅ λ©μλ (getResult() / getScore()) μ κ±°
poketopa 7f389cb
refactor(domain): getState() λ©μλ μμΉ λ³κ²½ (HandState -> Hand)
poketopa 6504b8d
refactor(test): λ©μλ λ³κ²½μ λ°λ₯Έ ν
μ€νΈ μ½λ λ³κ²½
poketopa ef048eb
feat(controller): DTOλ‘ μ΄λ¦κ³Ό λ°°ν
κΈμ‘μ λ°μ startGame()μ λκΈ°λλ‘ μμ
poketopa 0835980
feat(domain): Participantκ° μ΄ μμ΅μ νλλ₯Ό κ°μ§λλ‘ μΆκ° / νλ μ΄μ΄κ° λ°°ν
κΈ νλλ₯Ό κ°μ§λλ‘ μΆκ°
poketopa beca1a9
feat(domain): BlackJackGameμ΄ DTOλ₯Ό λ°μ κ²μμ μμ±νλλ‘ λ³κ²½
poketopa cedce1b
feat(dto): νλ μ΄μ΄ μ΄λ¦/λ°°ν
κΈ DTO μμ±g
poketopa ae26446
feat(view): λ°°ν
κΈ μ
λ ₯ λ©μλ μΆκ°
poketopa 2a3b016
feat(domain): Balance(μ΅μ’
μμ‘ κ°μ²΄) μμ±
poketopa 588fcd7
feat(domain): λ°°ν
κΈ κ°μ²΄ μΆκ°
poketopa 2ec1ca5
feat(domain): νλ 리μ΄κ° λ°°ν
κΈκ³Ό μμ‘μ κ°μ§λλ‘ μΆκ°
poketopa a62436f
feat(domain): Outcomeμ΄ λΈλμμΌλ‘ μΉλ¦¬νλ κ²½μ°λ₯Ό κ°μ§λλ‘ μΆκ°
poketopa 45aefe0
feat(domain): ResultCalculatorκ° νλ μ΄μ΄μ λλ¬μ μμ‘μ κ°±μ νλλ‘ κΈ°λ₯ μΆκ°
poketopa a732ce5
feat(message): λ°°ν
κΈ μ
λ ₯ λ©μμ§ μΆκ°
poketopa 333b44a
refactor(util): Nameparserκ° String 리μ€νΈλ₯Ό 리ν΄νλλ‘ μμ
poketopa 2cc9225
feat(view): λ°°ν
κΈ μ
λ ₯ κΈ°λ₯ μΆκ°
poketopa 505e37d
feat(view): μ΅μ’
κ²°κ³Ό μΆλ ₯ λ©μλ μΆκ°g
poketopa 8f24990
feat(message): κ²°κ³Ό μΆλ ₯ μμ μΆκ°
poketopa 91f7b5f
feat(controller): κ²°κ³Ό μΆλ ₯ λ©μλ λ° dto λ³ν κΈ°λ₯ μΆκ°
poketopa a5be31e
feat(domain): Participantκ° μμ μ μμ‘μ κ°μ Έμ€λ κΈ°λ₯ (getBalance()) μΆκ°
poketopa a4f9d97
feat(controller): DTO λ§€ν κ°μ²΄ λΆλ¦¬
poketopa 1ded033
refactor(controller): 컨νΈλ‘€λ¬μμ DTOλ‘ μ
λ ₯κ°μ λ°λλ‘ μμ
poketopa 6719381
feat(error): μ¬μλ λ‘μ§μ μν μλ¬ λ©μμ§ μΆκ°
poketopa fb66e0a
feat(view): μ¬μλ λ‘μ§ λ° μμΈ μ²λ¦¬ μΆκ°
poketopa 1e1cd79
feat(test): μ¬μλ λ‘μ§ ν
μ€νΈ μΆκ°
poketopa deb8642
refactor(domain): λλ¬κ° λΈλμμΌ λ νλ μ΄μ΄ ν¨λ°° 쑰건문 μμ
poketopa d5b9830
feat(test): λλ¬κ° λΈλμμΈ κ²½μ° νμμ΄μ΄ ν¨λ°° ν
μ€νΈ μΆκ°
poketopa 370dd86
feat(README): 리λλ―Έ νν© κ°±μ
poketopa 4d49d72
refactor: Depth 2μ΄μμΈ λ©μλ λΆλ¦¬
poketopa 6a6b5e9
refactor(domain): νλ μ΄μ΄κ° 21μ μΌ λ μλμΌλ‘ DRAWκ° μ’
λ£λλλ‘ λ³κ²½
poketopa 044c14a
feat(test): νλ μ΄μ΄κ° BLACKJACKμ΄ μλ μνμμ μ μκ° 21μ μΌ λ λλ‘μ° μ’
λ£ ν
μ€νΈ μΆκ°
poketopa c845bab
refactor: λ©μλ λͺ
λ³κ²½ (BettingMoney -> Betting / getCardList -> getCards)
poketopa 5efd147
refactor(controller): 컨νΈλ‘€λ¬ / λ§€νΌ / λ·° μ±
μ λΆλ¦¬ λ° μ°Έμ‘°νμ§ μλλ‘ μμ
poketopa 4e3fb38
refactor(view): λ·°κ° κ°μ²΄λ₯Ό μ°Έμ‘°νλ©° μΆλ ₯νμ§ μλλ‘ λ³κ²½
poketopa ff3b0ac
refactor(domain): λλ¬κ° 16μ΄νμΌ λ μΉ΄λλ₯Ό λ½λ λ‘μ§μ Dealer κ°μ²΄κ° λ΄λΉνλλ‘ μμ
poketopa 7888352
refactor(domain): HIT λμ STAY μνλ₯Ό κ°μ§λλ‘ μμ
poketopa 769eaf7
feat(test): STAY μνμ λν ν
μ€νΈ μ½λ μΆκ°
poketopa 48098b4
refactor: μ¬μ©νμ§ μλ λ©μλ λ° μμ μ κ±°
poketopa 417bcf2
refactor: ResultViewκ° μΉ΄λ κ°μ²΄λ₯Ό μ§μ λ°μ§ μκ³ DTOλ‘ κ²°κ³Όκ°μ λ°ννλλ‘ μμ
poketopa 76d03ed
refactor: μ¬μ©μμ λ°°ν
κΈμ΄ μ΅μ 10μ, 10μλ¨μλ‘ μ
λ ₯λλλ‘ μμ
poketopa b640dd9
refactor: ErrorMessage κ°μ²΄ μμ λ° μλ¬λ₯Ό InputViewμμ κ΄λ¦¬νλλ‘ μμ
poketopa bd30b64
refactor: μΉ΄λ λλ‘μ° λ©μλλ₯Ό μΈν°νμ΄μ€μ λκ³ λ€νμ±μΌλ‘ νλ μ΄μ΄μ λλ¬κ° ꡬννλλ‘ λ³κ²½
poketopa f3d4c66
refactor: TurnStateλ₯Ό ν΅ν΄ STANDμνλ₯Ό ꡬλΆνλλ‘ μμ
poketopa ded73b2
refactor: λλ¬κ° Balanceλ₯Ό κ³μ°νμ¬ κ°±μ νλλ‘ μμ
poketopa 0cf6a46
refactor: μΉν¨ νμΈ / balance μ μ° λ©μλ λΆλ¦¬
poketopa b832495
refactor(domain): μλ¬ λ©μμ§λ₯Ό νκΈλ‘ μμ
poketopa 70a665f
refactor: IOMessageλ₯Ό μμ νκ³ λ©μμ§κ° μ¬μ©λλ κ°μ²΄μμ μμλ‘ κ΄λ¦¬νλλ‘ μμ
poketopa 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
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
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 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,111 @@ | ||
| package controller.mapper; | ||
|
|
||
| import domain.card.Card; | ||
| import domain.game.GameResult; | ||
| import domain.participant.Dealer; | ||
| import domain.participant.Player; | ||
| import domain.participant.Players; | ||
| import domain.state.Outcome; | ||
| import dto.view.DealerStatDto; | ||
| import dto.view.ParticipantProfitDto; | ||
| import dto.view.ParticipantResultDto; | ||
| import dto.view.ParticipantStatsDto; | ||
| import dto.view.PlayerCardsDto; | ||
| import dto.view.PlayerOutcomeDto; | ||
| import dto.view.PlayerProfitDto; | ||
| import dto.view.ResultDto; | ||
| import dto.view.StartBlackJackDto; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class ResultViewMapper { | ||
| private static final String DEALER_NAME = "λλ¬"; | ||
|
|
||
| public StartBlackJackDto toStartBlackJackDto(Players players, Dealer dealer) { | ||
| return new StartBlackJackDto( | ||
| formatCardName(dealer.getCards().get(0)), | ||
| toPlayerCardsDtos(players) | ||
| ); | ||
| } | ||
|
|
||
| public ResultDto toResultDto(Players players, Dealer dealer) { | ||
| final ParticipantResultDto dealerResult = new ParticipantResultDto( | ||
| DEALER_NAME, | ||
| joinCardNames(dealer.getCards()), | ||
| dealer.getScore() | ||
| ); | ||
| final List<ParticipantResultDto> playerResults = new ArrayList<>(); | ||
| players.forEachPlayer(player -> playerResults.add(new ParticipantResultDto( | ||
| player.getName(), | ||
| joinCardNames(player.getCards()), | ||
| player.getScore() | ||
| ))); | ||
| return new ResultDto(dealerResult, playerResults); | ||
| } | ||
|
|
||
| public ParticipantStatsDto toParticipantStatsDto(Players players, GameResult gameResult) { | ||
| return new ParticipantStatsDto( | ||
| toDealerStatDto(gameResult), | ||
| toPlayerOutcomeDtos(players, gameResult) | ||
| ); | ||
| } | ||
|
|
||
| public ParticipantProfitDto toParticipantProfitDto(Players players, int dealerProfit) { | ||
| final List<PlayerProfitDto> playerProfitDtos = new ArrayList<>(); | ||
| players.forEachPlayer(player -> playerProfitDtos.add(new PlayerProfitDto( | ||
| player.getName(), | ||
| player.getBalance() | ||
| ))); | ||
| return new ParticipantProfitDto(dealerProfit, playerProfitDtos); | ||
| } | ||
|
|
||
| public PlayerCardsDto toPlayerCardsDto(final Player player) { | ||
| return new PlayerCardsDto( | ||
| player.getName(), | ||
| toCardNames(player.getCards()) | ||
| ); | ||
| } | ||
|
|
||
| private List<PlayerCardsDto> toPlayerCardsDtos(Players players) { | ||
| final List<PlayerCardsDto> playerCardsDtos = new ArrayList<>(); | ||
| players.forEachPlayer(player -> playerCardsDtos.add(new PlayerCardsDto( | ||
| player.getName(), | ||
| toCardNames(player.getCards()) | ||
| ))); | ||
| return playerCardsDtos; | ||
| } | ||
|
|
||
| private DealerStatDto toDealerStatDto(GameResult gameResult) { | ||
| final int dealerWinCount = gameResult.getDealerCount(Outcome.DEFAULT_WIN) | ||
| + gameResult.getDealerCount(Outcome.BLACKJACK_WIN); | ||
| final int dealerLoseCount = gameResult.getDealerCount(Outcome.LOSE); | ||
| final int dealerDrawCount = gameResult.getDealerCount(Outcome.DRAW); | ||
| return new DealerStatDto(dealerWinCount, dealerLoseCount, dealerDrawCount); | ||
| } | ||
|
|
||
| private List<PlayerOutcomeDto> toPlayerOutcomeDtos(Players players, GameResult gameResult) { | ||
| final List<PlayerOutcomeDto> playerOutcomeDtos = new ArrayList<>(); | ||
| players.forEachPlayer(player -> playerOutcomeDtos.add(new PlayerOutcomeDto( | ||
| player.getName(), | ||
| gameResult.getPlayerOutcome(player.getName()).result() | ||
| ))); | ||
| return playerOutcomeDtos; | ||
| } | ||
|
|
||
| private List<String> toCardNames(List<Card> cards) { | ||
| return cards.stream() | ||
| .map(this::formatCardName) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private String formatCardName(final Card card) { | ||
| return card.getRank().symbol() + card.getSuit().suit(); | ||
| } | ||
|
|
||
| private String joinCardNames(final List<Card> cards) { | ||
| return cards.stream() | ||
| .map(this::formatCardName) | ||
| .collect(Collectors.joining(", ")); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -9,44 +9,35 @@ public class Hand { | |
| private static final int ACE_ADJUST_SCORE = 10; | ||
| private static final int INITIAL_CARD_COUNT = 2; | ||
| private static final int BLACKJACK_SCORE = 21; | ||
| private static final int DEALER_DRAW_SCORE = 16; | ||
|
|
||
| private final List<Card> cards; | ||
| private int score; | ||
|
poketopa marked this conversation as resolved.
Gomding marked this conversation as resolved.
|
||
|
|
||
| public Hand() { | ||
| this.cards = new ArrayList<>(); | ||
| this.score = 0; | ||
| } | ||
|
|
||
| public void addCard(Card card) { | ||
| this.cards.add(card); | ||
| score += card.getScore(); | ||
| adjustAceScore(); | ||
| } | ||
|
|
||
| public int getScore() { | ||
| return score; | ||
| } | ||
|
|
||
| public int getResult() { | ||
| return score; | ||
| return calculateScore(); | ||
| } | ||
|
|
||
| public boolean checkBust() { | ||
| return score > BLACKJACK_SCORE; | ||
| } | ||
|
|
||
| public boolean isDealerDrawScore() { | ||
| return score <= DEALER_DRAW_SCORE; | ||
| return calculateScore() > BLACKJACK_SCORE; | ||
| } | ||
|
|
||
| private void adjustAceScore() { | ||
| private int calculateScore() { | ||
| int totalScore = cards.stream() | ||
| .mapToInt(Card::getScore) | ||
| .sum(); | ||
| int aceCount = countAces(); | ||
| while (checkBust() && aceCount > 0) { | ||
| score -= ACE_ADJUST_SCORE; | ||
| while (totalScore > BLACKJACK_SCORE && aceCount > 0) { | ||
| totalScore -= ACE_ADJUST_SCORE; | ||
| aceCount--; | ||
| } | ||
| return totalScore; | ||
| } | ||
|
|
||
| private int countAces() { | ||
|
|
@@ -58,10 +49,26 @@ public List<Card> getCards() { | |
| } | ||
|
|
||
| public HandState getHandState(){ | ||
|
poketopa marked this conversation as resolved.
|
||
| return HandState.getState(score, isInitialCards()); | ||
| final int score = calculateScore(); | ||
| if (score > BLACKJACK_SCORE) { | ||
| return HandState.BUST; | ||
| } | ||
|
|
||
| if (score < BLACKJACK_SCORE) { | ||
| return HandState.STAND; | ||
| } | ||
|
|
||
| if (isInitialCards()) { | ||
| return HandState.BLACKJACK; | ||
| } | ||
| return HandState.STAND; | ||
| } | ||
|
|
||
| private boolean isInitialCards(){ | ||
| return cards.size() == INITIAL_CARD_COUNT; | ||
| } | ||
|
|
||
| public boolean canDraw(){ | ||
| return getScore() < BLACKJACK_SCORE; | ||
| } | ||
|
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ¬κΈ°λ μ¬μ©νμ§ μλ λ©μλλ€μ! |
||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.