-
Notifications
You must be signed in to change notification settings - Fork 75
[황인규] 연료 주입, blackjack (Step1) #41
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
base: sk11ingyuhwang
Are you sure you want to change the base?
Conversation
- Sonata, Avante, K5
- CarTest.java - RentCarTest.java
- getCards() :: 카드를 얻는다. - getTotalScore() :: 카드에 적힌 총합을 구한다.
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.
안녕하세요 인규님!
몇 가지 코멘트를 남겼습니다.
확인 부탁드립니다.
static { | ||
Arrays.stream(CardNumber.values()).forEach( | ||
cardNumber -> Arrays.stream(CardPattern.values()).forEach( | ||
cardPattern -> cards.add(new Card(cardNumber, cardPattern)) | ||
) | ||
); | ||
Collections.shuffle(cards); | ||
} |
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.
만약 게임이 여러번 진행되면 문제가 발생할 것으로 예상됩니다.
덱보다 카드를 정적으로 생성해보는 것은 어떨까요?
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 blackjack.domain.card.Cards; | ||
import java.util.List; | ||
|
||
public abstract class CardSupport implements Gameable { |
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.
StageSupport
는 불필요한 행위인 것 같습니다.
그리고 CarSupport -> Gameable를 통해서 어떤 것을 말하고 싶었나요?
카드 추가 유무는 행위자인 Person에 있는 게 더 적절해 보입니다.
카드보다는 게임 자체 상태를 추상화해 관리해 보면 어떨까요?
블랙잭에는 여러 게임 상태가 존재합니다.
- bust
- blackjack
- stay
- hit
그리고 그런 게임 상태에 따라 게임 진행 여부를 판단하도록 구현해 보는 것이 어떨까요?
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.
오 맞습니다. 😭
블랙잭 게임에 대한 이해가 충분하지 못했던것 같아요. 🙇♂️
기존에 존재하던 CardSupport 와 Gameable 관계는 자주 사용하는 메소드를 분리하는 목적으로 만들었어요. 그러다 보니, 전혀 블랙잭 게임 룰을 반영하지 못헀던것 같아요.
현재는 CardSupport, StageSupport를 지우고 Gameable 에 staty
, draw
를 두어 상태관리를 추가하였습니다.
Gameable stay();
Gameable draw();
그리고, 각 게임 상태를 클래스로 구현해서 만들어주었어요.
게임에 상태에 따라 알맞은 구현체를 호출하면서 블랙잭 게임에 대한 상태가 더 명확해졌다는것을 느낄 수 있었어요. 👍
| -- state
| `-- Blackjack
| `-- Bust
| `-- Hit
| `-- Stay
|--
return false; | ||
} | ||
|
||
public int getTotalScoreOfPlayer(Player player) { |
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.
Person에서 카드 추가 유무와 현재 카드 상태를 가지도록 수정해 보는 것은 어떨까요?
현실 세계에서는 참가자와 딜러 손으로 카드를 받고, 현재 카드 점수를 판단합니다.
.filter(targetScore -> sourceScore > targetScore).count()).intValue(); | ||
} | ||
|
||
private int countLose(final int sourceScore, final List<Integer> targetScores) { |
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 List<Integer> calculateDealerGameResult() { | ||
int dealerScore = game.getDealer().getCards().cards().sumScore(); |
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.
질문주신 내용은 카드 점수의 상태를 CardSupport
를 수정하시면 자연스럽게 해결 될 문제라고 생각합니다.
블랙잭 게임 역할을 하는 Game
객체는 크게 다음과 같은 기능을 하면 될 것으로 생각합니다.
- 카드 분배
Winner
에게 참가자와 딜러의 카드점수 상태 전달Winner
에서 게임 결과 리턴받기
승패를 결정하는게 Winner
의 역할이라고 생각합니다.
감사합니다. 리뷰어님! |
- CardDeck#cards 참조 관계 끊어주도록 수정
승완님 안녕하세요. 🙇♂️ |
안녕하세요. 🙇♂️
이번 미션에서는 연료주입, 블랙잭에 대해 구현했습니다.
이번 미션에서 집중한 내용은
공통 기능에 대해서 인터페이스와 필요하다면 추상클래스를 적절히 묶어서 구현체로 구현
해 보았어요.한일
연료주입 🚐
연료주입
에서는 추상 메서드를 하나 이상 가지고 있는Car
클래스를 기반으로K5, Sonata, Avante
를 만들어주었어요.입력 값에 따라서 자동차 객체를 생성해줘야 하는 부분을 어떻게 구현해줘야 할지 고민이 많았어요.
이 부분은 페어와 의견을 공유해보면서
아래 of 메소드
를 활용해 자동차 이름과, 거리를 입력 받으면 알맞은 자동차 객체를 반환하도록 만들어 보았어습니다.블랙잭 🎴
블랙잭
에서는 공통 기능을 분류하는 작업을 우선 고민해보았어요.어떤 부분이 필요할지 몰라
블랙잭
을 우선 먼저 구현해보고 필요한 기능을 엮어보았습니다.아래 6가지가 공통된 기능을 수행하고 있었어요.
interface
위 interface 기능에서 관련된 것끼리 abstract으로 묶었어요.
abstract
또, 인터페이스를 활용해보니 저수준 모듈에서 고수준 모듈을 의존하게끔 바꿈으로써 구현 변경 및 테스트 어려움을 해결할 수 있었어요.
질문
이 글 을 읽어보고 interface와 abstract을 활용했는데 블랙잭에 필요한 공통 기능을 잘 나누었는지 리뷰어님께 확인받고 싶어요.
객체간에 의존 관계가 깊어져서 getter() 를 여러번 타게 되는 경우가 많이 발생했어요. 불필요한 객체를 만든건 아닌지 무척 걱정이 됩니다.
Winner
클래스에Game
객체를 들고 있는것이 맞는지 확신이 안들어요.Winner
클래스의 역할을Winner
를 가리기 위한 책임을 가지고 있는 클래스라고 생각했어요. 그래서Game
을 함으로써Winner
를 보여준다. 는 행위를 수행하는 역할을 하게 되는데요. 이 부분에 대해서 리뷰어 님의 생각이 궁금해요. 🙇♂️