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: 블랙잭 #481

Open
wants to merge 9 commits into
base: g1063114
Choose a base branch
from
Open

Step2: 블랙잭 #481

wants to merge 9 commits into from

Conversation

g1063114
Copy link

안녕하세요 리뷰어님!

블랙잭 구현이 생각보다 어려워서... 오래걸렸습니다

테스트를 어떤 방향으로 작성해야 하는지 피드백 부탁드립니다!

감사합니다!

@Flamme1004K
Copy link

스크린샷 2023-06-26 오전 12 05 43

실행에 대한 부분이 제외되었군요. 해당 부분에 대해서 구현 후에 다시 리뷰요청 부탁드립니다.

Copy link

@Flamme1004K Flamme1004K left a comment

Choose a reason for hiding this comment

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

안녕하세요!

리뷰 요청 감사합니다! 하지만 아직 미완성인 것 같아 로직에 대한 피드백은 못 드릴 것 같습니다.

완성 후에 리뷰 요청 부탁드립니다.

화이팅입니다!

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class BlackjackTest {

Choose a reason for hiding this comment

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

테스트를 만드는데에 가장 좋은 방법은 현재 만들어 놓은 도메인 클래스에 대한 검증에 대한 TODO List를 만들고 하나씩 만드는게 좋다고 생각합니다.

BlackjackTest 안에 모든 테스트를 만드시지말고, 각 도메인 클래스에 대한 단위 테스트를 만들어보시길 바랍니다.

링크

Choose a reason for hiding this comment

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

해당 부분에 대해 다시 한번 숙지하시고 테스트 케이스를 작성해 보세요.

Copy link

@Flamme1004K Flamme1004K left a comment

Choose a reason for hiding this comment

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

안녕하세요!

블랙잭 미션 구현 잘하셨습니다.

몇 가지 코멘트를 드렸으니, 확인 부탁드릴게요~ 😊

화이팅입니다!

Comment on lines 12 to 15
val playerNames = input.initGamePlayer()
val player1 = Player(name = playerNames.first())
val player2 = Player(name = playerNames.last())
val players = listOf(player1, player2)

Choose a reason for hiding this comment

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

여러명의 플레이어가 진행할 수 있도록 만들어주세요.

Comment on lines 22 to 29
players.forEach { player ->
while (player.isGetCardPossible()) {
val playerChoice = input.playerGetCard(player.name)
if (playerChoice == "n") break
game.giveCard(player)
output.checkPlayerCard(listOf(player))
}
}

Choose a reason for hiding this comment

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

  • indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다.
    요구 사항에 맞게 변경해볼까요?

}

output.showResult(players)
}

Choose a reason for hiding this comment

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

lint 체크 부탁드립니다.

val playerChoice = input.playerGetCard(player.name)
if (playerChoice == "n") break
game.giveCard(player)
output.checkPlayerCard(listOf(player))

Choose a reason for hiding this comment

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

플레이어만 넘길 수 없을까요?

players.forEach { player ->
while (player.isGetCardPossible()) {
val playerChoice = input.playerGetCard(player.name)
if (playerChoice == "n") break

Choose a reason for hiding this comment

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

플레이어의 상태로 게임 진행을 체크할 수 있지 않을까요?

package blackjack.domain

class CardDeck(
val deck: MutableList<Card> = cardDeck.shuffled().toMutableList()

Choose a reason for hiding this comment

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

해당 카드는 외부에서는 수정이 가능하죠. 외부에서는 수정이 불가능하도록 만들어볼까요?

}

companion object {
val cardDeck = CardType.values().flatMap { type ->

Choose a reason for hiding this comment

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

CardDeck에서만 사용하는 부분이여서 private을 추가해야하지 않을까하네요~

Comment on lines 8 to 12
fun status(status: PlayerStatus, score: Int): PlayerStatus {
if (score == BLACK_JACK_SCORE) return BLACK_JACK
if (score > BLACK_JACK_SCORE) return END
if (status != STAY && score < BLACK_JACK_SCORE) return GET
return STAY

Choose a reason for hiding this comment

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

블랙잭은 stay, blackjack, bust, hit이 있습니다.

4개의 상태로 리팩토링 해볼까요?

@@ -0,0 +1,12 @@
package blackjack.domain

class Scores(

Choose a reason for hiding this comment

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

scores와 score는 numberType만 사용을 하는 것 같네요. 과연 해당 클래스가 필요한지 생각해보세요.

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class BlackjackTest {

Choose a reason for hiding this comment

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

해당 부분에 대해 다시 한번 숙지하시고 테스트 케이스를 작성해 보세요.

Copy link

@Flamme1004K Flamme1004K 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.view.OutputView

class BlackjackGame(
val player: List<Player>,

Choose a reason for hiding this comment

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

일급 컬렉션으로 감싸볼까요?

Comment on lines +14 to +17
player.cards.card.forEach {
player.updateScore(it)
player.updateStatus()
}

Choose a reason for hiding this comment

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

player.cards.card를 줄여볼까요?

Comment on lines +21 to +29
private fun initCard(player: Player, count: Int = INIT_CARD_COUNT) {
val randomCards = deck.getRandomCard(count)
player.cards.initCard(randomCards)
}

fun giveFirstRandomCard(player: Player, count: Int = GIVE_CARD_COUNT) {
val randomCards = deck.getRandomCard(count).first()
player.receiveCard(randomCards)
}

Choose a reason for hiding this comment

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

두 함수를 합칠 수 있어보이네요.

player.receiveCard(randomCards)
}

fun choiceTurn(player: Player, input: InputView, output: OutputView) {

Choose a reason for hiding this comment

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

view 영역 class가 domain class까지 들어와버렸네요.

view 영역이 domain class까지 들어오지 못하도록 해주세요.

deck: List<Card> = cardDeck.shuffled()
) {
private val deck: MutableList<Card> = deck.shuffled().toMutableList()
fun getRandomCard(count: Int): MutableList<Card> {

Choose a reason for hiding this comment

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

MutableList는 외부에서 수정이 가능해요. 외부에서는 수정 못하도록 변경해볼까요?

Comment on lines +34 to +48
fun updateScore(card: Card) {
val cardScore = card.number.score
val calculateScore = score.flatMap { value ->
if (card.number == NumberType.ACE) {
cardScore.scores.map { value + it.value }
} else {
listOf(value + cardScore.scores.first().value)
}
}

if (isGetCardPossible()) {
score.clear()
score.add(calculateScore.min())
}
}

Choose a reason for hiding this comment

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

스크린샷 2023-06-29 오후 9 22 25

테스트 케이스가 실패했네요. 다시 구현 부탁드립니다.

companion object {
const val BLACK_JACK_SCORE = 21
fun status(status: PlayerStatus, score: Int): PlayerStatus {
if (score == BLACK_JACK_SCORE) return BLACK_JACK

Choose a reason for hiding this comment

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

과연 Socre가 21이라면 블랙잭일까요? 다른 룰은 없을까요?

require(choice == CHOICE_NO || choice == CHOICE_YES) {
"y랑 n으로만 선택할 수 있습니다."
}
return if (choice == CHOICE_YES) CHOICE_YES else CHOICE_NO

Choose a reason for hiding this comment

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

문자열보다 true/false로 반환하는게 좋지 않을까요?

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class PlayerTest {

Choose a reason for hiding this comment

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

플레이어에 대한 상태 변경 테스트도 추가해야하지 않을까요?

Comment on lines +15 to +29
fun `카드의 합이 21이 되면 블랙잭이다`() {
val name = "홍길동"
val card = Cards(
mutableListOf(
Card(NumberType.ACE, CardType.DIAMOND),
Card(NumberType.KING, CardType.SPADE),
Card(NumberType.QUEEN, CardType.SPADE)
)
)
val player = Player(name = name)
card.card.forEach { player.receiveCard(it) }

player.score.first() shouldBe 21
player.isBlackJack() shouldBe true
}

Choose a reason for hiding this comment

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

블랙잭 게임의 메서드로만 진행이 되도록 테스트케이스를 작성해보세요.

@Flamme1004K
Copy link

추가로 커밋 단위도 리팩토링에 대한 단위로 나눠주시길 바랍니다.

한번에 커밋하면 어떻게 리팩토링을 했느냐를 못보기 때문입니다.

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