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

[Step2] πŸš€ 2단계 - λΈ”λž™μž­ #656

Merged
merged 35 commits into from
Nov 27, 2023

Conversation

dlwnsgus777
Copy link

@dlwnsgus777 dlwnsgus777 commented Nov 24, 2023

μ•ˆλ…•ν•˜μ„Έμš” λ¦¬λ·°μ–΄λ‹˜!! μž˜λΆ€νƒλ“œλ¦½λ‹ˆλ‹€! πŸ™

참고둜 이번 μ½”ν‹€λ¦° ν΄λ¦°μ½”λ“œ With TDDμ—μ„œμ˜ λͺ©ν‘œλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€! πŸ‘

  • μ½”ν‹€λ¦° 문법 μ΅μˆ™ν•΄μ§€κΈ°(μ½”ν‹€λ¦° λ‹΅κ²Œ)
  • μœ μ§€λ³΄μˆ˜ μš©μ΄ν•˜κ³ (κ°μ œμ§€ν–₯적인) ν…ŒμŠ€νŠΈν•˜κΈ° 쒋은 μ½”λ“œμ— λŒ€ν•΄ 감작기

κ³ λ―Όν•œ λΆ€λΆ„

λ‚˜λ¦„λŒ€λ‘œ 고민을 ν•˜κΈ΄ ν–ˆμ§€λ§Œ κ°μ²΄λ“€μ˜ ν˜‘λ ₯에 λŒ€ν•΄μ„œ μ˜μ‘΄κ΄€κ³„λ₯Ό μ„€μ •ν•˜λŠ”λ° 감을 μž‘μ§€ λͺ»ν•΄ 많이 λ―Έν‘ν–ˆλ˜ 것 κ°™μŠ΅λ‹ˆλ‹€!!

dlwnsgus777 and others added 24 commits November 17, 2023 22:15
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 μ£Όμ„Έμš”! πŸ™ πŸ’ͺ

var score = scoreCalculator.calcScore(it.cards)
var drawAmount = -1

while (score <= 21 && drawAmount != 0) {
Copy link
Member

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 둜직이 μžˆλ‚˜μš”?

Copy link
Member

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("닀이아"),
Copy link
Member

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

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)
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 등을 ν™œμš©ν•΄λ³΄λ©΄ μ–΄λ–¨κΉŒμš”?

return score
}

private fun calcScore(score: Int): Int {
Copy link
Member

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

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

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

Choose a reason for hiding this comment

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

  1. 이 ν•¨μˆ˜κ°€ Companion Object둜 관리될 ν•„μš”κ°€ μžˆμ„κΉŒμš”?
  2. λΈ”λž™μž­μ˜ μΉ΄λ“œλŠ” 맀번 μΈμŠ€ν„΄μŠ€ν™”λ  ν•„μš”κ°€ μžˆμ„κΉŒμš”?

@dlwnsgus777
Copy link
Author

dlwnsgus777 commented Nov 27, 2023

μ•ˆλ…•ν•˜μ„Έμš” λ¦¬λ·°μ–΄λ‹˜!
μ§ˆλ¬Έλ“œλ Έλ˜ λ‚΄μš©μ— λ§žλŠ” λͺ©ν‘œλ₯Ό μž‘μ•„μ£Όμ‹  점이 큰 λ„μ›€λ˜μ—ˆμŠ΅λ‹ˆλ‹€!!γ…Ž

ν™•μ‹€νžˆ controller둜직과 도메인 λ‘œμ§μ„ λΆ„λ¦¬ν•˜λ €λ‹€λ³΄λ‹ˆ 약간은(?) 감이 μž‘ν˜€κ°€λŠ” 것 κ°™μ•˜μŠ΅λ‹ˆλ‹€!

이번 리뷰도 μž˜λΆ€νƒλ“œλ¦½λ‹ˆλ‹€! πŸ™


κ³ λ―Όν•œ λΆ€λΆ„

점수λ₯Ό μš”μ²­ν•˜λŠ” 뢀뢄에 λŒ€ν•΄

μ»¨νŠΈλ‘€λŸ¬κ°€ -> ν”Œλ ˆμ΄μ–΄μ—κ²Œ μ μˆ˜κ°€ μ–Όλ§ˆμΈμ§€ μš”μ²­ -> ν”Œλ ˆμ΄μ–΄λŠ” 점수 계산 (ScoreCalculatorμ‚¬μš©)

μ΄λ ‡κ²Œ ν•΄μ„œ Playerκ°€ ScoreCalculator μ˜μ‘΄μ„±μ„ 가지도둝 ν–ˆλŠ”λ° μ΄λŸ°μ‹μ˜ 흐름이 λ¦¬λ·°μ–΄λ‹˜μ΄ 보셨을 λ•Œ μžμ—°μŠ€λŸ¬μš΄μ§€ κΆκΈˆν•©λ‹ˆλ‹€!!

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.

μ•ˆλ…•ν•˜μ„Έμš” μ€€ν˜„λ‹˜!
리뷰 λ°˜μ˜μ„ 잘 ν•΄μ£Όμ…¨μŠ΅λ‹ˆλ‹€ πŸ’―

쑰금 κ³ λ―Όν•΄λ³΄μ‹œλ©΄ 쒋을 λ‚΄μš©κ³Ό μ§ˆλ¬Έμ— λŒ€ν•œ 닡변을 μ½”λ©˜νŠΈλ‘œ λ‹¬μ•˜μœΌλ‹ˆ λ‹€μŒ 단계 λ―Έμ…˜ μ§„ν–‰ν•΄μ£Όμ‹œλ©΄μ„œ 같이 λ°˜μ˜ν•΄μ£Όμ‹œλ©΄ λ©λ‹ˆλ‹€!

λ‹€μŒ λ―Έμ…˜λ„ ν™”μ΄νŒ…μž…λ‹ˆλ‹€ πŸ™

Copy link
Member

Choose a reason for hiding this comment

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

λ‹€μŒ λ‹¨κ³„λΆ€ν„°λŠ” λ‹€μŒ 자료λ₯Ό μ°Έκ³ ν•˜μ—¬ λΈ”λž™μž­ 도메인에 λŒ€ν•΄ 이해도λ₯Ό 높여보면 μ–΄λ–¨κΉŒμš”?

+) 특히 λ‹€μŒ λ‚΄μš©μ€ 넀이밍에 ν™œμš©ν•΄λ³΄μ…”λ„ 쒋을 것 κ°™μ•„μš”~
image

@@ -0,0 +1,3 @@
package blackjack.card

sealed interface BlackJackCard
Copy link
Member

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

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

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

Choose a reason for hiding this comment

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

ν•¨μˆ˜ 이름을 지을 λ•Œμ—λŠ” μ•½μ–΄ (calc, sub λ“±)λ₯Ό μ΅œλŒ€ν•œ ν™œμš©ν•˜μ§€ μ•ŠλŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. ν†΅μƒμ μœΌλ‘œ ν™œμš©λ˜λŠ” μ•½μ–΄(sum, println)κ°€ μ•„λ‹ˆλΌλ©΄ ν˜Όλž€μ„ 쀄 수 μžˆμ–΄μš”.

Comment on lines +10 to +15
val list = mutableListOf<BlackJackCard>()
initNormalCard(list)
initPictureCard(list)
initAceCard(list)

list.shuffle()
Copy link
Member

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()λ₯Ό ν™œμš©ν•˜λ©΄ λ©λ‹ˆλ‹€.

Comment on lines +45 to +60
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"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

UI 둜직 뢄리 πŸ‘

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