-
Notifications
You must be signed in to change notification settings - Fork 312
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
base: dlwnsgus777
Are you sure you want to change the base?
Changes from all commits
585c554
60c5695
3fb5c38
8deccc4
81a9b87
dbc4ac9
ba515fe
821edf8
99c2a82
7596635
f91a9bd
09a86f9
f9ffe93
8debf0c
532524d
f24fb80
9f18bcc
0742d5c
772fafc
d631fb5
dc12e12
85a1efb
3464f6a
243166d
ad1a372
e90f8a6
af98d6a
68ed8cb
46af015
353af0a
cbf31f3
6a46496
9caaa16
9eee8bb
b662b36
c772fe8
a61b188
2ca702c
3693ab2
4ebdeb7
9067668
70b8d6c
cfc087f
1edce57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package blackjack.participant | ||
|
||
import kotlin.math.roundToInt | ||
|
||
@JvmInline | ||
value class BettingAmount( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value class ํ์ฉ ๐ |
||
val amount: Int | ||
) { | ||
|
||
fun winToBlackjack(): BettingAmount { | ||
return BettingAmount((amount * 1.5).roundToInt()) | ||
} | ||
|
||
operator fun unaryMinus(): BettingAmount { | ||
return BettingAmount(amount * -1) | ||
} | ||
} | ||
|
||
infix operator fun BettingAmount.plus(bettingAmount: BettingAmount): BettingAmount { | ||
return BettingAmount(amount + bettingAmount.amount) | ||
} | ||
|
||
infix operator fun BettingAmount.minus(bettingAmount: BettingAmount): BettingAmount { | ||
return BettingAmount(amount - bettingAmount.amount) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
package blackjack.participant | ||
|
||
import blackjack.ScoreCalculator | ||
import blackjack.supoort.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 | ||
fun isBust(): Boolean { | ||
return 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() | ||
} | ||
} | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
package blackjack.participant | ||
|
||
import blackjack.ScoreCalculator | ||
import blackjack.card.BlackJackCard | ||
import blackjack.supoort.ScoreCalculator | ||
|
||
class Dealer( | ||
scoreCalculator: ScoreCalculator | ||
) { | ||
) { | ||
private val blackjackStrategy: BlackjackStrategy = BlackjackStrategy(scoreCalculator) | ||
|
||
var bettingAmount: BettingAmount = BettingAmount(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋๋ถ์ด ์ง๊ธ ๋๋ฌ์์ ํ๊ณ ์๋ ์ผ์ด ๋๋ฌด ๋ง์ต๋๋ค. |
||
val cards get() = blackjackStrategy.cards | ||
|
||
val isBust get() = blackjackStrategy.isBust | ||
val status get() = blackjackStrategy.status | ||
|
||
fun drawCard(cards: List<BlackJackCard>) { | ||
blackjackStrategy.drawCard(cards) | ||
|
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 | ||
} |
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) | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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 | ||
} | ||
} | ||
} |
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 | ||
} | ||
} | ||
} |
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 | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||
package blackjack.supoort | ||||||||||
|
||||||||||
import blackjack.participant.BettingAmount | ||||||||||
import blackjack.participant.Name | ||||||||||
|
||||||||||
data class GameResult( | ||||||||||
val resultMap: Map<Name, BettingAmount> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์คํ๋์ด ๋๋ฌ์ ํ๋ ์ด์ด์ ๊ด๊ณ๋ฅผ ์์์ด ์๋, ์กฐํฉ์ ํตํด ๊ตฌํํด์ฃผ์ ๋งํผ ์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ด์ ๐
Suggested change
๋ ๋ง์ฝ GameResult๊ฐ playerResultMap๋ฅผ ์๊ณ ์๋ค๋ฉด ๊ตณ์ด dealerResult๋ฅผ ์ธ๋ถ์์ ๊ณ์ฐํด์ค ํ์ ์์ด GameResult๊ฐ ์์ฒด์ ์ผ๋ก ํ๋จํ ์ ์์ ๊ฒ ๊ฐ์์. ์ฆ, Generator ํด๋์ค์ ํ์ ์ ๋ฌด๋ ๊ฐ์ด ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข๊ฒ ์ต๋๋ค. |
||||||||||
) |
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.
๋ค์ ์ฝ๋ฉํธ์ ๋ํด ๊ณ ๋ฏผํด๋ณด์ธ์ ๐
#656 (comment)