-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
이름 입력 구현 배팅금액 입력 구현
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요. 오렌지! 앨런입니다.
블랙잭 정말 열심히 짜주셨네요! 감탄입니다 👏👏
특히 상태패턴을 적용하신거에 되게 놀랐는데요.
오렌지코드를 잘 모르지만 변경되면 좋아보이는 점..? 작성해봤습니다.
감사합니다. ✌✌
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()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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에 딜러도 포함된다면 깔끔한 코드를 가져갈 수 있을 것 같아요.
private final Symbol symbol; | ||
|
||
private final Type type; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
딜러의 책임 아닐까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
17이 딜러가 버스트 하는 기준인가요? 제가 알고있는 바로는 딜러가 추가적인 패를 드로우할지 여부를 결정하는 기준
입니다. 의미가 잘못 전달될 여지가 있으니 네이밍을 바꿔보는게 어떨까요?
public boolean isDealerBust() { | ||
return sum() >= DEALER_BUST_NUMBER; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
딜러도 버스트는 21이 아닐까요..?
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자료구조 선택이 좋네요..!
대신 이렇게 하시려면 Name부분에서 이름 중복체크도 해줘야할 것 같아요.
@Override | ||
public boolean canDrawCard() { | ||
return !state.hands().isBust(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state.isNotBust()를 뚫어놓으면 디미터법칙을 지킬 수 있을 것 같아요.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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)의 시간복잡도를 가지게 될 것 같은데, 아래와 같이 바꿔보는건 어떨까요?
return cards.remove(0); | |
return cards.remove(cards.size() - 1); |
|
||
import static domain.Game.FIRST_DRAW_NUMBER; | ||
|
||
public class Hands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
블랙잭에서 한 명의 플레이어가 가지는 패를 Hand
라고 부릅니다. 일급 컬렉션이라서 복수형 네이밍을 선택하신 것 같은데, Hand
가 이미 복수형의 의미를 내포하고 있으니 아래와 같이 바꾸는게 좋지 않을까요?
public class Hands { | |
public class Hand { |
40 CARDS [countable]
a) the playing cards given to one person in a game
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
이라는 네이밍은 변경에 유연하지 못할 것 같아요. 이름을 다시 고민해보는게 어떨까요?
public Dealer() { | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정적 유틸리티 클래스라면 빈 private 생성자를 추가하여 인스턴스 생성을 방지해봐요!
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Game
클래스가 Deck
에서 모든 카드를 꺼내 Players
에 전달해줘야 할까요? Players
와 Deck
간의 협력 관계를 통해 풀어갈 수 있는 부분이라고 생각합니다.
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class Controller { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 역할을 하는 컨트롤러인지 명시적인 네이밍을 주는게 좋을 것 같아요.
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 패를 draw하는 단계에서 딜러와 모든 플레이어는 Finished 상태로 진입했을텐데, 여기서 또 stay
, bust
를 호출해야 할 특별한 이유가 있을까요?
private void validate(final List<Player> players) { | ||
Objects.requireNonNull(players, "플레이어는 1명 이상이어야 합니다. 입력값 : null"); | ||
if (players.isEmpty()) { | ||
throw new IllegalArgumentException("플레이어는 1명 이상이어야 합니다. 입력값 : empty"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
플레이어가 9명 이상인 시점부터 카드 52장을 모두 소모하고 부족할 가능성이 있는데, 최대 8명까지로 제한하는게 어떨까요?
상태패턴에 정신을 못차려서
수익부분 테스트코드 안 만듬. . .
목요일중에 만들겠습니다.. 토나올거같아...