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

Open
wants to merge 6 commits into
base: celine-yerim
Choose a base branch
from

Conversation

celine-yerim
Copy link

안녕하세요~
최대한 나눠서 블랙잭 개발 완료 했습니다~

@celine-yerim celine-yerim changed the base branch from main to celine-yerim November 29, 2023 16:03
Copy link

@namjackson namjackson left a comment

Choose a reason for hiding this comment

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

안녕하세요 예림님!
2단계 고생하셨습니다!
몇가지 고민할법한 코멘트들 남겼으니, 확인해주세요!
궁금하신부분이나, 질문있으시면, 언제나 편하게 dm이나 코멘트 해주세요 😄
변경사항 적용후, 다시 리뷰요청해주시면 좋을거 같아요!

import blackjack.view.InputView
import blackjack.view.ResultView

fun main() {

Choose a reason for hiding this comment

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

함수(또는 메서드)의 길이가 15라인을 넘어가지 않도록 구현한다.

메인함수가 길어졌네요! 요구사항을 지켜보아요!
main함수 내에서 구현은 최소화해보면 어떨까요?
Controller같은 클래스를 작성해보면 좋을거같아요!

Comment on lines 23 to 25
}
}
}

Choose a reason for hiding this comment

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

Indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다.

2개이상의 depth가 많아지면, 가독성 저하는 물론이고, 실수도 자주일어나곤해요!
미션의 프로그래밍 요구사항을 지켜보아요!

src/main/kotlin/blackjack/Card.kt Outdated Show resolved Hide resolved
src/main/kotlin/blackjack/Card.kt Outdated Show resolved Hide resolved
src/main/kotlin/blackjack/Card.kt Outdated Show resolved Hide resolved

data class Participant (
val name: String,
val cards: MutableList<Card> = mutableListOf(),

Choose a reason for hiding this comment

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

MutableList 타입이지만 외부에서 접근이 가능한 구조네요
외부에서 쉽게 변경하면, 의도하지 않은 결과가 나올수도 있을거같아요!

src/main/kotlin/blackjack/Participant.kt Outdated Show resolved Hide resolved

fun addCard() {
if (score <= 21) {
val card = Card.getCard()

Choose a reason for hiding this comment

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

싱글턴 패턴 장점도 많지만, 단점 또한 많아서, 사용에 주의가 필요한 패턴이예요!
위의 경우에는 클래스간 강한 결합을 만들어주게됩니다!
Participant 객체가 Card.getCard() 에 의존되는 구조가 되었네요!
수정해보면 어떨까요?

}

private fun calculateScore(card: Card) {
score += if (card.cardValue.value == StringValue.A) {

Choose a reason for hiding this comment

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

이런 구조라면 같은 카드조합이라도, A가 들어온 순서에 따라 값이 다르게 나올수 있을거 같아요
고민해보아요!

package blackjack

class BlackjackGame {
fun init(participants: List<Participant>){

Choose a reason for hiding this comment

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

init함수를 실행하게되면 외부의 파라미터를 들어온 participants 내부의 값이 참조 변경되는 구조네요!
구현부를 보면 알수 있지만,
blackjackGame.init(participants)라는 코드에서 participants 내부의 값이 변경된다고 알수 있을까요?

추가적으로 BlackjackGame 객체의 책임에 대해 고민해보시면 좋을거같아요!

Copy link

@namjackson namjackson 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 +7 to +11
fun start(names: List<String>, deck: Deck): List<Participant> {
return names.map { Participant(it, deck.getCards(2)) }
}

fun play(participant: Participant, deck: Deck, receive: Boolean): Boolean {

Choose a reason for hiding this comment

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

BlackjackGame 의 모든 함수에 deck 파라미터가 포함되고 있네요,
BlackjackGame내에서 deck을 관리해보면 어떨까요?

비슷한 이유로 Participants 또한 BlackjackGame에서 관리해도 좋을거같단 생각이 드네요 :)
한번 고민해보시면 좋을거같아요!

resultView.printCards(participants)

participants.forEach { participant ->
while (inputView.inputAnswer(participant).also { blackjackGame.play(participant, deck, it) }) {

Choose a reason for hiding this comment

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

also 와 같은 범위지정함수는 언제 써야할까요? 현재는 불필요하진 않을가요?

Suggested change
while (inputView.inputAnswer(participant).also { blackjackGame.play(participant, deck, it) }) {
while (inputView.inputAnswer(participant)) {
blackjackGame.play(..

Choose a reason for hiding this comment

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

view를 통해 카드를 더 받을것인지도 확인해야하지만,
21을 초과하는 숫자일때는, 카드를 더 받을수 없어요!

val participants = blackjackGame.start(names, deck)
resultView.printCards(participants)

participants.forEach { participant ->

Choose a reason for hiding this comment

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

여전히 main 에 너무 많은 일을하고 있어요
participants 관련 작업은 blackjackGame 내에서 해보도록 작업해보면 어떨까요?
view와의 상호작용에 대한 고민이라면, 람다 표현식을 참고해봐도 좋을거같아요 :)

;

fun getAceNumber(score: Int): Int {
return if (score + ACE.extraScore!! <= BLACKJACK_NUMBER) {

Choose a reason for hiding this comment

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

!! 은 언제나 사용을 지양해주세요1
ACE.extraScore는 일반적인 상수로 관리되어도 좋을거같네요!

Comment on lines +22 to +23
private fun List<Card>.listCopy(): List<Card> {
return this.map { it.copy() }

Choose a reason for hiding this comment

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

Card 는 불변객체로 만들어 주셨기 때문에,
컬렉션의 전체 Card들을 copy할 필요는 없을거 같아요!

toList() 를 활용해서, 새로운 리스트만을 반환하게하면 어떨가요?


@ParameterizedTest
@ValueSource(ints = [11, 20])
fun `A 카드 1 확인`(score: Int) {

Choose a reason for hiding this comment

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

테스트 케이스를 조금더 자세히 작성하면 어떨까요?
테스트 코드가 많아진다면,
테스트 케이스명으로만 관리되는데, 구체적인 케이스명이 아니라면, 관리하기가 어렵지않을까요?
구체적인 케이스명을 작성해보아요!

저는 개인적으로 케이스명도 저만의 규칙을 가지고 잇어요
(GIVEN)11이상의 숫자가 주어졌을때, (WHEN) A카드의 점수를 계산하면, (THEN) 1로 계산된다.
예림님만의 규칙을정해봐도 좋을거같아요!


@ParameterizedTest
@ValueSource(ints = [5, 10, 15])
fun getCards(count: Int) {

Choose a reason for hiding this comment

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

마찬가지로 의미있는 케이스명을 작성해보아요!

추가로 Deck의 카드를 모두 소모하면 어떻게 동작할까요?

@namjackson
Copy link

namjackson commented Dec 4, 2023

저는 미션 기간 종료하더라도, 리뷰는 진행할 예정입니다!
단, 미션 기간과 달리 24시간 이내로만 응답해드릴수는 없을수 있으니, 참고해주세요 :)
미션 끝까지 화이팅입니다!

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