-
Notifications
You must be signed in to change notification settings - Fork 278
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
[Step2] π 2λ¨κ³ - λΈλμ #656
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.
μλ νμΈμ μ€νλ!
ꡬνμ μ ν΄μ£Όμ
¨μ΅λλ€ π― κΉλν ꡬνμ΄ μ’μμ΅λλ€
κ³ λ―Όν΄λ³΄μλ©΄ μ’μλ§ν μ½λ©νΈλ₯Ό λ¬μμΌλ νμΈν΄μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€.
κΆκΈν μ μ΄λ λ Όμνκ³ μΆμ λ΄μ©μ΄ μμΌλ©΄ μΈμ λ DM μ£ΌμΈμ! π πͺ
var score = scoreCalculator.calcScore(it.cards) | ||
var drawAmount = -1 | ||
|
||
while (score <= 21 && drawAmount != 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.
GameManagerλ controller μν μ νλ κ°μ²΄λΌκ³ μ΄ν΄νμ΅λλ€
μ΄ λ‘μ§μ΄ controllerμ μλκ² μ μ ν κΉμ?
controller λ‘μ§μ΄ νλ‘κ·Έλ¨μ΄ 컀μ§λ©΄ 컀μ§μλ‘ κ³μ λμ΄λλκ² μ μ ν κΉμ?
μ μ ν κ°μ²΄μ μ±
μμΌλ‘ μμν μ μλ controller λ‘μ§μ΄ μλμ?
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.
μ΄ μ½λ©νΈλ₯Ό λ°μνλ©° Controllerμ μ± μμ λΆμ°μν€λκ±Έ μ΄λ° λ¨κ³ ν΅μ¬ λͺ©νλ‘ μΌμ보μμ£ γ γ
package blackjack.card | ||
|
||
enum class CardPattern(val patternName: String) { | ||
DIAMOND("λ€μ΄μ"), |
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.
λλ©μΈ κ°μ²΄μ λ·° μꡬμ¬νμ΄ ν¬ν¨λλκ² μ μ ν κΉμ? μλμ°¨ κ²½μ£Ό 5λ¨κ³ μꡬμ¬νμ μ°Έκ³ νμ¬ λλ©μΈ λ‘μ§κ³Ό λ·° λ‘μ§μ λͺ ννκ² λΆλ¦¬νκ³ , μμ‘΄ λ°©ν₯μ μ 리νλ©΄ μ΄λ¨κΉμ?
|
||
private fun joinPlayers() { | ||
val playerNames: List<String> = inputManager.inputPlayerNames() | ||
this.players = playerNames.map(::Player) |
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.
playersκ° λ€μ μ΄κΈ°νλ νμκ° μλ€λ©΄ κ°μ²΄ μμ± μ μ΄κΈ°νν μ μλλ‘ λ°κΏλ³΄λ©΄ μ΄λ¨κΉμ?
lateinit varμ μ¬μ©ν λμλ κΌ variableλ‘ μ μΈλ νμκ° μμμ§ κ³ λ―Όν΄λ³΄λ©΄ μ’κ² μ΅λλ€.
λΆλ³ν¨μ μ½νλ¦° μΈμ΄μ κ°μ₯ ν° μ₯μ μ€ νλλΌκ³ λ νλλ°μ, μ΄λ¬ν μ₯μ μ μ¨μ ν λ리기 μν΄ μ μ½νλ¦°μμλ κ°λ₯νλ©΄ varμ΄λ Mutable νμ μ¬μ©μ μ§μνλ €κ³ νκ³ μμ΅λλ€. π
|
||
card.filter { it is AceCard } | ||
.forEach { _ -> | ||
score = calcScore(score) |
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.
Kotlin Collectionμ fold λ±μ νμ©ν΄λ³΄λ©΄ μ΄λ¨κΉμ?
return score | ||
} | ||
|
||
private fun calcScore(score: Int): Int { |
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.
μ΄λ€ λ€μ΄λ°μ΄ λ€λ₯Έ κ°λ°μλ€λ μ΄ν΄νκΈ° μ¬μ΄ λ€μ΄λ°μΌκΉμ?
totalScore += when { | ||
(abs(plusMin - BEST_SCORE) < abs(plusMax - BEST_SCORE)) -> MIN_ACE_SCORE | ||
(abs(plusMin - BEST_SCORE) > abs(plusMax - BEST_SCORE)) -> MAX_ACE_SCORE | ||
else -> MIN_ACE_SCORE |
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.
λ€λ₯Έ κ°λ°μλ€λ μ΄ λ‘μ§μ λ³΄κ³ νλμ μ΄ν΄ν μ μμκΉμ?
val pattern: CardPattern | ||
) : BlackJackCard { | ||
override fun toString(): String { | ||
return "ace${pattern.patternName}" |
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.
λλ©μΈ κ°μ²΄μ λ·° μꡬμ¬νμ΄ ν¬ν¨λλκ² μ μ ν κΉμ?
|
||
companion object { | ||
private const val EMPTY_DECK_ERROR_MESSAGE: String = "μΉ΄λ λ±μ΄ λͺ¨λ μμ§λμμ΅λλ€." | ||
private fun initNormalCard(list: MutableList<BlackJackCard>) { |
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.
- μ΄ ν¨μκ° Companion Objectλ‘ κ΄λ¦¬λ νμκ° μμκΉμ?
- λΈλμμ μΉ΄λλ λ§€λ² μΈμ€ν΄μ€νλ νμκ° μμκΉμ?
μλ
νμΈμ 리뷰μ΄λ! νμ€ν controllerλ‘μ§κ³Ό λλ©μΈ λ‘μ§μ λΆλ¦¬νλ €λ€λ³΄λ μ½κ°μ(?) κ°μ΄ μ‘νκ°λ κ² κ°μμ΅λλ€! μ΄λ² 리뷰λ μλΆνλ립λλ€! π κ³ λ―Όν λΆλΆμ μλ₯Ό μμ²νλ λΆλΆμ λν΄ μ»¨νΈλ‘€λ¬κ° -> νλ μ΄μ΄μκ² μ μκ° μΌλ§μΈμ§ μμ² -> νλ μ΄μ΄λ μ μ κ³μ° ( μ΄λ κ² ν΄μ |
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.
μλ
νμΈμ μ€νλ!
리뷰 λ°μμ μ ν΄μ£Όμ
¨μ΅λλ€ π―
μ‘°κΈ κ³ λ―Όν΄λ³΄μλ©΄ μ’μ λ΄μ©κ³Ό μ§λ¬Έμ λν λ΅λ³μ μ½λ©νΈλ‘ λ¬μμΌλ λ€μ λ¨κ³ λ―Έμ μ§νν΄μ£Όμλ©΄μ κ°μ΄ λ°μν΄μ£Όμλ©΄ λ©λλ€!
λ€μ λ―Έμ λ νμ΄ν μ λλ€ π
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.
λ€μ λ¨κ³λΆν°λ λ€μ μλ£λ₯Ό μ°Έκ³ νμ¬ λΈλμ λλ©μΈμ λν΄ μ΄ν΄λλ₯Ό λμ¬λ³΄λ©΄ μ΄λ¨κΉμ?
- https://www.high1.com/casino/contents.do?key=1764
- https://namu.wiki/w/%EB%B8%94%EB%9E%99%EC%9E%AD(%EC%B9%B4%EB%93%9C%EA%B2%8C%EC%9E%84)
+) νΉν λ€μ λ΄μ©μ λ€μ΄λ°μ νμ©ν΄λ³΄μ
λ μ’μ κ² κ°μμ~
@@ -0,0 +1,3 @@ | |||
package blackjack.card | |||
|
|||
sealed interface BlackJackCard |
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.
λ±ν 컨벀μ μμ κ°μ νμ§λ μμ§λ§ κ°μΈμ μΌλ‘ sealed interface/class λ±μ ν νμΌμ λͺ¨μλλ κ²μ΄ κ°λ μ±μ΄ λλ€κ³ μκ°νλ νΈμ λλ€! μ°Έκ³ λ§ ν΄μ£ΌμΈμ γ γ
sealed interface BlackJackCard {
class AceCard(val pattern: CardPattern) : BlackJackCard
...
}
import blackjack.card.PictureCard | ||
import kotlin.math.abs | ||
|
||
class ScoreCalculator { |
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.
μ μλ₯Ό μμ²νλ λΆλΆμ λν΄
컨νΈλ‘€λ¬κ° -> νλ μ΄μ΄μκ² μ μκ° μΌλ§μΈμ§ μμ² -> νλ μ΄μ΄λ μ μ κ³μ° (ScoreCalculatorμ¬μ©)
μ΄λ κ² ν΄μ Playerκ° ScoreCalculator μμ‘΄μ±μ κ°μ§λλ‘ νλλ° μ΄λ°μμ νλ¦μ΄ 리뷰μ΄λμ΄ λ³΄μ ¨μ λ μμ°μ€λ¬μ΄μ§ κΆκΈν©λλ€!!
μ§κΈ λ¨κ³μμλ μ΄μν΄λ³΄μ΄μ§ μμ΅λλ€! λΈλμ λ―Έμ μ κ½μ λ°λ‘ λ€μ λ¨κ³μμ λλ¬μ νλ μ΄μ΄μ μ± μμ μ΄λ»κ² λΆν νλμ§μΈλ°μ, λ€μ λ¨κ³ λ―Έμ μ μ§ννμλ©΄μ μ’ λ κ³ λ―Όνμκ² λκ² λ€μ!
class ScoreCalculator { | ||
fun calcScore(card: List<BlackJackCard>): Int { | ||
return card.filterIsInstance<AceCard>().fold(calcScoreToNormalAndPictureCard(card)) { acc, _ -> | ||
calcAceScore(acc) |
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.
fold νμ© π
import kotlin.math.abs | ||
|
||
class ScoreCalculator { | ||
fun calcScore(card: List<BlackJackCard>): Int { |
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.
ν¨μ μ΄λ¦μ μ§μ λμλ μ½μ΄ (calc, sub λ±)λ₯Ό μ΅λν νμ©νμ§ μλ κ²μ΄ μ’μ΅λλ€. ν΅μμ μΌλ‘ νμ©λλ μ½μ΄(sum, println)κ° μλλΌλ©΄ νΌλμ μ€ μ μμ΄μ.
val list = mutableListOf<BlackJackCard>() | ||
initNormalCard(list) | ||
initPictureCard(list) | ||
initAceCard(list) | ||
|
||
list.shuffle() |
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.
κ°λ³ λΉ λ¦¬μ€νΈλ₯Ό λ§λ€μ΄ μ΄λ₯Ό μΌμΌν μ΄κΈ°ννλ μ μ°¨ μ§ν₯ μ€νμΌμ νμ©ν기보λ€, λΆλ³ 리μ€νΈ νμ λ§ νμ©νλ©΄ μ΄λ¨κΉμ? μλ₯Ό λ€μ΄ λ€μκ³Ό κ°μ΄ ν¨μ λ°νκ°μ λ§λ€μ΄λ³΄λκ±°μμ.
val cards: List<BlackJackCard> = normalCard() + pictureCard() + aceCard()
tip: Listμμλ shuffle()λμ shuffled()λ₯Ό νμ©νλ©΄ λ©λλ€.
private fun parsingCardPatternToString(cardPattern: CardPattern): String { | ||
return when (cardPattern) { | ||
CardPattern.DIAMOND -> "λ€μ΄μ" | ||
CardPattern.CLOVER -> "ν΄λ‘λ²" | ||
CardPattern.SPADE -> "μ€νμ΄λ" | ||
CardPattern.HEART -> "ννΈ" | ||
} | ||
} | ||
|
||
private fun parsingCardPictureToString(cardPicture: CardPicture): String { | ||
return when (cardPicture) { | ||
CardPicture.KING -> "K" | ||
CardPicture.JACK -> "J" | ||
CardPicture.QUEEN -> "Q" | ||
} | ||
} |
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.
UI λ‘μ§ λΆλ¦¬ π
μλ νμΈμ 리뷰μ΄λ!! μλΆνλ립λλ€! π
μ°Έκ³ λ‘ μ΄λ² μ½νλ¦° ν΄λ¦°μ½λ With TDDμμμ λͺ©νλ λ€μκ³Ό κ°μ΅λλ€! π
κ³ λ―Όν λΆλΆ
λλ¦λλ‘ κ³ λ―Όμ νκΈ΄ νμ§λ§ κ°μ²΄λ€μ νλ ₯μ λν΄μ μμ‘΄κ΄κ³λ₯Ό μ€μ νλλ° κ°μ μ‘μ§ λͺ»ν΄ λ§μ΄ λ―Έν‘νλ κ² κ°μ΅λλ€!!