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

[2단계 - 블랙잭 베팅] 리브(김민주) 미션 제출합니다. #695

Merged
merged 41 commits into from
Mar 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
39a9f08
docs(README.md): 요구 사항 업데이트
Minjoo522 Mar 13, 2024
1758848
feat(Money): 베팅 금액의 원시값을 포장하는 Money 객체 구현
Minjoo522 Mar 13, 2024
48cf9fa
feat(InputView): 배팅 금액 입력 받는 기능 구현
Minjoo522 Mar 13, 2024
2dae152
feat(Money): getMoney 구현
Minjoo522 Mar 13, 2024
3714c5f
feat(Hit): Hit 상태를 표현하는 객체 구현
Minjoo522 Mar 13, 2024
4daf110
feat(BlackJack): BlackJack 상태를 표현하는 객체 구현
Minjoo522 Mar 13, 2024
629f779
feat(Bust): Bust 상태를 표현하는 객체 구현
Minjoo522 Mar 13, 2024
ebbbf67
feat(Stand): Stand 상태를 표현하는 객체 구현
Minjoo522 Mar 13, 2024
351d619
feat(State): 현재 소유한 카드의 총 점수를 계산하는 calculateScore() 메서드 추가
Minjoo522 Mar 13, 2024
1e0a610
feat(Participant): Dealer, Player의 중복 메서드 Participant로 이동
Minjoo522 Mar 13, 2024
0b7e558
refactor(State): state에서 List<Card> -> Hand를 반환하는 메서드로 변경
Minjoo522 Mar 13, 2024
4c98d73
feat(Money): 현재 금액에 전달 받은 숫자 곱하는 기능 구현
Minjoo522 Mar 13, 2024
ddffb0c
refactor(Participant): 불필요한 Hand 필드 제거
Minjoo522 Mar 13, 2024
4e88564
feat(bets): 플레이어의 베팅 금액을 저장하는 Bets 구현 및 BlackJackGame에서 사용
Minjoo522 Mar 13, 2024
8fed05d
feat(State): calculateProfit 제거 및 isBlackJack, isBust 추가
Minjoo522 Mar 13, 2024
a412a89
rename: 불필요한 클래스 제거
Minjoo522 Mar 13, 2024
222eb48
feat(ResultCommand, Referee, Rule): 블랙잭 승리 관련 조건 추가
Minjoo522 Mar 13, 2024
40fccda
feat(Bets): 플레이어의 베팅 금액을 모아둔 Bets 생성 및 Money의 validate Bets로 이동
Minjoo522 Mar 13, 2024
847eab2
feat(NameProfit): 플레이어의 이름, 수익금을 담는 NameProfit Dto 추가
Minjoo522 Mar 13, 2024
8aee5df
feat(OutputView, BlackJackGame): 딜러와 플레이어의 수익금 출력하는 기능 구현
Minjoo522 Mar 13, 2024
fe6f360
rename(state): state 관련 클래스 제거
Minjoo522 Mar 13, 2024
20388a4
refactor(Participant): Dealer와 Player에 중복 코드 추상 클래스로 이동
Minjoo522 Mar 13, 2024
608df98
rename(Bets, Money): 패키지 이동
Minjoo522 Mar 13, 2024
b758eaa
refactor(Referee): Rule -> Referee와 통합
Minjoo522 Mar 13, 2024
1a7335e
refactor(BlackJackGame): 최종 수익 출력 관련 메서드 분리
Minjoo522 Mar 13, 2024
3ede65e
docs(README.md): 요구 사항 완료 내역 체크
Minjoo522 Mar 13, 2024
d4d04c4
style(test, BlackJackGame): 불필요한 import 구문 및 파라미터 제거
Minjoo522 Mar 13, 2024
784df14
rename(ResultCommandDisplay): 사용하지 않는 display enum 제거
Minjoo522 Mar 14, 2024
eb4e010
rename(BetMoney): Money -> BetMoney로 이름 변경
Minjoo522 Mar 15, 2024
1342326
refactor(BetMoney): 각 player의 수익을 계산하는 calculatePlayerProfit에서 Map이 아…
Minjoo522 Mar 15, 2024
de58ed6
refactor(Players): 필요 없는 파라미터 제거
Minjoo522 Mar 15, 2024
cca88cf
refactor(BlackJackGame): Bets를 Players가 아닌 BlackJackGame이 담담하도록 변경
Minjoo522 Mar 15, 2024
9b85741
refactor(Profit): 당첨 수익금을 포장하는 Profit 객체 생성 및 사용
Minjoo522 Mar 15, 2024
342fbd0
feat(BetMoney): 1원 미만 1억 초과 금액을 베팅 금액으로 입력했을 때 예외가 발생하는 기능 구현
Minjoo522 Mar 15, 2024
af6a018
rename(ProfitStatement): NameProfit -> ProfitStatement로 변경
Minjoo522 Mar 15, 2024
797d6db
fit(BlackJackGame): 데이터 타입 변경 반영
Minjoo522 Mar 15, 2024
16acf7a
refactor(BetsTest): TestFixture 분리 및 ParameterizedTest 개별 테스트로 분리
Minjoo522 Mar 15, 2024
bf22dd7
refactor(Participant, Dealer): canHit을 추상 클래스에서 제거하고 Dealer에서 메서드 명을 …
Minjoo522 Mar 15, 2024
98c12c1
rename(Deck): distribute -> drawn 메서드명 변경
Minjoo522 Mar 15, 2024
d668349
refactor(test): 테스트 코드에 Fixture 추가 및 DisplayName 상세화
Minjoo522 Mar 15, 2024
ee98739
refactor(test): 예외 메시지가 변경되어도 테스트가 실패하지 않도록 수정
Minjoo522 Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(ResultCommand, Referee, Rule): 블랙잭 승리 관련 조건 추가
  • Loading branch information
Minjoo522 committed Mar 13, 2024
commit 222eb4855f06fd4e05239a4ca05ba71f3c494279
4 changes: 4 additions & 0 deletions src/main/java/blackjack/model/participant/Dealer.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@ public boolean canHit() {
return state.calculateScore() <= HITTABLE_THRESHOLD;
}

public boolean isBlackJack() {
return state.isBlackJack();
}

public List<Card> distributeInitialCard() {
return List.of(deck.distribute(), deck.distribute());
}
10 changes: 0 additions & 10 deletions src/main/java/blackjack/model/result/Referee.java
Original file line number Diff line number Diff line change
@@ -18,14 +18,4 @@ public Referee(final Rule rule) {
public ResultCommand judgePlayerResult(final Player player) {
return rule.calculateResult(player);
}

public Map<ResultCommand, Integer> judgeDealerResult(final Players players) {
return players.stream()
.map(this::judgePlayerResult)
.collect(groupingBy(
ResultCommand::findOpposite,
() -> new EnumMap<>(ResultCommand.class),
reducing(0, i -> 1, Integer::sum)
));
}
}
23 changes: 12 additions & 11 deletions src/main/java/blackjack/model/result/ResultCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package blackjack.model.result;

public enum ResultCommand {
WIN,
LOSE,
DRAW,
WIN(1),
BLACK_JACK_WIN(1.5),
LOSE(-1),
DRAW(1),
;

public ResultCommand findOpposite() {
if (this == WIN) {
return LOSE;
}
if (this == LOSE) {
return WIN;
}
return DRAW;
private final double rate;

ResultCommand(double rate) {
this.rate = rate;
}

public double getRate() {
return rate;
}
}
31 changes: 23 additions & 8 deletions src/main/java/blackjack/model/result/Rule.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package blackjack.model.result;

import static blackjack.model.result.ResultCommand.*;

import blackjack.model.participant.Dealer;
import blackjack.model.participant.Player;

@@ -11,39 +13,52 @@ public Rule(final Dealer dealer) {
}

public ResultCommand calculateResult(final Player player) {
if (dealer.isBlackJack()) {
return judgePlayerResultWhenDealerBlackJack(player);
}
if (player.isBlackJack()) {
return BLACK_JACK_WIN;
}
if (dealer.isBust()) {
return judgePlayerResultWhenDealerBust(player);
}
return judgePlayerResultWhenDealerNotBust(player);
}

private ResultCommand judgePlayerResultWhenDealerBlackJack(final Player player) {
if (player.isBlackJack()) {
return DRAW;
}
return LOSE;
}

private ResultCommand judgePlayerResultWhenDealerBust(final Player player) {
if (player.isBust()) {
return ResultCommand.LOSE;
return LOSE;
}
return ResultCommand.WIN;
return WIN;
}

private ResultCommand judgePlayerResultWhenDealerNotBust(final Player player) {
if (player.isBust()) {
return ResultCommand.LOSE;
return LOSE;
}
if (player.notifyScore() > dealer.notifyScore()) {
return ResultCommand.WIN;
return WIN;
}
if (player.notifyScore() < dealer.notifyScore()) {
return ResultCommand.LOSE;
return LOSE;
}
return judgePlayerResultWhenSameScore(player);
}

private ResultCommand judgePlayerResultWhenSameScore(final Player player) {
if (player.hasManyCardsThan(dealer)) {
return ResultCommand.LOSE;
return LOSE;
}
if (player.hasSameCardsSizeThan(dealer)) {
return ResultCommand.DRAW;
return DRAW;
}
return ResultCommand.WIN;
return WIN;
}
}
32 changes: 3 additions & 29 deletions src/test/java/blackjack/model/result/RefereeTest.java
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import static blackjack.model.deck.Shape.DIA;
import static blackjack.model.deck.Shape.HEART;
import static blackjack.model.deck.Shape.SPADE;
import static blackjack.model.result.ResultCommand.BLACK_JACK_WIN;
import static blackjack.model.result.ResultCommand.DRAW;
import static blackjack.model.result.ResultCommand.LOSE;
import static blackjack.model.result.ResultCommand.WIN;
@@ -21,17 +22,11 @@
import blackjack.model.deck.Deck;
import blackjack.model.participant.Dealer;
import blackjack.model.participant.Player;
import blackjack.model.participant.Players;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class RefereeTest {
@Nested
@@ -82,12 +77,12 @@ void init() {
}

@Test
@DisplayName("플레이어 카드만 블랙잭인 경우 플레이어가 승리한다.")
@DisplayName("플레이어 카드만 블랙잭인 경우 플레이어가 블랙잭 승리한다.")
void playerWinWhenOnlyPlayerBlackJack() {
player.receiveInitialCards(List.of(new Card(CLOVER, TEN), new Card(SPADE, ACE)));
dealer.receiveInitialCards(List.of(new Card(SPADE, SEVEN), new Card(DIA, TEN), new Card(DIA, FOUR)));

assertThat(referee.judgePlayerResult(player)).isEqualTo(WIN);
assertThat(referee.judgePlayerResult(player)).isEqualTo(BLACK_JACK_WIN);
}

@Test
@@ -166,25 +161,4 @@ void sameScoreAndCount() {
assertThat(referee.judgePlayerResult(player)).isEqualTo(DRAW);
}
}

@ParameterizedTest
@MethodSource("generateCardsSupplierExpected")
@DisplayName("딜러의 결과를 반환한다.")
void getDealerResult(List<Card> cards, ResultCommand expected) {
Dealer dealer = new Dealer(new Deck());
dealer.receiveInitialCards(List.of(new Card(CLOVER, TEN), new Card(SPADE, TEN)));
Players players = Players.from(List.of("몰리", "리브", "포비"));
players.receiveInitialCards(() -> cards);

Referee referee = new Referee(new Rule(dealer));
assertThat(referee.judgeDealerResult(players)).containsAllEntriesOf(Map.of(expected, 3));
}

static Stream<Arguments> generateCardsSupplierExpected() {
return Stream.of(
Arguments.of(List.of(new Card(CLOVER, TEN), new Card(SPADE, TEN), new Card(DIA, FOUR)), WIN),
Arguments.of(List.of(new Card(CLOVER, TEN), new Card(SPADE, ACE)), LOSE),
Arguments.of(List.of(new Card(CLOVER, TEN), new Card(SPADE, TEN)), DRAW)
);
}
}