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단계 - 블랙잭 베팅] 제프리(홍성호) 미션 제출합니다. #922

Merged
merged 54 commits into from
Mar 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a086f34
refactor: 생성자에 방어적 복사 적용
AppleMint98 Mar 11, 2025
915a371
refactor: 메서드 네이밍 checkDealerSumUnderThreshold -> determineDealerAddi…
AppleMint98 Mar 11, 2025
43c1438
refactor: 반복문 내부 메서드호출 분리
AppleMint98 Mar 11, 2025
9e29e31
refactor: 상수 네이밍 BUST_STANDARD -> MAX_SCORE 변경
AppleMint98 Mar 11, 2025
3f35f84
refactor: playerCanHit 변수 추출
AppleMint98 Mar 11, 2025
dc8162e
refactor: doesNotBust 메서드로 부정연산자 제거
AppleMint98 Mar 12, 2025
0f0a44d
refactor: Gambler 추상 클래스 변경
AppleMint98 Mar 12, 2025
a873203
refactor: openOneCard -> openInitialCard 네이밍 변경
AppleMint98 Mar 12, 2025
38ef468
refactor: openInitialCards 추상메서드 구현
AppleMint98 Mar 12, 2025
dd913aa
style: 패키지 이동
AppleMint98 Mar 13, 2025
c1aad90
feat: View 인터페이스 구현
AppleMint98 Mar 14, 2025
de0685f
fix: 출력 오류 수정
AppleMint98 Mar 16, 2025
bf91081
style: 패키지 구조 변경
AppleMint98 Mar 16, 2025
385b132
style: 패키지 구조 변경
AppleMint98 Mar 16, 2025
1c4b571
feat: 설정 클래스 config 통합
AppleMint98 Mar 16, 2025
3c997d5
style : 클래스 이름 변경
AppleMint98 Mar 16, 2025
1afd53d
feat: GameBoard 객체 생성 후 로직 이관
AppleMint98 Mar 16, 2025
7d8fb3a
feat: GameBoard 객체 생성 후 로직 이관
AppleMint98 Mar 16, 2025
44dbd6d
feat: 블랙잭 판별 메서드 추가
AppleMint98 Mar 16, 2025
9e9374c
feat: 배팅 금액 기능 구현
AppleMint98 Mar 16, 2025
a7fa62a
fix: y 입력 시 추가로 받지않는 에러 수정
AppleMint98 Mar 16, 2025
d00adbf
fix: 수익 반환 자료형 변경
AppleMint98 Mar 16, 2025
5b7fb50
refactor: 안쓰는 메서드 제거
AppleMint98 Mar 17, 2025
b372c39
style: 테스트 디렉터리 구조 변경
AppleMint98 Mar 17, 2025
1f8f208
test: Card 객체 테스트 작성
AppleMint98 Mar 17, 2025
182def4
test: Cards 객체 테스트 작성
AppleMint98 Mar 17, 2025
f6990ef
test: Deck 객체 테스트 작성
AppleMint98 Mar 17, 2025
6e63922
refactor: 메서드 이름 및 위치 변경
AppleMint98 Mar 17, 2025
deb4451
refactor: 변수 이름 변경
AppleMint98 Mar 17, 2025
63ac0b0
test: Player 객체 테스트 작성
AppleMint98 Mar 17, 2025
874b4c3
test: Players 객체 테스트 작성
AppleMint98 Mar 17, 2025
95c3a2a
refactor: 배팅금액 업데이트 로직 메서드 분리
AppleMint98 Mar 17, 2025
c7d2d1f
test: Dealer 객체 테스트 작성
AppleMint98 Mar 17, 2025
a498eb8
style: 개행 추가 및 메서드 정렬
AppleMint98 Mar 17, 2025
9a2f0c2
fix: 메서드 호출 수정
AppleMint98 Mar 17, 2025
5c45470
refactor: get 네이밍을 calculate로 변경
AppleMint98 Mar 17, 2025
7c10c6e
fix: 무승부시 플레이어 표기오류 수정
AppleMint98 Mar 17, 2025
fc5c299
refactor: BlackjackGame -> BlackjackController 네이밍 변경
AppleMint98 Mar 18, 2025
251a78a
refactor: BlackjackTable -> BlackjackGame 네이밍 변경
AppleMint98 Mar 18, 2025
fe9c7c5
refactor: 게임 실행 로직 이관
AppleMint98 Mar 19, 2025
897faf7
refactor: View 인터페이스 제거
AppleMint98 Mar 19, 2025
d16bdb5
refactor: 변수 이름 변경 및 메서드 접근제한자 변경
AppleMint98 Mar 19, 2025
c1a8622
refactor: 매직넘버 제거
AppleMint98 Mar 19, 2025
4fe3ea9
refactor: draw 메서드의 반환값 일급 컬렉션 변경
AppleMint98 Mar 19, 2025
4f14767
refactor: 행위를 드러내도록 메서드 네이밍 변경
AppleMint98 Mar 19, 2025
239b12d
refactor: 플레이어들의 초기 패를 드로우할 시, 파라미터로 덱을 받도록 수정
AppleMint98 Mar 19, 2025
690bc81
refactor: 배당률을 MatchResult 의 필드로 옮기고, 배당금 계산 로직을 이관
AppleMint98 Mar 19, 2025
356c58c
style: import optimize
AppleMint98 Mar 19, 2025
18d5740
refactor: CsvSource -> MethodSource 변경
AppleMint98 Mar 19, 2025
6a3e5e6
refactor: 블랙잭 승패계산로직 Dealer와 분리
AppleMint98 Mar 19, 2025
5874976
feat: 초기 배팅금액 검증로직 추가
AppleMint98 Mar 19, 2025
a47ef45
style: 패키지 변경
AppleMint98 Mar 21, 2025
2d19054
feat(GamblerStatus): 갬블러의 게임 진행 상태를 나타내는 enum 구현
AppleMint98 Mar 21, 2025
3868de1
feat(BlackjackGame): BlackjackGame
AppleMint98 Mar 21, 2025
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: GameBoard 객체 생성 후 로직 이관
AppleMint98 committed Mar 16, 2025
commit 7d8fb3a8c565023e2a148e73dd79087966edcdfb
85 changes: 85 additions & 0 deletions src/main/java/blackjack/BlackjackTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package blackjack;

import blackjack.card.Card;
import blackjack.card.Cards;
import blackjack.card.Deck;
import blackjack.gambler.Dealer;
import blackjack.gambler.PlayerName;
import blackjack.gambler.Player;
import blackjack.gambler.Players;
import java.util.ArrayList;
import java.util.List;

public class BlackjackTable {

private final Deck deck;
private final Dealer dealer;
private final Players players;

public BlackjackTable(List<String> playerNames) {
validatePlayerCount(playerNames);
this.deck = Deck.initialize();
this.dealer = new Dealer();
this.players = registerPlayers(playerNames);
}

public void initializeGame() {
Cards dealerInitialCards = deck.drawInitialCards();
List<Cards> playerInitialCards = deck.drawInitialCards(getPlayersCount());
dealer.initializeHand(dealerInitialCards);
players.initializeHands(playerInitialCards);
}

private Players registerPlayers(List<String> names) {
return new Players(names.stream()
.map(PlayerName::new)
.map(nickname -> new Player(nickname, deck.drawInitialCards()))
.toList());
}

private void validatePlayerCount(List<String> playerNames) {
if (playerNames.isEmpty()) {
throw new IllegalArgumentException("[ERROR] 플레이어는 최소 한 명 이상 필요합니다.");
}
if (playerNames.size() > 6) {
throw new IllegalArgumentException("[ERROR] 플레이어는 최대 여섯 명 까지 지정할 수 있습니다.");
}
}

public int getPlayersCount() {
return players.getPlayers().size();
}

public List<String> getPlayerNames() {
return players.getPlayerNames();
}

public Players getPlayers() {
return players;
}

public Dealer getDealer() {
return dealer;
}

public void addCardTo(String playerName) {
Player player = findPlayer(playerName);
Card card = deck.drawOneCard();
player.addOneCard(card);
}

public Player findPlayer(String playerName) {
return players.findPlayer(playerName);
}

public void determineDealerAdditionalCard() {
if (dealer.isSumUnderThreshold()) {
Card card = deck.drawOneCard();
dealer.addOneCard(card);
}
}

public boolean isDealerDrawCard() {

}
}
24 changes: 24 additions & 0 deletions src/main/java/blackjack/constant/UserAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package blackjack.constant;

import java.util.Arrays;

public enum UserAction {

HIT("y"),
STAND("n"),
;

private final String command;

UserAction(String command) {
this.command = command;
}

public static UserAction from(String input) {
return Arrays.stream(values())
.filter(action -> action.command.equals(input))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("[ERROR] 올바른 기능을 입력해 주세요."));
}

}
30 changes: 30 additions & 0 deletions src/main/java/blackjack/gambler/PlayerName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package blackjack.gambler;

public class PlayerName {

public static final int NAME_LENGTH_LIMIT = 10;

private final String nickname;

public PlayerName(String nickname) {
validateNickNameLength(nickname);
validateNonBlank(nickname);
this.nickname = nickname;
}

public String getValue() {
return nickname;
}

private void validateNickNameLength(String nickname) {
if (nickname.length() > NAME_LENGTH_LIMIT) {
throw new IllegalArgumentException("[ERROR] 닉네임 길이는 " + NAME_LENGTH_LIMIT + "자를 초과할 수 없습니다.");
}
}

private void validateNonBlank(String nickname) {
if (nickname.isBlank()) {
throw new IllegalArgumentException("[ERROR] 닉네임은 빈 값을 입력할 수 없습니다.");
}
}
}
41 changes: 41 additions & 0 deletions src/test/java/domain/PlayerNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package domain;

import blackjack.gambler.PlayerName;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class PlayerNameTest {

@ParameterizedTest
@ValueSource(strings = {
"pobi", "jason", "nickname12"
})
void 닉네임_길이_범위_테스트(String nickname) {
// when // then
Assertions.assertDoesNotThrow(() -> new PlayerName(nickname));
}

@ParameterizedTest
@ValueSource(strings = {
"nickname123", "nickname1234", "nickname12345"
})
void 닉네임_길이_경계값_초과시_예외를_발생시킨다(String nickname) {
// when // then
org.assertj.core.api.Assertions.assertThatThrownBy(() -> new PlayerName(nickname))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("[ERROR] 닉네임 길이는 10자를 초과할 수 없습니다.");
}

@ParameterizedTest
@ValueSource(strings = {
"", " ", " "
})
void 닉네임이_빈값_입력_시_예외를_발생시킨다(String nickname) {
// when // then
org.assertj.core.api.Assertions.assertThatThrownBy(() -> new PlayerName(nickname))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("[ERROR] 닉네임은 빈 값을 입력할 수 없습니다.");
}

}