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

๐Ÿš€ 4๋‹จ๊ณ„ - ๋ธ”๋ž™์žญ(๋ฒ ํŒ…) #826

Open
wants to merge 17 commits into
base: seolyoungkim
Choose a base branch
from

Conversation

SeolYoungKim
Copy link

์•ˆ๋…•ํ•˜์„ธ์š” ๊ฒฝ๋ก๋‹˜!
๋งˆ์ง€๋ง‰ ๋ฏธ์…˜๋„ ์ž˜ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๐Ÿ™‡โ€โ™‚๏ธ

Copy link

@Rok93 Rok93 left a comment

Choose a reason for hiding this comment

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

์„ค์˜๋‹˜ ๋ฆฌ๋ทฐ ์š”์ฒญ ์ฃผ์‹ ๊ฑธ ๋†“์น˜๊ณ ์žˆ์–ด์„œ ๋ฆฌ๋ทฐ๊ฐ€ ๋งŽ์ด ๋Šฆ์—ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿฅฒ
๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์ด๋‹ˆ ์กฐ๊ธˆ๋งŒ ๋” ํž˜๋‚ด์„œ ๋ฏธ์…˜ ๋งˆ๋ฌด๋ฆฌ ์ง€์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๋ช‡๋ช‡ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ๋‘์—ˆ๋Š”๋ฐ, ํ™•์ธํ•ด์„œ ์ˆ˜์ • ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”. ๐Ÿ™

README.md Outdated
Comment on lines 99 to 103
- [] ๋ฌด์Šน๋ถ€์ธ ๊ฒฝ์šฐ ๊ฒœ๋ธ”๋Ÿฌ๊ฐ€ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋Œ๋ ค๋ฐ›๋Š”๋‹ค
- [] ๊ฒœ๋ธ”๋Ÿฌ๊ฐ€ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋ฐ›๋Š”๋‹ค
- [] ๋”œ๋Ÿฌ๊ฐ€ 21์„ ์ดˆ๊ณผํ•˜๋ฉด ๊ฒœ๋ธ”๋Ÿฌ๋“ค์ด ์Šน๋ฆฌํ•˜๋ฏ€๋กœ ๊ฒœ๋ธ”๋Ÿฌ๋“ค์€ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋Œ๋ ค๋ฐ›๋Š”๋‹ค
- [] ๋”œ๋Ÿฌ๊ฐ€ 21์  ์ดํ•˜์ด๊ณ  ๊ฒœ๋ธ”๋Ÿฌ๊ฐ€ ๋”œ๋Ÿฌ๋ณด๋‹ค ์ ์ˆ˜๊ฐ€ ๋†’์œผ๋ฉด ์Šน๋ฆฌํ•˜๋ฏ€๋กœ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋Œ๋ ค๋ฐ›๋Š”๋‹ค
- [] ๊ฒœ๋ธ”๋Ÿฌ์˜ ์นด๋“œ๊ฐ€ 2์žฅ์ด๊ณ  ๋ธ”๋ž™์žญ(ํ•ฉ์ด 21)์ธ ๊ฒฝ์šฐ 1.5๋ฐฐ ๋ฐ›๋Š”๋‹ค
Copy link

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 }
Copy link

Choose a reason for hiding this comment

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

extractDealer, extractGamblers ๋ฉ”์„œ๋“œ๋„ ํƒ€์ž…๋Œ€์‹ ์— isDealer ํ•„๋“œ๋กœ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ
๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ํƒ€์ž… ๋Œ€์‹ ์— ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ํ•„ํ„ฐ๋งํ•˜๋„๋ก ๋ณ€๊ฒฝํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

Copy link
Author

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) { "๊ฒŒ์ž„ ๋‚ด ๋”œ๋Ÿฌ๋Š” ํ•œ๋ช…๋งŒ ์ฐธ์—ฌ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค." }
Copy link

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
Copy link

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
Copy link

Choose a reason for hiding this comment

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

๋ธ”๋ž™์žญ 4๋‹จ๊ณ„์—๋Š” 3๊ฐœ ์ด์ƒ์˜ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง„ ํด๋ž˜์Šค๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค๋ผ๋ฏ„ ๋ฏธ์…˜ ์š”๊ตฌ์‚ฌํ•ญ์ด ์žˆ๋Š”๋ฐ์š”.

๋ฌผ๋ก  ์ฝ๊ธฐ์ „์šฉ ํ”„๋กœํผํ‹ฐ์˜ ๊ฒฝ์šฐ์—๋Š” ์œ„์—์„œ ์–ธ๊ธ‰ํ•˜๋Š” ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜ ๊ฐœ๋…๊ณผ๋Š” ๋‹ค๋ฅด๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€๋งŒ, ์œ„์˜ ๋ฏธ์…˜ ์š”๊ตฌ์‚ฌํ•ญ์€ ๊ฐ€๊ธ‰์  ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์„ ์–ธํ•˜์ง€ ๋ง๋ผ๋Š” ์˜๋„๋ฅผ ๋‚ดํฌํ•˜๊ณ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”. ๐Ÿ˜ƒ
๊ฐœ์ธ์ ์œผ๋กœ isDealer์˜ ๊ฒฝ์šฐ์—๋Š” ๊ผญ ํ•„๋“œ๋กœ ์„ ์–ธํ•  ํ•„์š” ์—†์ด ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋ฅผ ๋‘๊ณ , ๊ฐ ๊ตฌํ˜„์ฒด์—์„œ ์žฌ์ •์˜ํ•ด๋„ ์ถฉ๋ถ„ํ•  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์„ค์˜๋‹˜์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”? ๐Ÿค”

Copy link
Author

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>) {
Copy link

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) {
Copy link

Choose a reason for hiding this comment

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

image

์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ฅด๋ฉด ์†Œ์ˆซ์ ์€ ๋…ธ์ถœํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด๋„ค์š”. ๐Ÿค”

return false
}
override val isDealer: Boolean = false
private var betAmount: Double = 0.0
Copy link

Choose a reason for hiding this comment

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

(๋ฐฐํŒ…) ๊ธˆ์•ก ํ‘œํ˜„์€ ์†Œ์ˆ˜์ ์˜ ๋ถ€์ •ํ™•์„ฑ์„ ๊ณ ๋ คํ•˜์—ฌ double ๋ณด๋‹ค๋Š” BigDecimal์„ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๐Ÿค”

Copy link
Author

Choose a reason for hiding this comment

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

๋ฒ ํŒ…๊ธˆ์•ก ๋˜ํ•œ ๋ˆ์ด๊ณ  ์ •ํ™•ํ•ด์•ผ ํ•จ์„ ์ธ์ง€ํ•˜์ง€ ๋ชปํ–ˆ๋„ค์š” ๐Ÿ˜… ๊ฒฝ๋ก๋‹˜ ๋ง์”€๋Œ€๋กœ BigDecimal์„ ์ด์šฉํ•˜๋Š” ํŽธ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Comment on lines 11 to 15
dealer.isBlackjack() && gambler.isNotBlackjack() -> DEFEAT
dealer.isBurst() -> WIN
gambler.isBurst() -> DEFEAT
gambler.isScoreLargerThan(dealer) -> WIN
gambler.isScoreEqualTo(dealer) -> DRAW
Copy link

Choose a reason for hiding this comment

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

ResultStatus๋Š” gambler์˜ ๊ธฐ์ค€์—์„œ ์ธก์ •๋˜๋Š” ๊ฒฐ๊ณผ์ธ๋“ฏํ•˜๊ตฐ์š”?

ํ˜„์‹ค ์„ธ๊ณ„์—์„œ๋Š” ๋”œ๋Ÿฌ๊ฐ€ ๊ฒŒ์ž„ ์ฐธ๊ฐ€์ž๋“ค์˜ ์ŠนํŒจ๋ฅผ ํŒ๋‹จํ•ด์ฃผ๋Š”๋ฐ์š”.
๊ทธ์— ์ฐฉ์•ˆํ•ด์„œ ์ŠนํŒจ๋ฅผ ํŒ๋‹จํ•˜๋Š” ์—ญํ• ์„ dealer ๊ฐ์ฒด์—๊ฒŒ ์œ„์ž„ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๐Ÿค”

Comment on lines 6 to 13
ResultStatus.WIN -> if (isBlackjack) {
1.5
} else {
1.0
}

ResultStatus.DRAW -> 1.0
ResultStatus.DEFEAT -> -1.0
Copy link

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๋„ ์ œ๊ฑฐ๊ฐ€๋Šฅํ•  ๊ฒƒ ๊ฐ™์•„์„œ์š”. ๐Ÿ˜ƒ

Copy link
Author

Choose a reason for hiding this comment

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

์˜ค ์ด๋Ÿฐ ์ข‹์€ ๋ฐฉ๋ฒ•์ด..... ๋ฐ”๋กœ ์‹คํ–‰์— ์˜ฎ๊ฒผ์Šต๋‹ˆ๋‹ค!!

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