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] : ๐Ÿš€ 4๋‹จ๊ณ„ - ๋ธ”๋ž™์žญ(๋ฒ ํŒ…) #703

Open
wants to merge 44 commits into
base: dlwnsgus777
Choose a base branch
from

Conversation

dlwnsgus777
Copy link

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜!!
๊ฐ•์˜ ์ข…๋ฃŒ ํ›„์—๋„ ๋ฆฌ๋ทฐํ•ด์ฃผ์‹ ๋‹ค๊ณ  ํ•˜์‹œ๋‹ˆ... ๊ทธ์ € ๊ฐ์‚ฌํ• ๋”ฐ๋ฆ„์ž…๋‹ˆ๋‹คใ… ใ… ใ…  ๐Ÿ‘

์™„์ฃผ๋ฅผ ๋ชฉํ‘œ๋กœ ๋‹ฌ๋ ค๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!!!

์ด๋ฒˆ ๋‹จ๊ณ„๋„ ์ž˜๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!!

๊ณ ๋ฏผํ•œ ๋ถ€๋ถ„

ํ•œ์ฐธ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ GameResult์—์„œ ํ•˜๋˜ ๊ฒฐ๊ณผ ๊ณ„์‚ฐ์€ Dealer์—๊ฒŒ ์œ„์ž„ํ•ด ๊ฒฐ๊ณผ๋ฅผ ๊ณ„์‚ฐํ•˜๋‹ˆ ํ›จ์”ฌ ์ˆ˜์›”ํ•จ์„ ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค!
๊ทธ๋Ÿฌ๋‚˜ ๊ฐ์ฒด ๊ฐ„์˜ ์ฑ…์ž„? ์—ญํ• ์ด ์ž˜ ๋‚˜๋ˆ„์–ด์ง€์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค...
ํ•˜์ง€๋งŒ ์–ด๋””์„œ๋ถ€ํ„ฐ ์†๋Œ€๋‚˜๊ฐ€์•ผํ• ์ง€ ๊ฐ์ด ์„œ์ง€ ์•Š์•„ ๋ฆฌ๋ทฐ์˜ ํž˜์„ ๋นŒ๋ ค๋ณด๋ ค pr๋“œ๋ ค๋ด…๋‹ˆ๋‹คใ…Žใ…Ž

dlwnsgus777 and others added 30 commits December 5, 2023 22:44
Copy link
Member

@wisemuji wisemuji left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ์ค€ํ˜„๋‹˜!

๊ตฌํ˜„์„ ์ž˜ ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ’ฏ ๊น”๋”ํ•œ ๊ตฌํ˜„์ด ์ข‹์•˜์Šต๋‹ˆ๋‹ค.
ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋“ค์ด ์ง๊ด€์ ์œผ๋กœ ๋ณ€ํ•œ ๋ชจ์Šต์ด ์ธ์ƒ์ ์ด๋„ค์š” ๐Ÿ‘
๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๋งŒํ•œ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‹ฌ์•˜์œผ๋‹ˆ ํ™•์ธํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ธฐํ•œ์ด ์ง€๋‚ฌ๋Š”๋ฐ๋„ ๋ฏธ์…˜ ์ง„ํ–‰ํ•˜์‹œ๋Š” ๋ชจ์Šต์ด ๋Œ€๋‹จํ•˜์‹ญ๋‹ˆ๋‹ค!
๊ถ๊ธˆํ•œ ์ ์ด๋‚˜ ๋…ผ์˜ํ•˜๊ณ  ์‹ถ์€ ๋‚ด์šฉ์ด ์žˆ์œผ๋ฉด ์–ธ์ œ๋“  DM ์ฃผ์„ธ์š”! ๐Ÿ™ ๐Ÿ’ช

Copy link
Member

Choose a reason for hiding this comment

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

๋‹ค์Œ ์ฝ”๋ฉ˜ํŠธ์— ๋Œ€ํ•ด ๊ณ ๋ฏผํ•ด๋ณด์„ธ์š” ๐Ÿ™‚
#656 (comment)

Comment on lines 15 to 20
val playerResult = mutableMapOf<Name, BettingAmount>()

val (winCount, loseCount) = when {
dealer.isBust -> players.partition { !it.isBust }
else -> players.partition { it.resultScore() < dealer.resultScore() }
players.forEach {
val result = dealer.matchingScore(it)
playerResult[it.name] = it.status.calculateBettingAmount(result, it.bettingAmount)
}
Copy link
Member

Choose a reason for hiding this comment

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

mutableMapOf ์‚ฌ์šฉ ์—†์ด players.map { ... } ๋งŒ์œผ๋กœ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

companion object {
private const val WIN: String = "์Šน"
private const val LOSE: String = "ํŒจ"
resultMap = mapOf(Name("๋”œ๋Ÿฌ") to dealer.bettingAmount) + playerResult
Copy link
Member

Choose a reason for hiding this comment

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

๋”œ๋Ÿฌ์˜ ์ด๋ฆ„์€ ์ถœ๋ ฅํ•˜๋Š” ์ž…์žฅ์—์„œ ๊ผญ ํ•„์š”ํ•œ ์š”์†Œ์ผ๊นŒ์š”? ๐Ÿค”
GameResult๋ฅผ ํ†ตํ•ด ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ์˜ ๊ณตํ†ต๋œ ๊ฒฐ๊ณผ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์ง€๋งŒ ๋ถˆํ•„์š”ํ•œ ๋”œ๋Ÿฌ์˜ Name ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.

๊ฐœ๋ฐœ์ž๋“ค๋งˆ๋‹ค ์˜๊ฒฌ์ด ๊ฐˆ๋ฆด ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์ค€ํ˜„๋‹˜์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?

import kotlin.math.roundToInt

@JvmInline
value class BettingAmount(
Copy link
Member

Choose a reason for hiding this comment

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

value class ํ™œ์šฉ ๐Ÿ‘
operator overloading๋„ ์ ์šฉํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?
https://kotlinlang.org/docs/operator-overloading.html

Comment on lines +38 to +40
private fun isBlackjack(): Boolean {
return resultScore() == BLACKJACK
}
Copy link
Member

Choose a reason for hiding this comment

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

isBust์™€ isBlackjack()์€ ๊ฐ๊ฐ ํ”„๋กœํผํ‹ฐ, ํ•จ์ˆ˜๋กœ ์„ ์–ธ๋˜์—ˆ๋„ค์š”.

val isBust get() = resultScore() > BLACKJACK

์–ด๋–ค ์ƒํ™ฉ์—์„œ ํ”„๋กœํผํ‹ฐ๋ฅผ ์„ ํ˜ธํ•˜๊ณ  ํ•จ์ˆ˜๋ฅผ ์„ ํ˜ธํ•ด์•ผ ํ• ๊นŒ์š”?
๋‹ค์Œ ๊ธ€์ด ๋„์›€๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ์–ด์š”.

private val blackjackStrategy: BlackjackStrategy = BlackjackStrategy(scoreCalculator)
var bettingAmount: BettingAmount = BettingAmount(0)
Copy link
Member

Choose a reason for hiding this comment

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

matchingScore()์—์„œ ๋ฆฌํ„ดํ•  ๋•Œ BettingAmount ์ •๋ณด๋ฅผ ๊ฐ™์ด ๋ฐ˜ํ™˜ํ•œ๋‹ค๋ฉด ๊ตณ์ด variable์„ ์„ ์–ธํ•˜์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”

๋ชจ๋“  ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ž‘๊ฒŒ ์œ ์ง€ํ•œ๋‹ค.
3๊ฐœ ์ด์ƒ์˜ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง„ ํด๋ž˜์Šค๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

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

๋”๋ถˆ์–ด ์ง€๊ธˆ ๋”œ๋Ÿฌ์—์„œ ํ•˜๊ณ  ์žˆ๋Š” ์ผ์ด ๋„ˆ๋ฌด ๋งŽ์Šต๋‹ˆ๋‹ค.
matchingScore()๊ณผ ๊ฐ™์€ ๋กœ์ง์ด ๋”œ๋Ÿฌ์— ์žˆ๋Š”๊ฒŒ ์ ์ ˆํ• ๊นŒ์š”?
์Šน/ํŒจ ๊ณ„์‚ฐ ๋ฐ ๋ฐฐํŒ… ๊ธˆ์•ก ๊ฒฐ๊ณผ๋ฅผ ์–ป์–ด์˜ค๊ธฐ ์œ„ํ•ด์„œ ๋”œ๋Ÿฌ์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ๋ณ„๋„์˜ ๊ฐ์ฒด์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟ”๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

Comment on lines 21 to 30
changeStatus(cards)
}

private fun changeStatus(cards: List<BlackJackCard>) {
when {
!isFirstTurn(cards) && !isBust -> status = Stand()
!isFirstTurn(cards) && isBust -> status = Bust()
isFirstTurn(cards) && isBlackjack() -> status = Blackjack()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

๋งˆ์ง€๋ง‰ ๊ฐ•์˜๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ด๋Ÿฌํ•œ ๋กœ์ง๋„ ๊ฐ๊ฐ์˜ ์ƒํƒœ ๊ฐ์ฒด์—์„œ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฐ”๊ฟ”๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? (์ƒํƒœ ํŒจํ„ด)
์ด ์ฝ”๋ฉ˜ํŠธ ๋ฐ˜์˜์€ ์„ ํƒ์‚ฌํ•ญ์œผ๋กœ ์ง„ํ–‰ํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค ๐Ÿ™‚

@dlwnsgus777
Copy link
Author

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜!! ๊ฐ•์˜ ์ง€๋‚œ ํ›„์—๋„ ๋ฆฌ๋ทฐํ•ด์ฃผ์…”์„œ ๋Š˜ ๊ฐ์‚ฌํ•œ ๋งˆ์Œ์ž…๋‹ˆ๋‹ค ๐Ÿ™

ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ํ•˜๋ฉด์„œ ๊ถ๊ธˆํ•œ ์ ์ด ์ƒ๊ฒจ ๋ช‡๊ฐ€์ง€ ์งˆ๋ฌธ๋“œ๋ ค๋ด…๋‹ˆ๋‹ค!!

๋”œ๋Ÿฌ์˜ ์ด๋ฆ„์€ ์ถœ๋ ฅํ•˜๋Š” ์ž…์žฅ์—์„œ ๊ผญ ํ•„์š”ํ•œ ์š”์†Œ์ผ๊นŒ์š”? ๐Ÿค”
GameResult๋ฅผ ํ†ตํ•ด ํ”Œ๋ ˆ์ด์–ด์™€ ๋”œ๋Ÿฌ์˜ ๊ณตํ†ต๋œ ๊ฒฐ๊ณผ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์ง€๋งŒ ๋ถˆํ•„์š”ํ•œ ๋”œ๋Ÿฌ์˜ Name ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.
๊ฐœ๋ฐœ์ž๋“ค๋งˆ๋‹ค ์˜๊ฒฌ์ด ๊ฐˆ๋ฆด ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์ค€ํ˜„๋‹˜์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?

Name ๊ฐ์ฒด์ฒ˜๋Ÿผ ์›์‹œ๊ฐ’์„ ๊ฐ์‹ผ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ ๋‚˜๋ฆ„๋Œ€๋กœ์˜ ์ƒ๊ฐ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค!

  1. ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด
  2. ์ด๋ฆ„์— ๋Œ€ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์ด ์ƒ๊ฒผ์„ ๋•Œ ์ฑ…์ž„์„ Name์ด ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ์ข‹๋‹ค (Name ํด๋ž˜์Šค๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ)

๋˜ํ•œ ๋‹ค๋ฅธ Player ๊ฐ์ฒด์—์„œ๋„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ๋„ ํ•˜๊ณ  ๋ชจ๋“  ์›์‹œ๊ฐ’์„ ํฌ์žฅํ•˜๋ผ๋Š” ๊ณผ์ œ์˜ ์š”๊ตฌ์‚ฌํ•ญ์ด๊ธฐ๋„ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆํ•„์š”ํ•œ ๋”œ๋Ÿฌ์˜ Name ๊ฐ์ฒด ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋”๋ผ๋„ ๊ดœ์ฐฎ๋‹ค๋Š” ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!

๋‹ค๋งŒ ์ด์™€๊ฐ™์€ ์˜๋ฌธ์€ ์ฝ”๋“œ์˜ ๋ชจ์–‘ mapOf(Name("๋”œ๋Ÿฌ") to dealer.bettingAmount) ์ด๋Ÿฐ ํ˜•์‹ ๋•Œ๋ฌธ์— ์ƒ๊ฒจ๋‚ฌ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค

์ข€ ๋” ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•  ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!


๊ณ ๋ฏผํ•œ ๋ถ€๋ถ„

๋”œ๋Ÿฌ์— ๋Œ€ํ•œ ์ฑ…์ž„์ด ๋งŽ์•„ ๋ถ„๋ฆฌ๋ฅผ ํ•˜๋˜ ๋„์ค‘ GameResultGenerator ์™€ MatchingScoreCalculator ํด๋ž˜์Šค๊ฐ€ ํŒŒ์ƒ๋˜์—ˆ๋Š”๋ฐ
์ด ๋‘˜์˜ ๋กœ์ง์ด ๋น„์Šทํ•œ ๋ถ€๋ถ„์ด ๋งŽ์Šต๋‹ˆ๋‹ค... ๋‹จ์ˆœํžˆ return ๊ฐ’๋งŒ ๋‹ค๋ฅด๋‹ค๋Š” ๋Š๋‚Œ์ธ๋ฐ

์ด๋Ÿด ๋•Œ ์–ด๋–ค์‹์œผ๋กœ ๋ฆฌํŒฉํ„ฐ๋งํ• ์ง€ ๊ฐ์ด ์žกํžˆ์ง€ ์•Š์•„ ์งˆ๋ฌธ๋“œ๋ ค๋ด…๋‹ˆ๋‹ค!!

์ž˜๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!! ๐Ÿ˜ข

Copy link
Member

@wisemuji wisemuji left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ์ค€ํ˜„๋‹˜! ๋ฆฌ๋ทฐ ๋ฐ˜์˜์„ ์ž˜ ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ’ฏ

์กฐ๊ธˆ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๋„์ „์ ์ธ ๋‚ด์šฉ์„ ์ฝ”๋ฉ˜ํŠธ๋กœ ๋‹ฌ์•˜์œผ๋‹ˆ
ํŽธํ•˜๊ฒŒ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ๋งˆ์Œ๊ป ๋„์ „ํ•ด๋ณด์„ธ์š”.

์•„๋งˆ ๋‹ค์Œ ๋ฆฌ๋ทฐ ์š”์ฒญ์—์„œ๋Š” ๋จธ์ง€ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”.
๋งˆ์ง€๋ง‰๊นŒ์ง€ ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค ๐Ÿ’ช

import blackjack.participant.status.Blackjack
import blackjack.participant.status.Bust

object MatchingScoreCalculator {
Copy link
Member

Choose a reason for hiding this comment

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

๋”œ๋Ÿฌ์— ๋Œ€ํ•œ ์ฑ…์ž„์ด ๋งŽ์•„ ๋ถ„๋ฆฌ๋ฅผ ํ•˜๋˜ ๋„์ค‘ GameResultGenerator ์™€ MatchingScoreCalculator ํด๋ž˜์Šค๊ฐ€ ํŒŒ์ƒ๋˜์—ˆ๋Š”๋ฐ
์ด ๋‘˜์˜ ๋กœ์ง์ด ๋น„์Šทํ•œ ๋ถ€๋ถ„์ด ๋งŽ์Šต๋‹ˆ๋‹ค... ๋‹จ์ˆœํžˆ return ๊ฐ’๋งŒ ๋‹ค๋ฅด๋‹ค๋Š” ๋Š๋‚Œ์ธ๋ฐ
์ด๋Ÿด ๋•Œ ์–ด๋–ค์‹์œผ๋กœ ๋ฆฌํŒฉํ„ฐ๋งํ• ์ง€ ๊ฐ์ด ์žกํžˆ์ง€ ์•Š์•„ ์งˆ๋ฌธ๋“œ๋ ค๋ด…๋‹ˆ๋‹ค!!

#703 (comment)
์ด ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ƒํƒœ ํŒจํ„ด์œผ๋กœ ๋งŒ๋“ค์–ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ์ง€๊ธˆ๋„ Status ๊ฐ์ฒด๊ฐ€ ์žˆ์ง€๋งŒ ๋” ๋งŽ์€ ์ฑ…์ž„์„ ์ƒํƒœ๋กœ ์œ„์ž„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

Comment on lines 15 to 16
var bettingAmount = BettingAmount(0)
players.forEach {
Copy link
Member

Choose a reason for hiding this comment

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

Kotlin Collection์˜ fold, reduce ๋“ฑ์˜ API๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์ด ๋กœ์ง๋„ var ์„ ์–ธ ์—†์ด ๋ถˆ๋ณ€์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ์ฝ”๋ฉ˜ํŠธ๋Š” ์ฐธ๊ณ ๋งŒ ํ•ด์ฃผ์…”๋„ ์ข‹์Šต๋‹ˆ๋‹ค!

import blackjack.participant.Name

data class GameResult(
val resultMap: Map<Name, BettingAmount>
Copy link
Member

Choose a reason for hiding this comment

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

Name ๊ฐ์ฒด์ฒ˜๋Ÿผ ์›์‹œ๊ฐ’์„ ๊ฐ์‹ผ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ ๋‚˜๋ฆ„๋Œ€๋กœ์˜ ์ƒ๊ฐ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค!

  1. ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด
  2. ์ด๋ฆ„์— ๋Œ€ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์ด ์ƒ๊ฒผ์„ ๋•Œ ์ฑ…์ž„์„ Name์ด ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ์ข‹๋‹ค (Name ํด๋ž˜์Šค๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ)
    ๋˜ํ•œ ๋‹ค๋ฅธ Player ๊ฐ์ฒด์—์„œ๋„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ๋„ ํ•˜๊ณ  ๋ชจ๋“  ์›์‹œ๊ฐ’์„ ํฌ์žฅํ•˜๋ผ๋Š” ๊ณผ์ œ์˜ ์š”๊ตฌ์‚ฌํ•ญ์ด๊ธฐ๋„ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆํ•„์š”ํ•œ ๋”œ๋Ÿฌ์˜ Name ๊ฐ์ฒด ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋”๋ผ๋„ ๊ดœ์ฐฎ๋‹ค๋Š” ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!
    ๋‹ค๋งŒ ์ด์™€๊ฐ™์€ ์˜๋ฌธ์€ ์ฝ”๋“œ์˜ ๋ชจ์–‘ mapOf(Name("๋”œ๋Ÿฌ") to dealer.bettingAmount) ์ด๋Ÿฐ ํ˜•์‹ ๋•Œ๋ฌธ์— ์ƒ๊ฒจ๋‚ฌ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค
    ์ข€ ๋” ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•  ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

์ค€ํ˜„๋‹˜์ด ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด์˜ ๊ด€๊ณ„๋ฅผ ์ƒ์†์ด ์•„๋‹Œ, ์กฐํ•ฉ์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•ด์ฃผ์‹  ๋งŒํผ
์ด ๋‘˜์„ ๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ์ง€ ์•Š์„๊นŒ์š”?

์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด์š” ๐Ÿ™‚

Suggested change
val resultMap: Map<Name, BettingAmount>
data class GameResult(
val playerResultMap: Map<Name, BettingAmount>
val dealerResult: BettingAmount

๋˜ ๋งŒ์•ฝ GameResult๊ฐ€ playerResultMap๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ๊ตณ์ด dealerResult๋ฅผ ์™ธ๋ถ€์—์„œ ๊ณ„์‚ฐํ•ด์ค„ ํ•„์š” ์—†์ด GameResult๊ฐ€ ์ž์ฒด์ ์œผ๋กœ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”. ์ฆ‰, Generator ํด๋ž˜์Šค์˜ ํ•„์š” ์œ ๋ฌด๋„ ๊ฐ™์ด ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Comment on lines 44 to 51
// private fun playBlackJack(): GameResult {
// players.forEach {
// playerDraw(it)
// }
// dealerDraw(dealer)
//
// return GameResult(players, dealer)
// }
Copy link
Member

Choose a reason for hiding this comment

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

์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ•จ์ˆ˜๋Š” ์‚ญ์ œํ•ด์ฃผ์„ธ์š” ๐Ÿ™‚ VCS์— ๋ชจ๋‘ ๋‚จ์•„์žˆ์œผ๋‹ˆ ์ฝ”๋“œ๋ฅผ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์„ ํŽธํ•˜๊ฒŒ ์ƒ๊ฐํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค.

Comment on lines 38 to 40
players.forEach {
outputManager.printPlayerResultGame(it)
}
Copy link
Member

Choose a reason for hiding this comment

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

์ด๋Ÿฌํ•œ ๊ตฌ๋ฌธ์„ ํ•จ์ˆ˜ reference๋กœ ๋„˜๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Suggested change
players.forEach {
outputManager.printPlayerResultGame(it)
}
players.forEach(outputManager::printPlayerResultGame)

lambda๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ๊ณผ ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€ ์ฐธ๊ณ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธ€์„ ์†Œ๊ฐœํ•ด๋“œ๋ฆด๊ฒŒ์š” ๐Ÿ™‚
https://proandroiddev.com/kotlin-lambda-vs-method-reference-fdbd175f6845
์ฐธ๊ณ ๋กœ ์ €๋Š” ๊ฐ€๋Šฅํ•œ ๊ณณ์—์„œ๋Š” ๊ผญ ํ•จ์ˆ˜ reference๋ฅผ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ง€ํ–ฅํ•ฉ๋‹ˆ๋‹ค. lambda๋กœ ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ„๋„๋กœ ์กฐ์ž‘ํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ ํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜๋กœ ๋„˜๊ธด๋‹ค๋Š” ๊ฒƒ์„ ๋“œ๋Ÿฌ๋‚ผ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

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.

None yet

2 participants