-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ์ ์ด์ฝฅ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1119
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: khcho96
Are you sure you want to change the base?
Changes from all commits
87b8cad
1b1c966
a7aa54b
a6539dc
caba72c
7035b92
640c510
28f5d22
51c80be
b78f443
7f3f851
c3004ea
7431a4e
7c75ff3
59130bb
eb50b41
cd807d3
841c634
fbf79e0
1b369ed
6c2486f
91e304c
0f4bfaf
3e0ec19
7872210
e06ffda
927179b
0990745
83da4c2
fc36d0f
595d088
3919a63
1dcc127
653e765
2f578fe
edf3ee0
98f6661
a4ea9eb
f2b48ac
c779f8c
92b7197
0583a0f
519dd99
9cb7d69
2589175
7da70e2
94613d9
5ca14ad
bd95be8
fcb8756
7bb91ad
2544ed3
10b0abf
f6e8e9a
121e289
dda1d77
06892b3
d8a5c95
59b8816
a34b82e
a290e93
5131913
e13c47b
f98a848
368f1bb
145bbc2
ca54fc8
276d6ff
214ee2d
a1c6f29
2757c76
eee034c
14cfcc1
afb1761
0df7db2
529ca7c
cd917e1
ae02ed2
1bb8255
4c28283
3da7d09
7650a5a
38c446b
ecaf295
8549a01
22d2ee1
09a2d3d
522fad1
f712103
3dc17b8
2578a5f
e244b53
f961d98
db6bbc3
f9c39d1
b252768
133cb90
55e5d33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์นํจํ๋จ์ด ํ์ํ๋ค -> ์นํจ ํ๋จ์๋ ๋๋ฌ์ ํ๋ ์ด์ด๊ฐ ํ์ํ๋ค -> ์นํจ๋ฅผ ํ๋จํ๋ ๊ฐ์ฒด๊ฐ ๋๋ฌ์ ํ๋ ์ด์ด๋ฅผ ์์กดํ๋๊ฒ์ ์์ฐ์ค๋ฝ๋ค
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์กดํ๋ ๊ฑธ ์ต๋ํ ์ง์ํด์ผ ํ๋ค๊ณ ์๊ฐํ๋๋ฐ, ๋ช ํํ ์ด์ ๊ฐ ์์ผ๋ฉด ๊ด์ฐฎ์ ๊ฒ์ด์๊ตฐ์! ๐ฎ ์ธ์ ์์กดํด์ผํ๋๊ฐ์ ๋ํ ๊ธฐ์ค๊ณผ ๊ทธ ๊ธฐ์ค์ ๋ํ ์ง๊ธ ์ํฉ์์์ ์ ์ฉ์ ์๋์ฒ๋ผ ์ ๋ฆฌํด๋ดค์ต๋๋ค! 1. ์ฑ ์์ ์ํํ๋ ค๋ฉด ์ ๋ง ๊ทธ ๊ฐ์ฒด๋ฅผ ์์์ผ ํ๋๊ฐ์นํจ ํ๋จ์ ์ฑ ์์ ๊ฐ์ง ๊ฐ์ฒด๋ผ๋ฉด ํ๋ ์ด์ด์ ๋๋ฌ์ ์ํ๋ฅผ ์์์ผ ์นํจ๋ฅผ ๋น๊ตํ ์ ์์ผ๋ ์์ฐ์ค๋ฌ์ด ์์กด์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. 2. ์์กดํ๋ ๊ฐ์ฒด์ ๊ตฌ์ฒด์ ์ธ ๋ด๋ถ ์ฌ์ ๊น์ง ๋ชฐ๋ผ๋ ๋๋๊ฐํ์ํ ์์กด์ ์์กดํ๋ ๊ฐ์ฒด์ ๋ฉ์๋ ํธ์ถ ์ ๋์ด๊ณ , ๋ถํ์ํ ์์กด์ ์์กดํ๋ ๊ฐ์ฒด์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ๊บผ๋ด์ ์ด๋ฆฌ์ ๋ฆฌ ์กฐ์ํ๋ ์์ค์ด๋ผ๊ณ ์๊ฐํ์ต๋๋ค. ์ฆ, ์์กดํ๋๋ผ๋ ๋ด๋ถ ๊ตฌํ๋ณด๋ค ์ญํ ์ ์์กดํ๋ ๊ฒ์ด ๋ ๋ฐ๋์งํ๋ค๊ณ ์๊ฐํฉ๋๋ค. 3. ์์กด ๋๋ฌธ์ ์ฑ ์์ด ์์ด์ง ์๋๊ฐ์์กด์ด ์๊ธฐ๋ฉด์ ์๋ ๋งก์ง ์์๋ ๋ ํ๋จ, ๊ณ์ฐ, ์ถ๋ ฅ, ์ ์ฅ ์ฑ
์๊น์ง ํจ๊ป ๊ฐ์ ธ์ค๊ฒ ๋๋ค๋ฉด ๊ทธ๊ฑด ๊ฒฝ๊ณ๊ฐ ํ๋ ค์ง๋ค๋ ๊ฒ์ด๋ฏ๋ก ์์กดํ๋ฉด ์๋๋ค๊ณ ์๊ฐํฉ๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊ธฐ์ค์ด ๋ช
ํํ๋ค์ ๐ ๐ ๐
Gomding marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| public class Hand { | ||
|
|
||
| private static final int BLACKJACK_SCORE = 21; | ||
| private static final int REDUCED_SCORE_FROM_ACE = 10; | ||
| private static final int INITIAL_CARD_COUNT = 2; | ||
|
|
||
| private final List<Card> cards; | ||
|
|
||
|
|
@@ -17,29 +19,49 @@ public void addCard(Card card) { | |
| cards.add(card); | ||
| } | ||
|
|
||
| public int calculateScore() { | ||
| int score = cards.stream() | ||
| .map(Card::getScore) | ||
| .reduce(0, Integer::sum); | ||
| int aceCount = cards.stream() | ||
| .filter(Card::isAce) | ||
| .toList() | ||
| .size(); | ||
| public int calculateTotalScore() { | ||
| int baseScore = calculateBaseScore(); | ||
| int aceCount = calculateAceCount(); | ||
|
|
||
| return calculateScoreWithBestAce(score, aceCount); | ||
| return calculateTotalScoreWithAceCalculation(baseScore, aceCount); | ||
| } | ||
|
|
||
| private int calculateScoreWithBestAce(int score, int aceCount) { | ||
| private int calculateInitialScore() { | ||
| int baseScore = calculateInitialBaseScore(); | ||
| int aceCount = calculateAceCount(); | ||
|
|
||
| return calculateTotalScoreWithAceCalculation(baseScore, aceCount); | ||
| } | ||
|
|
||
| private Integer calculateBaseScore() { | ||
| return cards.stream() | ||
| .map(Card::getScore) | ||
| .reduce(0, Integer::sum); | ||
| } | ||
|
|
||
| private Integer calculateInitialBaseScore() { | ||
| return cards.subList(0, INITIAL_CARD_COUNT).stream() | ||
| .map(Card::getScore) | ||
| .reduce(0, Integer::sum); | ||
| } | ||
|
Comment on lines
+36
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฝ๋์ ์ค๋ณต๋๋ ๋ถ๋ถ์ด ์์ด์ ์ค๋ณต๋๋ ๋ถ๋ถ๋ง private ๋ฉ์๋๋ก ์ถ์ถํด๋ณผ ์ ์๊ฒ ๋ค์
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ ํผ๋๋ฐฑ ์ ์ฉ ๊ณผ์ ์์ calculateInitialBaseScore ๋ฉ์๋๊ฐ ์ญ์ ๋์์ต๋๋ค! |
||
|
|
||
| private int calculateAceCount() { | ||
| return (int) cards.stream() | ||
| .filter(Card::isAce) | ||
| .count(); | ||
| } | ||
|
|
||
| private int calculateTotalScoreWithAceCalculation(int score, int aceCount) { | ||
| while (score > BLACKJACK_SCORE && aceCount > 0) { | ||
| score -= 10; | ||
| score -= REDUCED_SCORE_FROM_ACE; | ||
| aceCount--; | ||
| } | ||
|
|
||
| return score; | ||
| } | ||
|
|
||
| public boolean isBust() { | ||
| return calculateScore() > BLACKJACK_SCORE; | ||
| return calculateTotalScore() > BLACKJACK_SCORE; | ||
| } | ||
|
|
||
| public Card getFirstCard() { | ||
|
|
@@ -50,4 +72,8 @@ public List<Card> getCard() { | |
| return cards.stream() | ||
| .toList(); | ||
| } | ||
|
|
||
| public boolean isBlackjack() { | ||
| return calculateInitialScore() == BLACKJACK_SCORE; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
๋ธ๋์ญ์ ํจ๊ฐ 2์ฅ + 21์ ์ผ ๋ ๋ฅผ ๋ธ๋์ญ์ด๋ ์ํ๋ก ๋ณด๊ณ ์์ด์~
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ์ฌ calculateInitialScore()๊ฐ ์ฒ์ ๋ฐ์ 2์ฅ์ด 21์ผ ๋๋ฅผ Blackjack์ผ๋ก ๋ณด๊ณ ์๋๋ฐ, ๊ทธ๋ฅ calculateTotalScore() == BLACKJACK_SCORE์ด๋ฉด์ cards.size() == 2์ธ ๊ฒ์ ๋ณด๋๊ฒ ์ ํํ๊ฒ ๊ตฐ์! ํด๋น๋ถ๋ถ ์์ ๊ฐ์ด ์์ ํ์ต๋๋ค! |
||
| } | ||
| } | ||
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.
constant ๋ผ๋ ํจํค์ง๋ ๋ณดํต์ ๋ฐ๋ก ๊ด๋ฆฌํ์ง ์๋๊ฒ์ ์งํฅํด์!
์์๋ผ๋ ๊ฐ๋ค์ ๋๋ถ๋ถ ํน์ ํด๋์ค์ ์์นํ๋๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํด์~
์์๋ฅผ ๋ชจ์๋ ํด๋์ค๋ฅผ ๋ถ๋ฆฌํด์ผํ๋คํด๋ constant ๋ผ๋ ํจํค์ง๋ก ๋ถ๋ฆฌํ๊ธฐ๋ณด๋ค๋ ์ฌ์ฉํ๋ ํจํค์ง ์์ ์์ฐ์ค๋ฝ๊ฒ ์์น์ํต๋๋ค
๊ณตํต์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ ๋ชจ์๋๋ ํจํค์ง๊ฐ ์์ ์ ์์ง๋ง
๊ทธ๊ณณ์ ํด๋์ค๋ฅผ ๋๋๋๊ฒ ๋ง๋์ง๋ ๊ฒ์ฆ์ ์ ํ๋๊ฒ ์ข๋ค๊ณ ์๊ฐํด์ :)
๊ทธ๋งํผ
๊ณต์ฉ์ด๋ผ๋ ๊ณต๊ฐ์ ๋ค๋ฅธ ์ฌ๋ฌ ๊ณณ์์ ์์กดํ ๊ฐ๋ฅ์ฑ์ ์ด์ด๋๋๊ฒ์ด๋๊น์๋ง์๊ณณ์์
๊ณต์ฉ ํจํค์ง๋ฅผ ์์กดํ๋ ๊ฒ์ ๋จ์ ์ ๋ฌด์์ผ๊น์?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.
๋ง์ํด์ฃผ์ ๋๋ก ๊ณต์ฉ ํจํค์ง๋ฅผ ๋ง์ ๊ณณ์์ ์์กดํ๋ฉด ๋ณ๊ฒฝ ๋ฒ์๊ฐ ๋์ด์ง๊ณ ๊ฒฐํฉ๋๊ฐ ๋์์ง๊ฒ ๋ค์. ๋ํ ๊ฐ ๊ฐ์ฒด๊ฐ ๊ฐ์ ธ์ผ ํ ์ฑ ์๊น์ง ๊ณต์ฉ์ผ๋ก ๋น ์ง ์ํ์ด ์์ด์, ์ฑ ์์ ๊ฒฝ๊ณ๊ฐ ํ๋ ค์ง๊ณ ์์ง๋๊ฐ ๋ฎ์์ง ์ ์๋ค๋ ์๊ฐ์ด ๋ญ๋๋ค.
๋ค์ ์๊ฐํด๋ณด๋ฉด, ๊ณต์ฉ์ผ๋ก ์ฌ์ฉ๋๋ ๊ฒ๋ ์์ง๋ง ์ฑ ์์ ๊ฒฝ๊ณ๋ฅผ ๋ช ํํ ์ ํ๊ธฐ ์ ๋งคํด์ "๊ณต์ฉ"์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ฌถ์ด๋์ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค๐