-
Notifications
You must be signed in to change notification settings - Fork 313
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
๐ 4๋จ๊ณ - ๋ธ๋์ญ(๋ฒ ํ ) #826
base: seolyoungkim
Are you sure you want to change the base?
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.
์ค์๋ ๋ฆฌ๋ทฐ ์์ฒญ ์ฃผ์ ๊ฑธ ๋์น๊ณ ์์ด์ ๋ฆฌ๋ทฐ๊ฐ ๋ง์ด ๋ฆ์์ต๋๋ค. ๐ฅฒ
๋ง์ง๋ง ๋จ๊ณ์ด๋ ์กฐ๊ธ๋ง ๋ ํ๋ด์ ๋ฏธ์
๋ง๋ฌด๋ฆฌ ์ง์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ช๋ช ์ฝ๋ฉํธ ๋จ๊ฒจ๋์๋๋ฐ, ํ์ธํด์ ์์ ๋ถํ๋๋ฆด๊ฒ์. ๐
README.md
Outdated
- [] ๋ฌด์น๋ถ์ธ ๊ฒฝ์ฐ ๊ฒ๋ธ๋ฌ๊ฐ ๋ฐฐํ ๊ธ์ก์ ๋๋ ค๋ฐ๋๋ค | ||
- [] ๊ฒ๋ธ๋ฌ๊ฐ ์ด๊ธฐ๋ ๊ฒฝ์ฐ ๋ฐฐํ ๊ธ์ก์ ๋ฐ๋๋ค | ||
- [] ๋๋ฌ๊ฐ 21์ ์ด๊ณผํ๋ฉด ๊ฒ๋ธ๋ฌ๋ค์ด ์น๋ฆฌํ๋ฏ๋ก ๊ฒ๋ธ๋ฌ๋ค์ ๋ฐฐํ ๊ธ์ก์ ๋๋ ค๋ฐ๋๋ค | ||
- [] ๋๋ฌ๊ฐ 21์ ์ดํ์ด๊ณ ๊ฒ๋ธ๋ฌ๊ฐ ๋๋ฌ๋ณด๋ค ์ ์๊ฐ ๋์ผ๋ฉด ์น๋ฆฌํ๋ฏ๋ก ๋ฐฐํ ๊ธ์ก์ ๋๋ ค๋ฐ๋๋ค | ||
- [] ๊ฒ๋ธ๋ฌ์ ์นด๋๊ฐ 2์ฅ์ด๊ณ ๋ธ๋์ญ(ํฉ์ด 21)์ธ ๊ฒฝ์ฐ 1.5๋ฐฐ ๋ฐ๋๋ค |
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.
๊ธฐ๋ฅ ๊ตฌํ์ ํ์
จ๋ค๋ฉด ํด๋น ๊ธฐ๋ฅ ๊ตฌํ ๋ชฉ๋กํ๋ โ
ํ์๋ฅผ ํด์ฃผ์ธ์. ๐
๊ฐ๊ธ์ ์ปค๋ฐ ๋จ์๋ก ๊ธฐ๋ฅ์ ๊ตฌํํ์ค ๋, ๊ฐ์ด ์ฒดํฌ๋ฅผ ํด์ฃผ์ ๋ค๋ฉด ๋ ์ด์์๋ ๋ฌธ์๊ฐ ๋ ๊ฒ ๊ฐ์์. ๐
require(dealers.size == 1) { "๊ฒ์ ๋ด ๋๋ฌ๋ ํ๋ช ๋ง ์ฐธ์ฌ ๊ฐ๋ฅํฉ๋๋ค." } | ||
} | ||
|
||
private fun requiresAtLeastOneGambler() { | ||
val gamblers = participants.filter { participant -> !participant.isDealer() } | ||
val gamblers = participants.filter { participant -> !participant.isDealer } |
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.
extractDealer, extractGamblers ๋ฉ์๋๋ ํ์
๋์ ์ isDealer
ํ๋๋ก ํํฐ๋งํ ์ ์์ ๊ฒ ๊ฐ์๋ฐ
๊ฐ๋ฅํ๋ค๋ฉด ํ์
๋์ ์ ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ํํฐ๋งํ๋๋ก ๋ณ๊ฒฝํด๋ณด๋ฉด ์ด๋จ๊น์?
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.
extractDealer, extractGamblers ๋ฉ์๋๋ ๊ฐ๊ฐ Dealer
, Gambler
ํ์
์ ์ฌ์ฉํด์ผ๋ง ํ๋ ๊ฒฝ์ฐ๊ฐ ์์ด์ filterIsInstance
๋ฅผ ์ฌ์ฉํ๋๋ฐ์.
์ด ๋ถ๋ถ์ ๋ํด์ ๊ณ์ ๊ณ ๋ฏผ์ ํด๋ณด๊ณ ์๋๋ฐ, isDealer
๋ฅผ ์ฌ์ฉํด๋ ๊ฒฐ๊ตญ ํ์
์บ์คํ
์ ํด์ฃผ์ด์ผ ํ๋ ์ํฉ์ด ์์, ์ ์ด์ extract๋ฅผ ์๋ํ๋ ์์ ์์ ํ์
์ผ๋ก ๊ฑธ๋ฌ์ฃผ๋๊ฒ ์ข์ง ์์๊น? ์๊ฐํ์ต๋๋ค!
ํน์ ๊ฒฝ๋ก๋๊ป์๋ Participant
๋ฅผ Gambler
, Dealer
๋ก ์บ์คํ
ํด์ ์ฌ์ฉํด์ผ ํ ๊ฒฝ์ฐ์๋ ์ด๋ค ๋ฐฉ๋ฒ์ผ๋ก ๊ตฌํ์ ํ์ค๊น์?
@@ -11,12 +11,12 @@ class Participants(private val participants: List<Participant>) { | |||
} | |||
|
|||
private fun requiresOnlyOneDealer() { | |||
val dealers = participants.filter { participant -> participant.isDealer() } | |||
val dealers = participants.filter { participant -> participant.isDealer } | |||
require(dealers.size == 1) { "๊ฒ์ ๋ด ๋๋ฌ๋ ํ๋ช ๋ง ์ฐธ์ฌ ๊ฐ๋ฅํฉ๋๋ค." } |
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์ด๋ผ๋ ์ซ์๋ ๋งค์ง๋๋ฒ์ธ ๊ฒ ๊ฐ๋ค์.
์์๋ก ์ถ์ถํ์ฌ ์๋ฏธ๋ฅผ ๋๋ฌ๋ด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐
@@ -21,6 +23,15 @@ sealed class Participant(val name: String) { | |||
return score > BlackjackRule.BLACKJACK_SCORE | |||
} | |||
|
|||
fun isBlackjack(): Boolean { | |||
return cards.size == 2 |
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.
2๋ผ๋ ์ซ์๋ ๋งค์ง๋๋ฒ๋ก ๋ณด์ด๋ค์.
์ด์ ์ฝ๋ฉํธ์ ๋์ผํ๊ฒ ๋งค์ง๋๋ฒ ์ฒ๋ฆฌ ์ ์ ํ๊ฒ ๋ถํ๋๋ฆด๊ฒ์!
@@ -9,6 +9,8 @@ sealed class Participant(val name: String) { | |||
val score: Int | |||
get() = _cards.calculateTotalScore() | |||
|
|||
abstract val isDealer: Boolean |
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.
๋ธ๋์ญ 4๋จ๊ณ์๋ 3๊ฐ ์ด์์ ์ธ์คํด์ค ๋ณ์๋ฅผ ๊ฐ์ง ํด๋์ค๋ฅผ ์ฐ์ง ์๋๋ค
๋ผ๋ฏ ๋ฏธ์
์๊ตฌ์ฌํญ์ด ์๋๋ฐ์.
๋ฌผ๋ก ์ฝ๊ธฐ์ ์ฉ ํ๋กํผํฐ์ ๊ฒฝ์ฐ์๋ ์์์ ์ธ๊ธํ๋ ์ธ์คํด์ค ๋ณ์ ๊ฐ๋
๊ณผ๋ ๋ค๋ฅด๋ค๊ณ ์๊ฐํ์ง๋ง, ์์ ๋ฏธ์
์๊ตฌ์ฌํญ์ ๊ฐ๊ธ์ ์ธ์คํด์ค ๋ณ์๋ฅผ ๋ถํ์ํ๊ฒ ์ ์ธํ์ง ๋ง๋ผ๋ ์๋๋ฅผ ๋ดํฌํ๊ณ ์๋ค๊ณ ์๊ฐํด์. ๐
๊ฐ์ธ์ ์ผ๋ก isDealer์ ๊ฒฝ์ฐ์๋ ๊ผญ ํ๋๋ก ์ ์ธํ ํ์ ์์ด ์ถ์ ๋ฉ์๋๋ฅผ ๋๊ณ , ๊ฐ ๊ตฌํ์ฒด์์ ์ฌ์ ์ํด๋ ์ถฉ๋ถํ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ๋๋ฐ ์ค์๋์ ์ด๋ป๊ฒ ์๊ฐํ์๋์? ๐ค
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.
์ ๋ isDealer
๊ฐ ์ํ๋ฅผ ํํํ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํด์ ์ธ์คํด์ค ๋ณ์๋ก ์ ์ธ์ ํ์์๋๋ฐ, ์ง๊ธ ๋ณด๋ ์ ๊ฐ isXxx()
๋ ๋ชจ๋ ๋ฉ์๋๋ก ์ ์ธ์ ํด๋์์๊ตฐ์... ใ
ใ
ใ
์ผ๊ด์ฑ์ ๋ง์ถ๊ธฐ ์ํด์๋ผ๋ ๋ฉ์๋๋ก ๋ณ๊ฒฝํ๋ ๊ฒ์ด ์ข์ ๋ณด์
๋๋ค. ๊ฒฝ๋ก๋ ๋ง์๋๋ก ์ถ์ ๋ฉ์๋๋ก ๋ณ๊ฒฝ์ ํ์์ด์ ๐
์ถ๊ฐ๋ก, ์ ๋ isDealer
๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ์ ์ธํ๋๋, ๋ฉ์๋๋ก ์ ์ธํ๋๋์ ๋ํด ์ ๋ง ๋ง์ด ๊ณ ๋ฏผ์ด ๋๋ ๊ฒ ๊ฐ์์.
์ฝํ๋ฆฐ์์ ์ ์ธํ๋ ์ธ์คํด์ค ๋ณ์(ํ๋กํผํฐ)๋ค์, ์๋ฐ์ ์ธ์คํด์ค ๋ณ์์๋ ๋ค๋ฅด๊ฒ, ๊ฐ์ ์ ์ฅํ๋ ํ๋๋ backing field๋ก ๋ฐ๋ก ๋๊ณ , getter, setter ๋ฉ์๋๋ก์จ ์ทจ๊ธ๋๋ ๊ฑธ๋ก ์๊ณ ์์ต๋๋ค.
๊ทธ๋ฌ๋ค ๋ณด๋ ์ธ์คํด์ค ๋ณ์๋ก ์ ์ธํ๋ ๊ฒ๊ณผ, ๋ฉ์๋๋ก ๋ฐ๋ก ์ ์ธํ๋ ๊ฒ์ด ๋ณ ์ฐจ์ด๊ฐ ์์ด๋ณด์ด๊ณ , ๊ฒฐ๊ตญ isDealer
์ ๊ฐ์ ๊ฒ๋ค์ ํ๋๋ก ์ธ์ง? ๋ฉ์๋๋ก ์ถ์ถํด์ ์ธ์ง? ์ ๋ํด ์ด๋ค ๊ธฐ์ค์ ์ก๊ณ ์ฌ์ฉ์ ํ ์ง ์์ง๋ ๊ฒฐ์ ์ ๋ชป๋ด๋ ธ์ต๋๋ค. ใ
ใ
ใ
ํน์ ์ด์ ๋ํด ๊ฒฝ๋ก๋์ ์ด๋ค ๊ธฐ์ค์ ๊ฐ๊ณ ๊ณ์ ์ง๊ฐ ๊ถ๊ธํฉ๋๋ค!!
} | ||
|
||
private fun dealCardToGambler( | ||
gambler: Gambler, | ||
fun placeBet(gamblers: List<Gambler>) { |
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 ํด๋์ค ๋ด๋ถ์์๋ง ์ฌ์ฉ๋๋๋ ๋ฉ์๋๊ฐ์๋ฐ์.
์ ๊ทผ์ ํ์๋ฅผ private
๋ก ๋๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐
return gamblerResults.joinToString(separator = LINE_FEED) { gamblerResult -> | ||
val gambler = gamblerResult.gambler | ||
"${gambler.name}: ${createWinOrDefeatMessage(gamblerResult)}" | ||
fun printAllFinalProfit(blackjackResults: BlackjackResults) { |
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.
return false | ||
} | ||
override val isDealer: Boolean = false | ||
private var betAmount: Double = 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.
(๋ฐฐํ
) ๊ธ์ก ํํ์ ์์์ ์ ๋ถ์ ํ์ฑ
์ ๊ณ ๋ คํ์ฌ double ๋ณด๋ค๋ BigDecimal์ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค
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.
๋ฒ ํ ๊ธ์ก ๋ํ ๋์ด๊ณ ์ ํํด์ผ ํจ์ ์ธ์งํ์ง ๋ชปํ๋ค์ ๐ ๊ฒฝ๋ก๋ ๋ง์๋๋ก BigDecimal์ ์ด์ฉํ๋ ํธ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
dealer.isBlackjack() && gambler.isNotBlackjack() -> DEFEAT | ||
dealer.isBurst() -> WIN | ||
gambler.isBurst() -> DEFEAT | ||
gambler.isScoreLargerThan(dealer) -> WIN | ||
gambler.isScoreEqualTo(dealer) -> DRAW |
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.
ResultStatus๋ gambler์ ๊ธฐ์ค์์ ์ธก์ ๋๋ ๊ฒฐ๊ณผ์ธ๋ฏํ๊ตฐ์?
ํ์ค ์ธ๊ณ์์๋ ๋๋ฌ๊ฐ ๊ฒ์ ์ฐธ๊ฐ์๋ค์ ์นํจ๋ฅผ ํ๋จํด์ฃผ๋๋ฐ์.
๊ทธ์ ์ฐฉ์ํด์ ์นํจ๋ฅผ ํ๋จํ๋ ์ญํ ์ dealer ๊ฐ์ฒด์๊ฒ ์์ํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค
ResultStatus.WIN -> if (isBlackjack) { | ||
1.5 | ||
} else { | ||
1.0 | ||
} | ||
|
||
ResultStatus.DRAW -> 1.0 | ||
ResultStatus.DEFEAT -> -1.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.
ResultStatus
์ ๋ธ๋์ญ์ผ๋ก ์น๋ฆฌํ ์ผ์ด์ค๋ฅผ ์ถ๊ฐํ๊ณ ์ถ๊ฐ์ ์ผ๋ก 1.5, 1.0, -1.0 ๊ณผ ๊ฐ์ ๋ฐฐํ
์จ(?)์ ResultStatus์ ํ๋กํผํฐ๋ก ๋ฌ๋ณด๋ฉด ์ด๋จ๊น์?
์์ ๊ฐ์ด ๋ณ๊ฒฝํ๋ค๋ฉด ์ง๊ธ์ฒ๋ผ ํ๋์ฝ๋ฉ์ ํ๋ ์์๊ฐ ์ค์ด๋ค ๊ฒ ๊ฐ๊ณ ๋, ProfitMultiplier
๋ ์ ๊ฑฐ๊ฐ๋ฅํ ๊ฒ ๊ฐ์์์. ๐
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.
์ค ์ด๋ฐ ์ข์ ๋ฐฉ๋ฒ์ด..... ๋ฐ๋ก ์คํ์ ์ฎ๊ฒผ์ต๋๋ค!!
์๋ ํ์ธ์ ๊ฒฝ๋ก๋!
๋ง์ง๋ง ๋ฏธ์ ๋ ์ ๋ถํ๋๋ฆฝ๋๋ค ๐โโ๏ธ