Skip to content

[0] 블랙잭#3

Open
deok-beom wants to merge 13 commits intoCODE-CLEANERS:mainfrom
deok-beom:level_2_blackjack
Open

[0] 블랙잭#3
deok-beom wants to merge 13 commits intoCODE-CLEANERS:mainfrom
deok-beom:level_2_blackjack

Conversation

@deok-beom
Copy link

@deok-beom deok-beom commented Nov 23, 2023

아이고 브랜치를 잘못땄네요.
람다, 스트림, 옵셔널 실습은 커밋 내용이 보이는데 코드는 없을겁니다..

1. 열거형 Card를 열거형 Rank, 열거형 Suit, 클래스 Card로 변경
2. Game 클래스를 GameHandler로 변경
3. Game 클래스에서 화면에 입력/표시하는 기능을 Game Input/Output View로 분리
4. 기존 Game 클래스에서 각 플레이어의 배팅 금액을 Map으로 관리하던 것을 플레이어 객체 스스로가 저장하도록 변경, 이에 따라 수익 계산도 플레이어 객체가 스스로가 수행하도록 변경
Copy link
Collaborator

@ca1af ca1af left a comment

Choose a reason for hiding this comment

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

너무 멋진 구현입니다!! 역쉬 범스타 ㅎㅎ

리팩토링 할 게 있을까? 싶은 구현이긴 하지만, 굳이 한번 연습해보자는 취지로 몇 가지 제한사항을 남겨봅니다.

  1. 클래스의 길이는 최대 60~70 라인 안으로
  2. 매서드의 길이는 15라인 안쪽으로
  3. 인덴트는 1로 고정

위와 같이 연습해보면 어떨까요? 클래스와 매서드를 조금 더 빡빡하게 구분하는 연습을 해보는 것도 재미있을 것 같습니다. 더불어 구현하면서 제가 노력한 부분은

  1. 객체가 재사용 가능할 것 (즉, 중복이 없을 것)
  2. 객체가 변경에 열려있을 것.

에 집중했는데, 범스타는 어떤 부분을 신경썼는지 궁금합니다!

Comment on lines 27 to 37
private List<Card> shuffleDeck(List<Card> cards) {
Random random = new Random();
List<Card> shuffledDeck = new LinkedList<>();
for (int i = cards.size(); i > 0; i--) {
int pick = random.nextInt(cards.size());
shuffledDeck.add(cards.get(pick));
cards.remove(pick);
}

return shuffledDeck;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

같은 랜덤값이 또 나오면 어떻게 되나요? (ex : 5 -> 5)

Copy link
Author

@deok-beom deok-beom Nov 24, 2023

Choose a reason for hiding this comment

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

ArrayList는 값을 remove하면 뒤의 값들이 다시 자리를 채우기 때문에 로직 상으로는 문제 없읍니다.
근데 지금 보니까 ArrayList는 remove()에 인덱스를 전달하면 데이터를 삭제하고 해당 데이터를 반환해주기 때문에 이부분은 최적화 할 수 있을 것 같네요

Comment on lines 30 to 34
String[] names = in.get().split(",");
for (String name : names) {
Player player = new Player(name);
players.add(player);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

입력값을 검증하는 로직을 추가해보면 어떨까요?

Comment on lines 48 to 60
private int addNumber(Card hand, int sum) {
int number = hand.getNumber();
if (hand.isAce() && sum + number > 21) {
return sum + 1;
}

return sum + number;
}

public boolean isBust() {
int result = calculateHands();
return result > 21;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

원시값을 포장하면 어떨까요? 21이라는 숫자의 의미가 명확해질 것 같습니다.

Comment on lines 49 to 52
int number = hand.getNumber();
if (hand.isAce() && sum + number > 21) {
return sum + 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

더불어 Card hand 는 card 라는 이름이 더 낫지 않았을까 싶습니당. 이부분은 취향인듯!

Comment on lines 8 to 13
public class Player {
protected final String name;
protected final List<Card> hands;
protected double chip;
private int batAmount;

Copy link
Collaborator

Choose a reason for hiding this comment

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

실생활을 생각하면 Player 가 핸드를 계산(숫자 합 계산) 하는 것이 자연스럽지만, 플레이어의 책임이 더 커지게 된다면? 혹은 Hand를 계산하는 로직이 더 복잡해진다면? 해당 클래스의 책임이 과도해 질 것 같습니다. 객체로 분리해보는것은 어떨까요?

1. 원시값 포장
2. 핸드 객체를 만들어 손패를 계산하는 로직을 이관함
3. 클래스의 길이는 최대한 70라인에 가깝게, 매서드의 길이는 최대한 15라인에 가깝게, 인덴트는 1로 고정
Copy link
Collaborator

@ca1af ca1af left a comment

Choose a reason for hiding this comment

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

매서드체이닝 넘모 머싯습니당

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.

2 participants