Skip to content
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] 블랙잭(베팅) #797

Open
wants to merge 1 commit into
base: kimihiqq
Choose a base branch
from
Open

Conversation

kimihiqq
Copy link

안녕하세요 리뷰어님 🙂
이번 PR에서는 Step4 블랙잭(베팅) 기능들을 구현해 추가했습니다
이번 단계도 잘 부탁드립니다! 🙇

Copy link

@Wordbe Wordbe left a comment

Choose a reason for hiding this comment

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

블랙잭 미션을 빠르게 구현해주셨네요.
고생하셨습니다!

코멘트 드린 내용을 확인해보시고, 가능하신 부분은 반영 부탁드립니다.
감사합니다 ☺️

Comment on lines +38 to +51
private fun calculatePlayerResult(
player: Player,
dealerScore: Int,
dealerBlackjack: Boolean,
): Int {
val playerBlackjack = player.isBlackjack()
return when {
player.getTotalValue() > BUST_THRESHOLD -> -player.getBettingAmount()
dealerScore > BUST_THRESHOLD -> player.getBettingAmount()
dealerBlackjack && playerBlackjack -> 0
playerBlackjack -> (player.getBettingAmount() * BLACKJACK_MULTIPLIER).toInt()
player.getTotalValue() > dealerScore -> player.getBettingAmount()
else -> -player.getBettingAmount()
}
Copy link

Choose a reason for hiding this comment

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

Score 라는 객체를 만들어 일부 혹은 전체 기능의 일을 위임해보면 어떨까요?

Comment on lines +28 to +35
val playerResults =
participants.players.getPlayers()
.associate { player ->
player.name to calculatePlayerResult(player, dealerScore, dealerBlackjack)
}

val dealerProfit = playerResults.values.sum() * -1
return playerResults + ("Dealer" to dealerProfit)
Copy link

Choose a reason for hiding this comment

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

player result 객체를 만들어보는건 어떨까요? 🙂

player.name to calculatePlayerResult(player, dealerScore, dealerBlackjack)
}

val dealerProfit = playerResults.values.sum() * -1
Copy link

Choose a reason for hiding this comment

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

앞에 -(마이너스) 를 달아서 간단하게 표현해도 좋을 것 같아요 🙂

class Player(val name: String) : Participant()
class Player(
val name: String,
private var bettingAmount: Int,
Copy link

Choose a reason for hiding this comment

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

이 변수의 값은 바뀌지 않아보여요 !

Comment on lines +7 to +9
fun getBettingAmount(): Int {
return bettingAmount
}
Copy link

Choose a reason for hiding this comment

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

코틀린은 외부에서 사용할 게터는 자동으로 정의해주기 때문에 필요없어보여요 😀

@@ -6,6 +6,11 @@ object InputView {
return readlnOrNull()?.split(",")?.map { it.trim() } ?: emptyList()
}

fun getBettingAmount(playerName: String): Int {
println("$playerName 의 배팅 금액은?")
return readlnOrNull()?.toIntOrNull() ?: 0
Copy link

Choose a reason for hiding this comment

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

베팅 금액이 없으면 게임을 시작하지 못하게 해야 하지 않을까요? 🧐

Comment on lines 7 to +9
class PlayersTest : StringSpec({
"Players should distribute two cards to each player" {
val players = Players(listOf(Player("pobi"), Player("jason")))
val players = Players(listOf(Player("pobi", 1000), Player("jason", 1000)))
Copy link

Choose a reason for hiding this comment

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

players 도 getter 가 있는데, 코틀린 기본 게터를 사용해보는게 어떨까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants