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

[오렌지] 블랙잭 미션 제출합니다. #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

YerinCho
Copy link

@YerinCho YerinCho commented Jul 1, 2020

상태패턴에 정신을 못차려서
수익부분 테스트코드 안 만듬. . .
목요일중에 만들겠습니다.. 토나올거같아...

Copy link
Member

@hongbin-dev hongbin-dev 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 +21 to +28
public void drawFirst(Players players, Dealer dealer) {
List<Card> drawCards = new ArrayList<>();
for (int index = 0; index < players.size() * FIRST_DRAW_NUMBER; index++) {
drawCards.add(deck.deal());
}
players.firstDraw(drawCards);
dealer.drawFirst(deck.deal(), deck.deal());
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void drawFirst(Players players, Dealer dealer) {
List<Card> drawCards = new ArrayList<>();
for (int index = 0; index < players.size() * FIRST_DRAW_NUMBER; index++) {
drawCards.add(deck.deal());
}
players.firstDraw(drawCards);
dealer.drawFirst(deck.deal(), deck.deal());
}
public void drawFirst(Players players) {
List<Card> drawCards = new ArrayList<>();
for (int index = 0; index < players.size() * FIRST_DRAW_NUMBER; index++) {
drawCards.add(deck.deal());
}
players.firstDraw(drawCards);
}

Players에 딜러도 포함된다면 깔끔한 코드를 가져갈 수 있을 것 같아요.

Comment on lines +6 to +8
private final Symbol symbol;

private final Type type;
Copy link
Member

Choose a reason for hiding this comment

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

별건 아니지만,, 둘이 사이가 안좋나요..?

public class Hands {
public static final int TEN = 10;
public static final int ELEVEN = 11;
public static final int BLACKJACK = 21;
Copy link
Member

Choose a reason for hiding this comment

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

21이 블랙잭이냐? 라고 했을 때 아닐수도 있다고 생각되는 네이밍이네요.

public static final int TEN = 10;
public static final int ELEVEN = 11;
public static final int BLACKJACK = 21;
public static final int DEALER_BUST_NUMBER = 17;
Copy link
Member

@hongbin-dev hongbin-dev Jul 2, 2020

Choose a reason for hiding this comment

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

public static final int DEALER_BUST_NUMBER = 17; 딜러의 책임 아닐까요?

Copy link

@KS-KIM KS-KIM Jul 2, 2020

Choose a reason for hiding this comment

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

17이 딜러가 버스트 하는 기준인가요? 제가 알고있는 바로는 딜러가 추가적인 패를 드로우할지 여부를 결정하는 기준입니다. 의미가 잘못 전달될 여지가 있으니 네이밍을 바꿔보는게 어떨까요?

Comment on lines +60 to +62
public boolean isDealerBust() {
return sum() >= DEALER_BUST_NUMBER;
}
Copy link
Member

Choose a reason for hiding this comment

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

딜러도 버스트는 21이 아닐까요..?

Comment on lines +13 to +19
public static Map<String, Double> calculateMoney(Dealer dealer, Players players) {
Map<String, Double> earningMonies = new LinkedHashMap<>();
for (Player player : players.getPlayers()) {
earningMonies.put(player.getName(), calculate(dealer, player));
}
return earningMonies;
}
Copy link
Member

Choose a reason for hiding this comment

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

자료구조 선택이 좋네요..!
대신 이렇게 하시려면 Name부분에서 이름 중복체크도 해줘야할 것 같아요.

Comment on lines +19 to +22
@Override
public boolean canDrawCard() {
return !state.hands().isBust();
}
Copy link
Member

Choose a reason for hiding this comment

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

state.isNotBust()를 뚫어놓으면 디미터법칙을 지킬 수 있을 것 같아요.

Copy link

@KS-KIM KS-KIM left a comment

Choose a reason for hiding this comment

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

안녕하세요 오렌지🍊, 어려운 미션인데도 불구하고 잘 구현해 주셨습니다.

1차적으로 프로덕션 코드 리뷰했으니 확인하시고 궁금한 점 있으시면 코멘트 달아주세요.

테스트 코드는 여력이 될 때 리뷰해드리겠습니다!

}

public Card deal() {
return cards.remove(0);
Copy link

Choose a reason for hiding this comment

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

CardFactory를 보니 자료구조가 ArrayList네요.
0번째 인덱스 값을 지운다면 deal 메서드가 O(N)의 시간복잡도를 가지게 될 것 같은데, 아래와 같이 바꿔보는건 어떨까요?

Suggested change
return cards.remove(0);
return cards.remove(cards.size() - 1);


import static domain.Game.FIRST_DRAW_NUMBER;

public class Hands {
Copy link

@KS-KIM KS-KIM Jul 2, 2020

Choose a reason for hiding this comment

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

블랙잭에서 한 명의 플레이어가 가지는 패를 Hand라고 부릅니다. 일급 컬렉션이라서 복수형 네이밍을 선택하신 것 같은데, Hand가 이미 복수형의 의미를 내포하고 있으니 아래와 같이 바꾸는게 좋지 않을까요?

Suggested change
public class Hands {
public class Hand {

40 CARDS [countable]
a) the playing cards given to one person in a game

참고: https://www.ldoceonline.com/ko/dictionary/hand

public static final int TEN = 10;
public static final int ELEVEN = 11;
public static final int BLACKJACK = 21;
public static final int DEALER_BUST_NUMBER = 17;
Copy link

@KS-KIM KS-KIM Jul 2, 2020

Choose a reason for hiding this comment

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

17이 딜러가 버스트 하는 기준인가요? 제가 알고있는 바로는 딜러가 추가적인 패를 드로우할지 여부를 결정하는 기준입니다. 의미가 잘못 전달될 여지가 있으니 네이밍을 바꿔보는게 어떨까요?

}

private boolean isAceOne(int sum) {
return isAceExist() && sum > ELEVEN;
Copy link

Choose a reason for hiding this comment

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

버스트 기준이 25로 바뀐다면 ELEVEN의 값은 바뀌지 않을까요? 보다 유연한 네이밍을 하는게 좋을 것 같아요.

if (isAceNotExist() || isAceOne(sum)) {
return sum;
}
return sum + TEN;
Copy link

Choose a reason for hiding this comment

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

Ace를 1 또는 11이 아니라 1 또는 20으로 볼 수 있다면? TEN이라는 네이밍은 변경에 유연하지 못할 것 같아요. 이름을 다시 고민해보는게 어떨까요?

Comment on lines +5 to +6
public Dealer() {
}
Copy link

Choose a reason for hiding this comment

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

빈 생성자가 필요한 특별한 이유가 있나요?

import java.util.List;
import java.util.Map;

public class PlayerFactory {
Copy link

Choose a reason for hiding this comment

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

정적 유틸리티 클래스라면 빈 private 생성자를 추가하여 인스턴스 생성을 방지해봐요!

Comment on lines +22 to +27
List<Card> drawCards = new ArrayList<>();
for (int index = 0; index < players.size() * FIRST_DRAW_NUMBER; index++) {
drawCards.add(deck.deal());
}
players.firstDraw(drawCards);
dealer.drawFirst(deck.deal(), deck.deal());
Copy link

Choose a reason for hiding this comment

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

Game 클래스가 Deck에서 모든 카드를 꺼내 Players에 전달해줘야 할까요? PlayersDeck간의 협력 관계를 통해 풀어갈 수 있는 부분이라고 생각합니다.

import java.util.Map;
import java.util.stream.Collectors;

public class Controller {
Copy link

Choose a reason for hiding this comment

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

어떤 역할을 하는 컨트롤러인지 명시적인 네이밍을 주는게 좋을 것 같아요.

Comment on lines +36 to +55
private static void calculateWhenStay(Hands dealerHands, Player player) {
if (dealerHands.isBust() || player.getHands().isBiggerThan(dealerHands)) {
player.stay();
}
if (dealerHands.isBiggerThan(player.getHands())) {
player.bust();
}
}

private static void calculateWhenBlackjack(Hands dealerHands, Player player) {
if (dealerHands.isBlackjack()) {
player.stay();
}
}

private static void calculateWhenBust(Hands dealerHands, Player player) {
if (dealerHands.isBust()) {
player.stay();
}
}
Copy link

Choose a reason for hiding this comment

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

이미 패를 draw하는 단계에서 딜러와 모든 플레이어는 Finished 상태로 진입했을텐데, 여기서 또 stay, bust를 호출해야 할 특별한 이유가 있을까요?

Comment on lines +17 to +22
private void validate(final List<Player> players) {
Objects.requireNonNull(players, "플레이어는 1명 이상이어야 합니다. 입력값 : null");
if (players.isEmpty()) {
throw new IllegalArgumentException("플레이어는 1명 이상이어야 합니다. 입력값 : empty");
}
}
Copy link

Choose a reason for hiding this comment

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

플레이어가 9명 이상인 시점부터 카드 52장을 모두 소모하고 부족할 가능성이 있는데, 최대 8명까지로 제한하는게 어떨까요?

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.

3 participants