Skip to content
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
585c554
refactor: ์ถœ๋ ฅ ํฌ๋งท ๋งž์ถ”๊ธฐ
dlwnsgus777 Dec 5, 2023
60c5695
feat: ์ ์ˆ˜ ๊ณ„์‚ฐ ๋ฒ„๊ทธ ์ˆ˜์ •
dlwnsgus777 Dec 5, 2023
3fb5c38
feat: ktlint
dlwnsgus777 Dec 5, 2023
8deccc4
feat: ๋ฉ”์„œ๋“œ ๋ช… ์ˆ˜์ •
dlwnsgus777 Dec 5, 2023
81a9b87
refactor: object ๋กœ ๋ณ€๊ฒฝ
dlwnsgus777 Dec 5, 2023
dbc4ac9
test: ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€
dlwnsgus777 Dec 5, 2023
ba515fe
refactor: default arguments ์‚ฌ์šฉ
dlwnsgus777 Dec 5, 2023
821edf8
doc: ์š”๊ตฌ์‚ฌํ•ญ ์ •๋ฆฌ
dlwnsgus777 Dec 5, 2023
99c2a82
feat: ๋ฒ ํŒ… ๊ธˆ์•ก ํด๋ž˜์Šค ์ƒ์„ฑ
dlwnsgus777 Dec 5, 2023
7596635
feat: ํด๋ž˜์Šค ์ด๋ฆ„ ์˜คํƒ€ ์ˆ˜์ •
dlwnsgus777 Dec 5, 2023
f91a9bd
feat: Player๊ฐ€ ๋ฒ ํŒ… ๊ธˆ์•ก์„ ๊ฐ€์ง€๋„๋ก ๊ฐœ๋ฐœ
dlwnsgus777 Dec 5, 2023
09a86f9
feat: ๋ฒ ํŒ… ๊ธˆ์•ก ์ž…๋ ฅ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
dlwnsgus777 Dec 6, 2023
f9ffe93
feat: ๋ธ”๋ž™์žญ ์ƒํƒœ ์ถ”๊ฐ€
dlwnsgus777 Dec 6, 2023
8debf0c
feat: ํžˆํŠธ ์ƒํƒœ ์ถ”๊ฐ€
dlwnsgus777 Dec 6, 2023
532524d
refactor: ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง
dlwnsgus777 Dec 6, 2023
f24fb80
feat: ์Šคํƒ ๋“œ ์ƒํƒœ ์ถ”๊ฐ€
dlwnsgus777 Dec 6, 2023
9f18bcc
feat: ๋ฒ„์ŠคํŠธ ์ƒํƒœ ์ถ”๊ฐ€
dlwnsgus777 Dec 6, 2023
0742d5c
refactor: ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง
dlwnsgus777 Dec 6, 2023
772fafc
doc: README.md update
dlwnsgus777 Dec 6, 2023
d631fb5
feat: ๋‹ค์Œ ์ž‘์—…์„ ์œ„ํ•œ ์ค‘๊ฐ„์ €์žฅ...
dlwnsgus777 Dec 6, 2023
dc12e12
feat: ์ ์ˆ˜ ๊ณ„์‚ฐ ๋กœ์ง ์ถ”๊ฐ€
Dec 7, 2023
85a1efb
feat: ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€
Dec 7, 2023
3464f6a
feat: ๋”œ๋Ÿฌ ๊ฐ์ฒด๊ฐ€ ํ”Œ๋ ˆ์ด์–ด ๊ฐ์ฒด์˜ ์ ์ˆ˜์™€ ์ž์‹ ์˜ ์ ์ˆ˜๋ฅผ ๋น„๊ตํ•˜๋„๋ก ์ˆ˜์ •
Dec 7, 2023
243166d
feat: lint ์ž‘์—… ๋ฐ ๊นจ์ง„ ํ…Œ์ŠคํŠธ ์ •๋ฆฌ
dlwnsgus777 Dec 7, 2023
ad1a372
feat: ๋ฒ ํŒ… ๊ธˆ์•ก ๊ณ„์‚ฐ ๋กœ์ง ์ถ”๊ฐ€
dlwnsgus777 Dec 7, 2023
e90f8a6
feat: ๋ฆฐํŠธ ์ •๋ฆฌ
dlwnsgus777 Dec 7, 2023
af98d6a
test: ๊นจ์ง„ ํ…Œ์ŠคํŠธ ์ •๋ฆฌ
dlwnsgus777 Dec 7, 2023
68ed8cb
feat: ์•ˆ์“ฐ๋Š” ์ฝ”๋“œ ์ •๋ฆฌ
dlwnsgus777 Dec 7, 2023
46af015
feat: isBust๋ฅผ Status๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋กœ ๋ณ€๊ฒฝ
dlwnsgus777 Dec 7, 2023
353af0a
feat: ktlint
dlwnsgus777 Dec 7, 2023
cbf31f3
feat: mutableMapOf ์‚ฌ์šฉ ์ œ๊ฑฐ
dlwnsgus777 Dec 9, 2023
6a46496
feat: isBust ํ•จ์ˆ˜๋กœ ๋ณ€๊ฒฝ
dlwnsgus777 Dec 9, 2023
9caaa16
feat: DSL๊ณผ operator ํ•จ์ˆ˜ ์‚ฌ์šฉ
dlwnsgus777 Dec 9, 2023
9eee8bb
feat: DSL ์ถ”๊ฐ€
dlwnsgus777 Dec 9, 2023
b662b36
feat: game package ์ƒ์„ฑ
dlwnsgus777 Dec 9, 2023
c772fe8
feat: test ์ผ€์ด์Šค ์ถ”๊ฐ€
dlwnsgus777 Dec 10, 2023
a61b188
feat: ๊ฒŒ์ž„๊ฒฐ๊ณผ ๊ณ„์‚ฐ์„ ์œ„ํ•œ GameResultGenerator ์˜ค๋ธŒ์ ํŠธ ์ถ”๊ฐ€
dlwnsgus777 Dec 10, 2023
2ca702c
feat: ktlint
dlwnsgus777 Dec 10, 2023
3693ab2
feat: ๋”œ๋Ÿฌ์˜ ์ ์ˆ˜ ๊ณ„์‚ฐ ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ๋กœ์šด ํด๋ž˜์Šค ์ถ”๊ฐ€
dlwnsgus777 Dec 10, 2023
4ebdeb7
feat: ํŒจํ‚ค์ง€ ๋ช… ๋ณ€๊ฒฝ game -> support
Dec 11, 2023
9067668
feat: ktlint
Dec 11, 2023
70b8d6c
feat: MatchingScoreCalculator ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ถ”๊ฐ€ ๋ฐ ์—ญํ•  ๋ถ„๋ฆฌ
Dec 11, 2023
cfc087f
feat: ktlint
Dec 11, 2023
1edce57
refactor: ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฐ˜์˜
Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- ์ž…๋ ฅ
- [x] ๊ฒŒ์ž„์— ์ฐธ์—ฌํ•  ์‚ฌ๋žŒ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.
- [x] ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋” ๋ฐ›์„์ง€ ๋ง์ง€ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.
- [x] ํ”Œ๋ ˆ์ด์–ด์˜ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

- ์ถœ๋ ฅ
- [x] ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์นด๋“œ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
Expand Down Expand Up @@ -37,6 +38,19 @@
- [x] ๋”œ๋Ÿฌ๋Š” ์ฒ˜์Œ์— ๋ฐ›์€ 2์žฅ์˜ ํ•ฉ๊ณ„๊ฐ€ 16์ดํ•˜๋ผ๋ฉด ๋ฐ˜๋“œ์‹œ ํ•œ์žฅ์˜ ์นด๋“œ๋ฅผ ๋ฐ›๋Š”๋‹ค.
- [x] 16์  ์ดํ•˜๋ฉด ๊ณ„์† ์นด๋“œ๋ฅผ ๋ฝ‘๋Š”๋‹ค.
- [x] 17์  ์ด์ƒ์ด๋ฉด ์นด๋“œ๋ฅผ ์ถ”๊ฐ€๋กœ ๋ฐ›์„ ์ˆ˜ ์—†๋‹ค.
- [x] ์ƒํƒœ๋ผ๋Š” ํด๋ž˜์Šค๊ฐ€ ์žˆ๋‹ค.
- [x] ํžˆํŠธ๋ผ๋Š” ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค
- [x] ํžˆํŠธ๋Š” ๋จผ์ € ๋ฐ›์€ ๋‘ ์žฅ์˜ ํ•ฉ์ด 21์— ๋ชป๋ฏธ์น˜๋Š” ๊ฒฝ์šฐ๋‹ค.
- [x] ๋ฒ„์ŠคํŠธ๋ผ๋Š” ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค.
- [x] ๋ฒ„์ŠคํŠธ๋Š” ์นด๋“œ ์ดํ•ฉ์ด 21์„ ๋„˜์€ ๊ฒฝ์šฐ๋‹ค.
- [] ์นด๋“œ๋ฅผ ์ถ”๊ฐ€๋กœ ๋ฝ‘์•„ 21์„ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ ๋ฐฐํŒ… ๊ธˆ์•ก์„ ๋ชจ๋‘ ์žƒ๋Š”๋‹ค.
- [] ๋”œ๋Ÿฌ๊ฐ€ ๋ฒ„์ŠคํŠธ๋ผ๋ฉด ๋‚จ์•„ ์žˆ๋Š” ํ”Œ๋ ˆ์ด์–ด๋“ค์€ ๋ฒ ํŒ… ๊ธˆ์•ก์„ ๋ฐ›๋Š”๋‹ค.
- [x] ์Šคํƒ ๋“œ๋ผ๋Š” ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค.
- [x] ์Šคํƒ ๋“œ๋Š” ๋” ์ด์ƒ ์นด๋“œ๋ฅผ ๋ฝ‘์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋‹ค.
- [x] ๋ธ”๋ž™์žญ ์ด๋ผ๋Š” ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค.
- [x] ์ฒ˜์Œ ๋ฐ›์€ ๋‘ ์žฅ์˜ ์นด๋“œ์˜ ์ด ํ•ฉ์ด 21์ด ๋˜๋Š” ๊ฒฝ์šฐ์ด๋‹ค.
- [] ๋ฒ ํŒ… ๊ธˆ์•ก์˜ 1.5๋ฐฐ๋ฅผ ๋”œ๋Ÿฌ์—๊ฒŒ ๋ฐ›๋Š”๋‹ค.
- [] ๋”œ๋Ÿฌ์™€ ํ”Œ๋ ˆ์ด์–ด ๋™์‹œ์— ๋ธ”๋ž™์žญ์ธ ๊ฒฝ์šฐ ํ”Œ๋ ˆ์ด์–ด๋Š” ๋ฒ ํŒ…ํ•œ ๊ธˆ์•ก์„ ๋Œ๋ ค๋ฐ›๋Š”๋‹ค.

## ์šฉ์–ด ์ •๋ฆฌ

Expand All @@ -45,4 +59,8 @@
- ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ฒ„์ŠคํŠธ ๋‹นํ•˜๋ฉด ํŒจ๋ฐฐ๊ฐ€ ํ™•์ •๋œ๋‹ค.
- ๋”œ๋Ÿฌ๊ฐ€ ๋ฒ„์ŠคํŠธ ๋‹นํ•˜๋ฉด ๊ทธ ์‹œ์ ๊นŒ์ง€ ๋‚จ์•„์žˆ๋Š” ๋ชจ๋“  ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์Šน๋ฆฌํ•œ๋‹ค.
- ๋ธ”๋ž™์žญ(Blackjack)
- Aํ•œ์žฅ๊ณผ 10, J, Q, L ๋กœ 21์„ ์ด๋ฃจ๋Š” ๊ฒฝ์šฐ ๋ฒ ํŒ… ๊ธˆ์•ก์˜ 1.5๋ฐฐ๋ฅผ ๋Œ๋ ค์ค€๋‹ค.
- Aํ•œ์žฅ๊ณผ 10, J, Q, L ๋กœ 21์„ ์ด๋ฃจ๋Š” ๊ฒฝ์šฐ ๋ฒ ํŒ… ๊ธˆ์•ก์˜ 1.5๋ฐฐ๋ฅผ ๋Œ๋ ค์ค€๋‹ค.
- ํžˆํŠธ(Hit)
- ๋จผ์ € ๋ฐ›์€ ๋‘ ์žฅ์˜ ํ•ฉ์ด 21์— ๋ชป๋ฏธ์น˜๋Š” ๊ฒฝ์šฐ
- ์Šคํƒ ๋“œ(Stand)
- ๋” ์ด์ƒ ์นด๋“œ๋ฅผ ๋ฝ‘์ง€ ์•Š๊ณ  ๋„˜์–ด๊ฐ„ ๊ฒฝ์šฐ
11 changes: 5 additions & 6 deletions src/main/kotlin/blackjack/GameManager.kt
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)

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blackjack

import blackjack.card.CardDeck
import blackjack.participant.BettingAmount
import blackjack.participant.Dealer
import blackjack.participant.Name
import blackjack.participant.Player
Expand All @@ -23,17 +24,16 @@ class GameManager(
players.forEach { it.drawCard(CardDeck.draw(FIRST_DRAW)) }
dealer.drawCard(CardDeck.draw(FIRST_DRAW))

outputManager.printFirstTurn2(players)
outputManager.printFirstTurn(players)
outputManager.printPlayersAndDealerCards(players, dealer)

val result = playBlackJack()

outputManager.printDealerResultGame(dealer)

players.forEach {
outputManager.printPlayerResultGame(it)
}

outputManager.printDealerResultGame(dealer)

outputManager.printResult(result)
}

Expand Down Expand Up @@ -62,15 +62,14 @@ class GameManager(
while (dealer.shouldDraw()) {
outputManager.printDealerCanDrawMessage()
dealer.drawCard(CardDeck.draw(DRAW_CARD))
outputManager.printDealerCards(dealer)
}
}

private fun playerChooseDraw(drawAmount: Int) = drawAmount > 0

private fun joinPlayers(): List<Player> {
val playerNames: List<String> = inputManager.inputPlayerNames()
return playerNames.map { Player(Name(it), ScoreCalculator()) }
return playerNames.map { Player(Name(it), BettingAmount(inputManager.inputBettingAmount(it))) }
}

private fun joinDealer(): Dealer {
Expand Down
25 changes: 7 additions & 18 deletions src/main/kotlin/blackjack/GameResult.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
package blackjack

import blackjack.participant.BettingAmount
import blackjack.participant.Dealer
import blackjack.participant.Name
import blackjack.participant.Player
import blackjack.participant.Result

class GameResult(
players: List<Player>,
dealer: Dealer
) {
val resultMap: Map<Name, Result>
val resultMap: Map<Name, BettingAmount>

init {
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 { ... } ๋งŒ์œผ๋กœ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!


val playerResult = mutableMapOf<Name, Result>().apply {
winCount.map { this[it.name] = Result.Win() }
loseCount.map { this[it.name] = Result.Lose() }
}

resultMap = mapOf(
Name("๋”œ๋Ÿฌ") to Result.DealerResult(winCount.size, loseCount.size)
) + playerResult
}

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 ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.

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

}
}
24 changes: 24 additions & 0 deletions src/main/kotlin/blackjack/participant/BettingAmount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package blackjack.participant

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

val amount: Int
) {
fun changeNegative(): BettingAmount {
return BettingAmount(amount * -1)
}

fun winToBlackjack(): BettingAmount {
return BettingAmount((amount * 1.5).roundToInt())
}

fun plusAmount(bettingAmount: BettingAmount): BettingAmount {
return BettingAmount(amount + bettingAmount.amount)
}

fun minusAmount(bettingAmount: BettingAmount): BettingAmount {
return BettingAmount(amount - bettingAmount.amount)
}
}
28 changes: 25 additions & 3 deletions src/main/kotlin/blackjack/participant/BlackjackStrategy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,45 @@ package blackjack.participant

import blackjack.ScoreCalculator
import blackjack.card.BlackJackCard
import blackjack.participant.status.Blackjack
import blackjack.participant.status.Bust
import blackjack.participant.status.Hit
import blackjack.participant.status.Stand
import blackjack.participant.status.Status

class BlackjackStrategy(
private val scoreCalculator: ScoreCalculator,
) {
var cards: List<BlackJackCard> = emptyList()
var status: Status = Hit()

val isBust get() = resultScore() > BUST
val isBust get() = resultScore() > BLACKJACK

fun drawCard(cards: List<BlackJackCard>) {
this.cards += cards
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.

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


private fun isFirstTurn(cards: List<BlackJackCard>): Boolean = cards.size == FIRST_TURN_DRAW

fun resultScore(): Int {
return scoreCalculator.calculateGameScore(cards)
}

private fun isBlackjack(): Boolean {
return resultScore() == BLACKJACK
}
Comment on lines +40 to +42
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

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


companion object {
private const val BUST: Int = 21
private const val BLACKJACK: Int = 21
private const val FIRST_TURN_DRAW: Int = 2
}
}
}
43 changes: 41 additions & 2 deletions src/main/kotlin/blackjack/participant/Dealer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package blackjack.participant

import blackjack.ScoreCalculator
import blackjack.card.BlackJackCard
import blackjack.participant.status.Blackjack
import blackjack.participant.status.Bust

class Dealer(
scoreCalculator: ScoreCalculator
) {
) {
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()๊ณผ ๊ฐ™์€ ๋กœ์ง์ด ๋”œ๋Ÿฌ์— ์žˆ๋Š”๊ฒŒ ์ ์ ˆํ• ๊นŒ์š”?
์Šน/ํŒจ ๊ณ„์‚ฐ ๋ฐ ๋ฐฐํŒ… ๊ธˆ์•ก ๊ฒฐ๊ณผ๋ฅผ ์–ป์–ด์˜ค๊ธฐ ์œ„ํ•ด์„œ ๋”œ๋Ÿฌ์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ๋ณ„๋„์˜ ๊ฐ์ฒด์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟ”๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?


val cards get() = blackjackStrategy.cards

val isBust get() = blackjackStrategy.isBust
val status get() = blackjackStrategy.status

fun drawCard(cards: List<BlackJackCard>) {
blackjackStrategy.drawCard(cards)
Expand All @@ -24,6 +27,42 @@ class Dealer(
return blackjackStrategy.resultScore() < MAX_DRAW_SCORE
}

fun matchingScore(player: Player): Result {
if (player.status is Blackjack) {
return when (status) {
is Blackjack -> Result.Lose
else -> {
bettingAmount = bettingAmount.minusAmount(
player.status.calculateBettingAmount(
Result.Win,
player.bettingAmount
)
)
return Result.Win
}
}
}

if (player.status is Bust) {
bettingAmount = bettingAmount.plusAmount(player.bettingAmount)
return Result.Lose
}

if (status is Bust) {
bettingAmount = bettingAmount.minusAmount(player.bettingAmount)
return Result.Win
}

return when (resultScore() > player.resultScore()) {
true -> {
bettingAmount = bettingAmount.plusAmount(player.bettingAmount)
Result.Lose
}

else -> Result.Win
}
}

companion object {
private const val MAX_DRAW_SCORE: Int = 17
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/blackjack/participant/Name.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ package blackjack.participant
@JvmInline
value class Name(
val value: String
)
) {
init {
require(value.isNotBlank()) { VALID_MESSAGE }
}

companion object {
private const val VALID_MESSAGE: String = "๋นˆ ๊ฐ’์€ ์ด๋ฆ„์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/blackjack/participant/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import blackjack.card.BlackJackCard

class Player(
val name: Name,
scoreCalculator: ScoreCalculator
val bettingAmount: BettingAmount = BettingAmount(0),
scoreCalculator: ScoreCalculator = ScoreCalculator()
) {
constructor(name: Name, scoreCalculator: ScoreCalculator) : this(name, BettingAmount(0), scoreCalculator)

private val blackjackStrategy: BlackjackStrategy = BlackjackStrategy(scoreCalculator)

val cards get() = blackjackStrategy.cards

val isBust get() = blackjackStrategy.isBust
val status get() = blackjackStrategy.status

fun drawCard(cards: List<BlackJackCard>) {
blackjackStrategy.drawCard(cards)
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/blackjack/participant/Result.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package blackjack.participant

sealed interface Result {
class Win : Result
class Lose : Result
class DealerResult(val win: Int, val lose: Int) : Result
object Win : Result
object Lose : Result
}
13 changes: 13 additions & 0 deletions src/main/kotlin/blackjack/participant/status/Blackjack.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package blackjack.participant.status

import blackjack.participant.BettingAmount
import blackjack.participant.Result

class Blackjack : Status {
override fun calculateBettingAmount(result: Result, bettingAmount: BettingAmount): BettingAmount {
return when(result) {
is Result.Win -> bettingAmount.winToBlackjack()
is Result.Lose -> BettingAmount(0)
}
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/blackjack/participant/status/Bust.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package blackjack.participant.status

import blackjack.participant.BettingAmount
import blackjack.participant.Result

class Bust : Status {
override fun calculateBettingAmount(result: Result, bettingAmount: BettingAmount): BettingAmount {
return bettingAmount.changeNegative()
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/blackjack/participant/status/Hit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package blackjack.participant.status

import blackjack.participant.BettingAmount
import blackjack.participant.Result

class Hit : Status {
override fun calculateBettingAmount(result: Result, bettingAmount: BettingAmount): BettingAmount {
return when (result) {
is Result.Win -> bettingAmount
is Result.Lose -> bettingAmount.changeNegative()
}
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/blackjack/participant/status/Stand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package blackjack.participant.status

import blackjack.participant.BettingAmount
import blackjack.participant.Result

class Stand : Status {
override fun calculateBettingAmount(result: Result, bettingAmount: BettingAmount): BettingAmount {
return when(result) {
is Result.Win -> bettingAmount
is Result.Lose -> bettingAmount.changeNegative()
}
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/blackjack/participant/status/Status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package blackjack.participant.status

import blackjack.participant.BettingAmount
import blackjack.participant.Result

interface Status {
fun calculateBettingAmount(result: Result, bettingAmount: BettingAmount): BettingAmount
}
6 changes: 6 additions & 0 deletions src/main/kotlin/blackjack/ui/InputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class InputManager {
return inputUserValue().replace("\\s".toRegex(), "").split(",")
}

fun inputBettingAmount(playerName: String): Int {
println()
println("${playerName}์˜ ๋ฒ ํŒ… ๊ธˆ์•ก์€?")
return inputUserValue().toInt()
}

private fun inputUserValue(): String {
val input = readln()
require(input.isNotBlank()) { INPUT_NOT_NULL_MESSAGE }
Expand Down
Loading