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

Open
wants to merge 17 commits into
base: sodp5
Choose a base branch
from
Open

Step2 - 블랙잭 #647

wants to merge 17 commits into from

Conversation

sodp5
Copy link

@sodp5 sodp5 commented Nov 21, 2023

안녕하세요!
최대한 룰을 이해해보려 노력했는데 알맞게 구현했는지 잘 모르겠네요 ㅎㅎ;

과제를 수행하면서 가장 어려웠던 포인트는 Player가 현재 들고 있는 카드셋이 어떤 상태인지 알아보는것이었습니다.
OnGoingPlayer.of로 체크해서 type으로 비교하고 있었는데, 비슷한 모양의 class가 여럿 생기고
누군가가 작업을 한다면 팩토리 메서드가 OnGoingPlayer에 있는것으로 예상하기 어려울것 같은데 적절한 위치를 잘 판단하지 못했습니다

이 부분을 비롯해서 리뷰어님 의견을 여쭙니다 🙇

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.

안녕하세요!

2단계 미션 너무 잘 구현해주셨네요! 👍👍

몇 가지 코멘트를 남겼으니 확인 후 코드리뷰 요청 부탁드립니다!

화이팅입니다!

Comment on lines +1 to +16

[x] 숫자와 문양을 가진 카드 구현

[x] 카드 뭉치인 덱 구현

[x] 점수 합계를 계산할 수 있는 카드목록 구현

[x] 이름과 카드 목록을 가질 수 있는 플레이어 구현

[x] 카드를 두 장 받는 기능 구현

[x] 카드를 한 장 더 받는 기능 구현

[x] 21이 초과했는지 판별하는 기능 구현

Choose a reason for hiding this comment

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

요구 사항 정리 좋습니다~

Comment on lines +20 to +33
while (true) {
if (onGoingPlayer !is OnGoingPlayer) {
break
}

val isHit = InputView.isHit(onGoingPlayer.name)

if (!isHit) {
break
}

onGoingPlayer = blackJack.hit(onGoingPlayer)
OutputView.printCards(onGoingPlayer)
}

Choose a reason for hiding this comment

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

do while을 사용해보는 것도 좋을 것 같아요 :)

자바와 다르게 kotlin의 do while은 특징이 있어요. 한번 찾아보시겠어요?

Comment on lines +17 to +19
operator fun plus(other: Card): Cards {
return Cards(value + other)
}

Choose a reason for hiding this comment

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

연산자 오버로딩 👍👍

return cards.removeFirst()
}

private fun setupDeck(): List<Card> {

Choose a reason for hiding this comment

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

👍👍

Comment on lines +8 to +18
fun of(name: String, cards: Cards): Player {
val hardAcePoint = cards.getPoints()

return if (hardAcePoint == BlackJack.BlackJackedNumber) {
BlackJackedPlayer(name, cards)
} else if (hardAcePoint > BlackJack.BlackJackedNumber) {
BustedPlayer(name, cards)
} else {
OnGoingPlayer(name, cards)
}
}

Choose a reason for hiding this comment

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

과제를 수행하면서 가장 어려웠던 포인트는 Player가 현재 들고 있는 카드셋이 어떤 상태인지 알아보는것이었습니다.
OnGoingPlayer.of로 체크해서 type으로 비교하고 있었는데, 비슷한 모양의 class가 여럿 생기고
누군가가 작업을 한다면 팩토리 메서드가 OnGoingPlayer에 있는것으로 예상하기 어려울것 같은데 적절한 위치를 잘 판단하지 못했습니다

확실히, 누군가가 작업을 한다면 여러 플레이어에 대한 상태 변화가 OnGoingPlayer에 정적 팩토리 메서드로 되어있다면 파악하기 어려울 것 같아요.

일단, 정적 팩토리 메서드 패턴은 저는 외부의 다른 값으로 특정 클래스의 생성자를 만든다고 생각해요. 하지만, 현재 BlackJackNumber에 따라서 플레이어의 객체가 변경되는 것은 생성자를 만드는 것보다는 도메인 로직이라고 생각해요.

도메인 로직이라고 생각하여 여럿 플레이어가 상태에 따라 변경하도록 한다면, 행위에 대해 추상화하여 상태 머신(State machine)을 도입해보는 것도 나쁘지 않다고 생각이 드네요.

경문님은 어떻게 생각하시나요?

Comment on lines +11 to +12
return if (hardAcePoint == BlackJack.BlackJackedNumber) {
BlackJackedPlayer(name, cards)

Choose a reason for hiding this comment

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

참고로 블랙잭은 첫 두장의 카드가 21인 경우를 말해요. 여기서는 21점이면 언제나 블랙잭인 것 같네요.

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

class SoftAcePointStrategy : CardPointStrategy {

Choose a reason for hiding this comment

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

ACE에 대한 전략 👍

Comment on lines +9 to +18
val cards = Cards(
listOf(
Card(Suit.Spade, Rank.Ace),
Card(Suit.Spade, Rank.Two),
)
)

val totalPoint = cards.getPoints()

assertThat(totalPoint).isEqualTo(13)

Choose a reason for hiding this comment

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

스크린샷 2023-11-22 오후 9 24 31

ACE 3장에 숫자8 카드가 1장일 때 21일 것 같은데 11이 나오네요. 한장 더 받을거라는 플레이어 심리를 보여주는 걸까요!? 😱

Copy link
Author

Choose a reason for hiding this comment

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

아..! Ace가 두 장 이상이면 무조건 스플릿해야하는 것으로 이해해서 고려하지 않았었는데 그냥 진행해도 되나보군요..?!

그러면 생각나는 방법은, 모든 경우의수를 따져보는것 밖에 없다고 느껴지는데요..!
지금 수정한다고 하면 아마도 Ace를 제외한 합산과 Ace의 모든 경우의 수를 따져볼것 같아요
혹시 생각 해볼 만한 다른 전략이 있을까요??

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