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
Step4 블랙잭 (베팅) #548
base: sjparkk
Are you sure you want to change the base?
Step4 블랙잭 (베팅) #548
Conversation
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.
안녕하세요!
블랙잭(베팅) 미션도 잘 구현해주셨습니다👍
몇가지 피드백을 남겼는데 한 번 확인해보시고 다시 리뷰 요청해주세요🙂
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.
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.
카드를 더 받는 과정에서 반복문에 실수가 있었네요..!
수정하였습니다!
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.
@@ -16,17 +17,20 @@ class BlackJackController( | |||
fun play() { | |||
|
|||
val blackjackGame = initBlackjackGame() | |||
val blackjackFlag = blackjackService.checkAllPlayersBlackjack(blackjackGame) |
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.
BlackJackGame 객체는 이미 플레이어와 딜러를 알고 있어요.
플레이어와 딜러가 어떤 상태인지 판단하는 책임을 BlackJackGame가 수행하면 어떨까요?
이 코드뿐만 아니라 (player, dealer)를 인자로 받는 다른 메서드를 BlackJackGame으로 이동시켜도 좋을 것 같아요🙂
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.
BlackJackGame 클래스 내로 책임 위임하였습니다!
if (score > STANDARD_CARD_SCORE) { | ||
this.condition = Condition.STAY | ||
} else if (score.compareTo(Score.BLACK_JACK_SCORE) == 1) { | ||
} else if (score > BLACK_JACK_SCORE) { | ||
this.condition = Condition.BUST | ||
} |
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.
score에 따른 상태 변경을 Condition이 가져가면 어떨까요?
contition = Condition.from(score)
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.
Condition에서 점수 비교하여 반환할 수 있도록 변경하였습니다!
@@ -13,4 +13,10 @@ abstract class Participant( | |||
open fun hit(card: Card) { | |||
cards.append(card) | |||
} | |||
|
|||
open fun checkBlackjack() { | |||
if(cards.calculateScore().value == Score.BLACK_JACK_SCORE.value) { |
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.
Score의 value가 아닌 Score 인스턴스끼리 비교하도록 만들어도 좋을 것 같아요.
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.
점수 비교 수정하였습니다!
var betAmount: Double = betAmount | ||
private set |
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.
게임 중에는 베팅 금액을 변경할 수 없을 것 같아요.
최종 수익은 (베팅 금액 * 수익률)으로 계산할 수 있으니 수익률이라는 값을 정의해보면 어떨까요?
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.
betAmount은 수정이 불가능하도록 수정하고 최종 수익률 금액을 들고 있는 money 프로퍼티를 추가하여 정의하였습니다!
@@ -33,12 +37,25 @@ class BlackjackService { | |||
} | |||
} | |||
|
|||
fun resultBlackjackGameMoney(players: List<Player>, dealer: Dealer): List<BlackjackGameMoneyResult> { |
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.
마찬가지로 BlackJackGame이 이 책임을 가져가면 어떨까요?
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.
BlackJackGame으로 책임 위임하였습니다!
val result = mutableListOf<BlackjackGameMoneyResult>() | ||
|
||
players.forEach { player -> | ||
when (dealer.determineResult(player)) { | ||
MatchResult.WIN -> result.add(BlackjackGameMoneyResult(player.name, -player.betAmount)) | ||
MatchResult.LOSE -> result.add(BlackjackGameMoneyResult(player.name, player.betAmount)) | ||
MatchResult.DRAW -> result.add(BlackjackGameMoneyResult(player.name, 0.0)) | ||
} | ||
} | ||
return result |
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.
map
연산을 활용해봐도 좋을 것 같아요.
val result = mutableListOf<BlackjackGameMoneyResult>() | |
players.forEach { player -> | |
when (dealer.determineResult(player)) { | |
MatchResult.WIN -> result.add(BlackjackGameMoneyResult(player.name, -player.betAmount)) | |
MatchResult.LOSE -> result.add(BlackjackGameMoneyResult(player.name, player.betAmount)) | |
MatchResult.DRAW -> result.add(BlackjackGameMoneyResult(player.name, 0.0)) | |
} | |
} | |
return result | |
return players.map { | |
when(dealer.determineResult(it)) { | |
MatchResult.WIN -> BlackjackGameMoneyResult(it.name, -it.betAmount) | |
MatchResult.LOSE -> BlackjackGameMoneyResult(it.name, it.betAmount) | |
MatchResult.DRAW -> BlackjackGameMoneyResult(it.name, 0.0) | |
} | |
} |
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.
map 연산으로 수정하였습니다~!
private fun addGameResult( | ||
result: MutableList<BlackjackGameResult>, | ||
playerName: String, |
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.
사용하지 않는 메서드는 제거해주시면 좋을 것 같습니다🙂
(이하 동일)
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.
사용하지 않는 메서드 제거하였습니다!
리뷰 재요청드립니다~! |
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.
안녕하세요!
피드백 반영해주신 부분 확인했습니다👍
프로그램을 직접 실행시켜보니 아직 버그가 남아있는 것 같아요🥲
추가 피드백을 함께 남겼는데 한 번 확인해보시고 다시 리뷰 요청 부탁드립니다🙂
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.
private fun replaceWhiteSpaceAndSplitByComma(target: String): List<String> { | ||
return target.trim().replace("\\s".toRegex(), "").split(",") | ||
} |
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.
입력 데이터를 가공하는 책임을 View가 가져가면 어떨까요?
fun resultBlackjackGameMoney(): List<BlackjackGameMoneyResult> { | ||
return players.map { player -> | ||
when (dealer.determineResult(player)) { | ||
MatchResult.WIN -> BlackjackGameMoneyResult(player.name, -player.money) | ||
MatchResult.LOSE -> BlackjackGameMoneyResult(player.name, player.money) | ||
MatchResult.DRAW -> BlackjackGameMoneyResult(player.name, 0.0) | ||
} | ||
} | ||
} |
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.
플레이어들이 돈을 얻거나 잃는 과정이 이 함수에서 담당하면 어떨까요?
승패에 따라 돈을 얻고 잃는 것이 결정되니 코드 응집도도 높아질 것 같습니다🙂
fun currentCondition(): Condition { | ||
return this.condition | ||
} |
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.
상태를 나타낸다면 프로퍼티로 제공하면 어떨까요?
Participant에서 아래와 같이 프로퍼티에 getter를 붙이면 항상 현재 상태를 반환하게 만들 수 있습니다🙂
fun currentCondition(): Condition { | |
return this.condition | |
} | |
// Participant.kt | |
var condition: Condition get() = this.condition | |
protected set |
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.
지금 BlackjackService가 BlackjackGame를 초기화하고 있어요.
하지만 BlackjackGame을 초기화하는 역할은 BlackjackGame이 가져갈 수도 있을 것 같습니다.
그리고 지금 게임과 관련된 책임이 Service, Game에 각각 흩어져 있는 것 같아요.
두 객체 모두 게임 진행에 대한 책임을 가진다면, 굳이 나누지 않고 하나로 합치는 방법도 코드 응집도 측면에서 좋을 수 도 있습니다🙂
참고로 블랙잭은 다음과 같은 순서로 게임이 진행됩니다.
- 플레이어가 베팅한다.
- 플레이어와 딜러에게 카드를 2장씩 분배한다.
- 딜러가 블랙잭이면 블랙잭이 아닌 플레이어는 모두 패배한다. 블랙잭인 플레이어는 베팅 금액을 돌려받는다.
- 딜러가 블랙잭이 아니고 블랙잭인 플레이어가 있다면, 그 플레이어들은 베팅 금액의 1.5배를 돌려받고 게임에서 빠진다.
- 남은 플레이어들은 계속 게임을 진행한다.
- 플레이어는 Stay, Burst, Blackjack 상태가 될 때 까지 카드를 받아 공개한다.
- 플레이어의 차례가 종료되면 딜러는 점수가 16을 넘길 때 까지 카드를 뽑는다.
- 딜러와 플레이어의 점수를 비교해, 플레이어가 이기면 베팅 금액만큼 돌려받고 진다면 베팅 금액을 잃는다.
먼저 각각의 단계를 Controller에 함수로 작성해보신 후, 입출력과 관련된 함수를 제외하고 모두 BlackjackGame 클래스로 이동시켜보면 어떨까요? 그 과정에서 중복 코드를 제거하고 함수를 하나의 책임만 가지도록 바꿔나갈 수 있을 것 같아요🙂
안녕하세요! 블랙잭 베팅 미션 구현하여 리뷰 요청드립니다!
step3에 리뷰 요청 주신 부분도 수정하였습니다!
(Link - #499)