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

πŸš€ 3단계 - λΈ”λž™μž­(λ”œλŸ¬) #653

Open
wants to merge 81 commits into
base: moto6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
4530961
refactor : μ™ΈλΆ€μ—μ„œ λΈ”λž™μž­ μΉ΄λ“œλ₯Ό λ½‘λŠ” μ „λž΅μ„ μ£Όμž…λ°›λ„λ‘ λ¦¬νŒ©ν† λ§
Nov 19, 2023
768e5e8
learn : λ―Έμ™„μ„± ν•™μŠ΅μ½”λ“œλ₯Ό μ™„μ„±μ‹œν‚΄ : 방어적 볡사 κ΄€λ ¨ μ˜ˆμ œμ½”λ“œ
Nov 19, 2023
f595abb
learn : λ―Έμ™„μ„± ν•™μŠ΅μ½”λ“œλ₯Ό μ™„μ„±μ‹œν‚΄ : 방어적 볡사 κ΄€λ ¨ μ˜ˆμ œμ½”λ“œ μž‘μ„±
Nov 19, 2023
2c3439f
learn : λ―Έμ™„μ„± ν•™μŠ΅μ½”λ“œλ₯Ό μ™„μ„±μ‹œν‚΄ : 방어적 볡사 κ΄€λ ¨ μ˜ˆμ œμ½”λ“œ μž‘μ„±
Nov 19, 2023
ec334d4
refactor : Pair<> 자료ꡬ쑰λ₯Ό ν•˜λ‚˜μ˜ 클래슀둜 묢음
Nov 19, 2023
2196d5b
refactor : κ³Όλ„ν•˜κ²Œ κΈΈκ³  λ‹€μ†Œ λΆ€μ‘±ν•œ ν‘œν˜„μ˜ λ³€μˆ˜λͺ…을 μ μ ˆν•˜κ²Œ μˆ˜μ •
Nov 19, 2023
193b74b
docs : μš”κ΅¬μ‚¬ν•­ 뢄석
Nov 19, 2023
2e6ed51
test : λ”œλŸ¬ 클래슀λ₯Ό μΆ”κ°€ν•˜κ³ , λ”œλŸ¬ν΄λž˜μŠ€μ—μ„œ μ±…μž„μ €μ•Όν•  역할에 λŒ€ν•΄ ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„±
Nov 19, 2023
dc3c6f6
feat : μ°Έκ°€μž λͺ…단에 λ”œλŸ¬ μΆ”κ°€
Nov 19, 2023
01dd4ca
refactor : ν”Œλ ˆμ΄μ–΄λ‘œ λ³€μˆ˜λͺ… μˆ˜μ •
Nov 19, 2023
c294555
refactor : λ”œλŸ¬ 클래슀 μΆ”κ°€
Nov 19, 2023
2f9e2f2
refactor : λ”œλŸ¬μ˜ 역할에 λŒ€ν•œ ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„±
Nov 19, 2023
cf0f5f2
refactor : λ”œλŸ¬μ˜ 역할에 λŒ€ν•œ ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„±
Nov 21, 2023
c651d71
feat : λ”œλŸ¬ 클래슀의 κΈ°λŠ₯ κ΅¬ν˜„
Nov 21, 2023
1f8d48f
feat : λ”œλŸ¬ κΈ°λŠ₯ κ΅¬ν˜„μ„ μœ„ν•œ 클래슀 μž‘μ„±
Nov 22, 2023
2008753
feat : λ”œλŸ¬ κΈ°λŠ₯ κ΅¬ν˜„
Nov 22, 2023
0cf2ee0
feat : λ”œλŸ¬ κΈ°λŠ₯ κ΅¬ν˜„
Nov 23, 2023
d5d036d
test : 클래슀 μ΄μ „μœΌλ‘œ μΈν•œ μ±…μž„μ†Œμž¬ λ³€κ²½μœΌλ‘œ ν…ŒμŠ€νŠΈλ₯Ό μ΄λ™μ‹œν‚¨λ‹€
Nov 23, 2023
e1a92a3
feat : λ”œλŸ¬ 좜λ ₯ κΈ°λŠ₯ κ΅¬ν˜„
Nov 23, 2023
fd08d2e
feat : λ”œλŸ¬ 좜λ ₯ κΈ°λŠ₯ κ΅¬ν˜„
Nov 23, 2023
72c2a9f
feat : λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄κ°„ 곡톡 λ™μž‘μ„ μΈν„°νŽ˜μ΄μŠ€λ‘œ 묢음
Nov 23, 2023
405c44e
feat : λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄κ°„ 곡톡 λ™μž‘μ„ μΈν„°νŽ˜μ΄μŠ€λ‘œ 묢음
Nov 23, 2023
3fc2d98
feat : λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄κ°„ 곡톡 λ™μž‘μΈ κ²Œμž„ ν”Œλ ˆμ΄λ₯Ό μΈν…ŒνŽ˜μ΄μŠ€λ‘œ 좔상화함
Nov 23, 2023
118b83b
feat : λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄μ˜ λΈ”λž™μ  ν”Œλž˜μ΄μ˜ μ „λž΅μ„ μΈν„°νŽ˜μ΄μŠ€ν™” ν•œλ‹€
Nov 23, 2023
bc99f47
feat : 깨진 ν…ŒμŠ€νŠΈμ½”λ“œ 제거
Nov 23, 2023
0e3a932
refactor : νŒ¨ν‚€μ§€ ꡬ쑰화
Nov 24, 2023
73c8890
refactor : λΆˆν•„μš”ν•œ 주석 제거
Nov 24, 2023
cea03de
refactor : νŒ¨ν‚€μ§€ 이동
Nov 24, 2023
030b03f
refactor : μœ„μΉ˜ λ³€κ²½
Nov 25, 2023
f3ce24d
refactor : ν”½μŠ€μ³λ₯Όμ΄μš©ν•΄μ„œ λ°˜λ³΅λ˜λŠ” 데이터 생성 쀑볡 μ½”λ“œλ₯Ό 제거
Nov 25, 2023
b90b454
refactor : 검증 단언문을 좔가함
Nov 25, 2023
8426423
refactor : λΈ”λž™μž­ κ²Œμž„μœΌλ‘œ 클래슀λ₯Ό 뢄리함
Nov 25, 2023
a83a725
refactor : λ©”μ„œλ“œλͺ… μˆ˜μ •
Nov 25, 2023
a33565d
refactor : λ”œλŸ¬μ˜ 결과정보λ₯Ό λ§Œλ“€κΈ° μœ„ν•΄μ„œ μ‹¬νŒμ΄ μ •ν•˜λŠ”κ²ƒμ΄ μ•„λ‹Œ, λ”œλŸ¬ 객체 λ‚΄λΆ€μ—μ„œ λ”œλŸ¬μ˜ κ²°κ³Όλ₯Ό λ§Œλ“€λ„λ‘ μˆ˜μ •
Nov 25, 2023
5267bff
refactor : 결과정보λ₯Ό 좜λ ₯ν•˜κΈ° μœ„ν•΄ λ‹€λ₯Έ ν”Œλ ˆμ΄μ–΄λΈ”μ„ μž…λ ₯받도둝 μˆ˜μ •
Nov 25, 2023
fb97643
refactor : κ³Όλ„ν•˜κ²Œ λ³΅μž‘ν•œ result 객체듀을 μ œκ±°ν•œλ‹€
Nov 25, 2023
7abf5ad
refactor : λΈ”λž™μž­μ˜ 점수λ₯Ό λ‚˜νƒ€λ‚΄λŠ” 도맀인 포μž₯클래슀λ₯Ό μΆ”κ°€ν•œλ‹€
Nov 26, 2023
3ee585d
refactor : BlackJack() 도맀인 포μž₯클래슀λ₯Ό μ μš©ν•œλ‹€
Nov 26, 2023
7c15dae
refactor : BlackJack() 도맀인 포μž₯클래슀λ₯Ό μ μš©ν•΄μ„œ ν”Œλ ˆμ΄μ–΄λΈ” μΈν„°νŽ˜μ΄μŠ€μ—μ„œ λ©”μ‹œμ§€λ‘œ μ‚¬μš©ν•˜κ²Œ μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€
Nov 26, 2023
73e3a94
refactor : λΈ”λž™μž­μ˜ κ²°κ³Όλ₯Ό λ‚˜νƒ€λ‚΄λŠ” 방법을 κ°œμ„ ν•΄μ„œ μž…λ ₯ arg 둜 λ°›λŠ” 클래슀λ₯Ό λ³€κ²½ν•˜μ˜€μŠ΅λ‹ˆλ‹€
Nov 26, 2023
0f0ea7d
refactor : burst μ—¬λΆ€λ₯Ό μ™ΈλΆ€μ˜ 객체(Referee) κ°€ 값을 κΊΌλ‚΄μ„œ νŒλ‹¨ν•΄μ£Όλ˜ κΈ°μ‘΄ 방식을 μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
Nov 26, 2023
8481f0e
refactor : λ¦¬νŒ©ν† λ§μ„ ν•˜λ‹€ λ³΄λ‹ˆ μ‹¬νŒ 역할을 ν•˜λŠ” Referee λ₯Ό μ œκ±°ν• μˆ˜ 있게 λ˜μ—ˆμŠ΅λ‹ˆλ‹€
Nov 26, 2023
9df4b97
refactor : λŠ˜μ–΄λ‚œ player, Dealer 클래슀의 μ±…μž„κ³Ό 역할을 κ²€μ¦ν•˜κΈ° μœ„ν•΄ λ‹¨μœ„ν…ŒμŠ€νŠΈλ„ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€
Nov 26, 2023
bc61788
refactor : λ”œλŸ¬μ˜ κ²°κ³Όλ₯Ό λ”œλŸ¬ 클래슀 λ‚΄λΆ€μ—μ„œ κ²°μ •ν•˜λ„λ‘ μˆ˜μ •
Nov 26, 2023
a0f1238
refactor : λͺ¨λ“  ν”Œλ ˆμ΄μ–΄λŠ” νƒˆλ½ν• λ•ŒκΉŒμ§€ μΉ΄λ“œλ₯Ό 받을 수 μžˆλ‹€ κΈ°λŠ₯을 κ΅¬ν˜„
Nov 26, 2023
57bc00c
refactor : μΈν…”λ¦¬μ œμ΄ μ›Œλ‹μ΄ λœ¨μ§€μ•Šλ„λ‘ κ²½κ³ λ₯Ό μˆ˜μ •
Nov 26, 2023
f96536d
refactor : λΈ”λž™μž­ κ²Œμž„μ˜ 룰인, ν”Œλ ˆμ΄μ–΄μ€‘ μ΅œν›„ν¬ ν•œλͺ…이 λ‚¨μ„λ•ŒκΉŒμ§€ μΉ΄λ“œλ₯Ό 받을 수 μžˆλ‹€
Nov 26, 2023
caf5ab4
refactor : λΈ”λž™μž­ κ²Œμž„μ—μ„œ μΉ΄λ“œλ₯Όλ½‘λŠ” 정책을 μ™ΈλΆ€μ—μ„œ μ£Όμž… 받도둝 μˆ˜μ •
Nov 26, 2023
d15d30e
refactor : λΆˆν•„μš”ν•œ λ©”μ„œλ“œ 제거
Nov 26, 2023
149d549
refactor : λΈ”λž™μž­μ˜ μƒνƒœλ₯Ό λ‚˜νƒ€λ‚΄λŠ” λ³€μˆ˜ μΆ”κ°€
Nov 26, 2023
fd79141
refactor : λΈ”λž™μž­ κ²Œμž„μ—μ„œ ν”Œλ ˆμ΄μ–΄μ˜ μƒνƒœλ₯Ό 확인할 수 μžˆλŠ” λ³€μˆ˜ μΆ”κ°€
Nov 26, 2023
92ec4b5
refactor : λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄κ°€ 생쑴여뢀에 λŒ€ν•΄μ„œ μƒνƒœλ₯Ό μ €μž₯ν•˜μ§€ μ•Šκ³  맀번 κ³„μ‚°ν•˜λ„λ‘ μˆ˜μ •
Nov 26, 2023
0bde0c3
style : style formatting
Nov 26, 2023
b58ab33
test : λ³€ν™”λœ μ±…μž„κ³Ό 역할에 따라 ν…ŒμŠ€νŠΈμ½”λ“œ 이동 및 μΆ”κ°€
Nov 26, 2023
57d5ed8
test : ν”Œλ ˆμ΄μ–΄κ°€ μ΄κΈ°λŠ” κ²½μš°μ— λŒ€ν•œ ν…ŒμŠ€νŠΈμ½”λ“œ μΆ”κ°€
Nov 26, 2023
ec56d38
test : λ”œλŸ¬ ν΄λž˜μŠ€μ— λŒ€ν•œ ν…ŒμŠ€νŠΈ μ½”λ“œ μΆ”κ°€
Nov 26, 2023
de4eb89
style : μŠ€νƒ€μΌ ν¬λ©”νŒ…
Nov 26, 2023
f7d07c5
refactor : μ •μ±…μ—μ„œ μž…λ ₯을 받도둝 μˆ˜μ •
Nov 26, 2023
a2a5e6e
refactor : νŒ¨ν‚€μ§€ 이동
Nov 26, 2023
1292c65
refactor : ν”Œλ ˆμ΄μ–΄ 이름을 좜λ ₯ν•˜λ„λ‘ μˆ˜μ •
Nov 26, 2023
3e17672
refactor : 좜λ ₯ 둜직 점검
Nov 26, 2023
9a47953
refactor : 좜λ ₯ 둜직 점검
Nov 26, 2023
515e2a9
refactor : λΆˆν•„μš”ν•œ μ½”λ“œ 제거
Nov 26, 2023
cbf46fc
feat : κ²€μ¦μš© ν•œμ€„, λ””λ²„κΉ…ν¬μΈνŠΈ
Nov 26, 2023
953086a
refactor : νŒ¨ν‚€μ§€ 이동
Nov 27, 2023
9bd27f7
refactor : νŒ¨ν‚€μ§€ 이동
Nov 27, 2023
f3773b7
test : μ—λŸ¬κ°€ λ‚˜λŠ” λΆ€λΆ„μ˜ ν…ŒμŠ€νŠΈμ½”λ“œ μΆ”κ°€
Nov 27, 2023
a81cff6
refactor : 가독성을 늘리기 μœ„ν•΄ νŒŒλ¦¬λ―Έν„° 넀이밍
Nov 27, 2023
f0a699c
refactor : νŒ¨ν‚€μ§€ ꡬ쑰 정리
Nov 27, 2023
d7d3af1
refactor : νŒ¨ν‚€μ§€ ꡬ쑰 정리
Nov 27, 2023
1d1e228
refactor : λΈ”λž™μž­μ˜ κ²½κΈ° κ²°κ³Όλ₯Ό μ •ν•΄μ£ΌλŠ” 클래슀 뢄리
Nov 27, 2023
043ffcc
test : λΈ”λž™μž­μ˜ 룰을 λͺ°λΌ μž‘μœ„μ μœΌλ‘œ μ •ν–ˆλ˜ ν…ŒμŠ€νŠΈμ½”λ“œλ“€μ„ μˆ˜μ •
Nov 27, 2023
930745b
test : λΈ”λž™μž­μ˜ κ²½κΈ° κ²°κ³Όλ₯Ό κ²°μ •ν•˜λŠ” ν…ŒμŠ€νŠΈμ½”λ“œλ₯Ό μž‘μ„±ν•œλ‹€
Nov 27, 2023
366b2b2
test : stand λ₯Ό μ™ΈμΉ˜λ©΄ μžλ™μœΌλ‘œ 더이상 μΉ΄λ“œλ₯Ό 받을 수 μ—†λŠ” μƒνƒœκ°€ λ˜μ–΄μ•Όν•œλ‹€
Nov 27, 2023
be3bc4d
bugfix : 버그가 λ‚˜λŠ” 뢀뢄을 μˆ˜μ •
Nov 27, 2023
b20b5c5
refactor : 잘λͺ» μž‘μ„±λœ ν…ŒμŠ€νŠΈμ½”λ“œ μˆ˜μ •
Nov 27, 2023
4f07cb3
refactor : 좜λ ₯ν˜•μ‹ μˆ˜μ •
Nov 27, 2023
e4a59a0
bugfix : λ”œλŸ¬μ˜ 승패 좜λ ₯ 버그λ₯Ό μˆ˜μ •
Nov 27, 2023
9632f36
test : ν…ŒμŠ€νŠΈμ½”λ“œ μΆ”κ°€
Nov 27, 2023
53faf16
refactor : μƒμ„±μž νŒŒλΌλ―Έν„° μΆ”κ°€
Nov 27, 2023
4769e26
bugfix: λ²„κ·Έμˆ˜μ •
Nov 27, 2023
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,26 @@ Player.hit() : λΈ”λž™μž­μ—μ„œ μΉ΄λ“œλ₯Ό λ°›λŠ” 행동은 "히트" λ”œλŸ¬κ°€
- λ§€μ§λ„˜λ²„, λ§€μ§μŠ€νŠΈλ§μ„ μƒμˆ˜λ‘œ 뢄리해내기 (특히 view, model)
- μ–΄λ–€ ν…ŒμŠ€νŠΈμ½”λ“œκ°€ ν•„μš”ν•œμ§€ μƒκ°ν•˜κ³ (뭘 κ΅¬ν˜„ν•΄μ•Όν•˜μ§€, 뭐가 μš”κ΅¬μ‘°κ±΄μΈμ§€ λ¦¬λ§ˆμΈλ“œ) >> ν…ŒμŠ€νŠΈμ½”λ“œλ₯Ό μž‘μ„±ν•˜κ³  >> ν…ŒμŠ€νŠΈν• μˆ˜ μžˆλ„λ‘ λ¦¬νŒ©ν† λ§ν•˜κΈ°
```

<br><br>

## πŸš€ 3단계 - λΈ”λž™μž­(λ”œλŸ¬)

- μš”κ΅¬μ‚¬ν•­ 뢄석
```text
- λ”œλŸ¬ κΈ°λŠ₯을 κ΅¬ν˜„
- λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄ 쀑 μΉ΄λ“œμ˜ 합이 21 λ˜λŠ” 21에 κ°€μž₯ κ°€κΉŒμš΄ 숫자λ₯Ό κ°€μ§€λŠ” μͺ½μ΄ μ΄κΈ°λŠ” κΈ°λŠ₯을 κ΅¬ν˜„
- λ”œλŸ¬λŠ” μ²˜μŒμ— 받은 2μž₯의 합계가 16μ΄ν•˜μ΄λ©΄ λ°˜λ“œμ‹œ 1μž₯의 μΉ΄λ“œλ₯Ό μΆ”κ°€λ‘œ λ°›μ•„μ•Ό ν•˜κ³ , 17점 이상이면 μΆ”κ°€λ‘œ 받을 수 μ—†λ‹€
- λ”œλŸ¬μ˜ 히트/μŠ€ν…λ“œ μ „λž΅μ€ μžλ™μ΄λΌλŠ” μ˜λ―Έμž„. ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„± ν•„μš”

- μ‹¬νŒκΈ°λŠ₯(Referee) : μ μˆ˜κ³„μ‚° $& 승패λ₯Ό νŒλ‹¨
- λ”œλŸ¬κ°€ 21을 μ΄ˆκ³Όν•˜λ©΄ κ·Έ μ‹œμ κΉŒμ§€ 남아 있던 ν”Œλ ˆμ΄μ–΄λ“€μ€ 가지고 μžˆλŠ” νŒ¨μ— 상관 없이 μŠΉλ¦¬ν•œλ‹€.
- λΈ”λž™μž­ κ²Œμž„μ€ λ”œλŸ¬μ™€ ν”Œλ ˆμ΄μ–΄ 쀑 μΉ΄λ“œμ˜ 합이 21 λ˜λŠ” 21에 κ°€μž₯ κ°€κΉŒμš΄ 숫자λ₯Ό κ°€μ§€λŠ” μͺ½μ΄ 이긴닀

-μž…μΆœλ ₯ κΈ°λŠ₯
- κ²Œμž„μ„ μ™„λ£Œν•œ ν›„ 각 ν”Œλ ˆμ΄μ–΄λ³„λ‘œ 승패λ₯Ό 좜λ ₯

```


walkover - λΆ€μ „μŠΉ, λ‚™μŠΉ : μƒλŒ€λ°©(λ”œλŸ¬μ˜ λͺ°μˆ˜νŒ¨λ‘œ μ΄κΈ°λŠ”)
26 changes: 18 additions & 8 deletions src/main/kotlin/blackjack/Controller.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
package blackjack

import blackjack.model.DealerStrategy
import blackjack.model.Participants
import blackjack.model.PlayableReaction
import blackjack.model.Player
import blackjack.model.Referee
import blackjack.model.pack.ShuffledPack
import blackjack.view.InputView
import blackjack.view.OutputView

fun main() {
val participants = InputView.join()
participants.dealing()
participants.dealing(ShuffledPack)
OutputView.dealing(participants)
OutputView.presentCards(participants)
while (participants.isContinue()) {
playingBlackJack(participants)
}
OutputView.result(participants)
OutputView.presentScores(participants)
OutputView.presentResult(Referee.blackJackResult(participants))
}

fun playingBlackJack(participants: Participants) {
participants.participants.forEach {
it.hitOrStand()
participants.players.values.forEach {
it.playing(InputView.askHit(it), ShuffledPack)
}
when (participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack)) {
PlayableReaction.HIT -> println("λ”œλŸ¬λŠ” 16μ΄ν•˜λΌ ν•œμž₯의 μΉ΄λ“œλ₯Ό 더 λ°›μ•˜μŠ΅λ‹ˆλ‹€.")
PlayableReaction.STAND -> println("λ”œλŸ¬λŠ” 17이상이라 μΉ΄λ“œλ₯Ό 받지 μ•Šμ•˜μŠ΅λ‹ˆλ‹€.")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

λΈ”λž™μž­ 룰이 잘 λ°˜μ˜λ˜μ–΄μžˆμ§€ μ•Šμ•„ λ³΄μ—¬μš”.
μ•„λž˜ 룰듀이 λ°˜μ˜λ˜μ–΄μžˆμ§€ μ•Šμ•„μ„œ, λΈ”λž™μž­ 룰을 λ‹€μ‹œ ν•œ 번 νŒŒμ•…ν•΄λ³΄μ‹  ν›„ ν”„λ‘œμ νŠΈμ— λ°˜μ˜ν•΄λ³΄λŠ” 건 μ–΄λ–¨κΉŒμš”?

  • ν”Œλ ˆμ΄μ–΄λŠ” Bust 되기 μ „κΉŒμ§€ Hitλ₯Ό ν•  수 μžˆλ‹€.
  • λ”œλŸ¬λŠ” ν”Œλ ˆμ΄μ–΄κ°€ λͺ¨λ‘ μ°¨λ‘€λ₯Ό μ§„ν–‰ν•œ λ’€ μΉ΄λ“œ 뽑기λ₯Ό μ§„ν–‰ν•œλ‹€.


private fun Player.hitOrStand() {
if (InputView.askHit(this)) {
this.hit()
}
OutputView.playerCardPresent(this)

// if () {
// this.hit(ShuffledPack)
// }
// OutputView.playerCardPresent(this)
}
moto6 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions src/main/kotlin/blackjack/model/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ class Card private constructor(
val cardRank: CardRank,
) {
companion object {
private val CARDS: Map<Pair< Suit, CardRank>, Card> by lazy {
private val CARDS: Map<Trump, Card> by lazy {
Suit.values().flatMap { suit ->
CardRank.values().map { rank ->
(suit to rank) to Card(suit, rank)
Trump(suit to rank) to Card(suit, rank)
}
}.toMap()
}

fun of(suit: Suit, cardRank: CardRank): Card {
return requireNotNull(this.CARDS[suit to cardRank]) { "μž…λ ₯된 suit=[$suit] , cardRank=[$cardRank] λŠ” μ°Ύμ„μˆ˜ μ—†μŠ΅λ‹ˆλ‹€" }
return requireNotNull(this.CARDS[Trump(suit to cardRank)]) { "μž…λ ₯된 suit=[$suit] , cardRank=[$cardRank] λŠ” μ°Ύμ„μˆ˜ μ—†μŠ΅λ‹ˆλ‹€" }
}
}
}
6 changes: 3 additions & 3 deletions src/main/kotlin/blackjack/model/Cards.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Cards(

private fun scoreWithAce(): Int {
val simpleSum = simpleSumOfScore()
if (simpleSum + ALTERNATIVE_ACE_SCORE_DIFF > HIGHEST_SCORE) {
if (simpleSum + ACE_BONUS_SCORE > HIGHEST_SCORE) {
return simpleSum
}
return simpleSum + ALTERNATIVE_ACE_SCORE_DIFF
return simpleSum + ACE_BONUS_SCORE
}

fun count(): Int {
Expand All @@ -40,7 +40,7 @@ class Cards(

companion object {
Copy link
Member

Choose a reason for hiding this comment

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

Cards 객체λ₯Ό λΆˆλ³€ 객체둜 λ§Œλ“€μ–΄λ³΄λŠ” μ‹œλ„λ₯Ό 해보셔도 μ’‹κ² λ„€μš” πŸ™‚

private const val HIGHEST_SCORE: Int = 21
private const val ALTERNATIVE_ACE_SCORE_DIFF: Int = 11 - 1
private const val ACE_BONUS_SCORE: Int = 10

fun emptyCards(): Cards {
return Cards(mutableListOf())
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/blackjack/model/Dealer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package blackjack.model

import blackjack.model.pack.Pack

class Dealer(
val cards: Cards = Cards(),
) : Playable {

override fun score(): Int {
return cards.totalScore()
}

override fun dealing(pack: Pack) {
this.cards.add(pack.pickCard())
this.cards.add(pack.pickCard())
}

fun countOfCards(): Int {
return cards.count()
}

override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction {
if (playingStrategy.isHit()) {
cards.add(pack.pickCard())
return PlayableReaction.HIT
}
return PlayableReaction.STAND
}

companion object {
private const val DEALER_PICK_THRESHOLD = 16
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/blackjack/model/DealerResult.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package blackjack.model

data class DealerResult(
val point: Int,
val winning: Int,
val drawing: Int,
val losing: Int,
)
14 changes: 14 additions & 0 deletions src/main/kotlin/blackjack/model/DealerStrategy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package blackjack.model

class DealerStrategy(
private val currentScore: Int,
) : PlayingStrategy {

override fun isHit(): Boolean {
return currentScore <= DEALER_PICK_THRESHOLD
}

companion object {
private const val DEALER_PICK_THRESHOLD = 16
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/blackjack/model/ParticipantResults.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package blackjack.model

class ParticipantResults(
val playerResults: PlayersResults,
val dealerDealerResult: Pair<Dealer, DealerResult>,
) {
fun dealerResult(): DealerResult {
return dealerDealerResult.second
}

fun playerResult(player: Player): PlayerResult {
return playerResults.resultOfPlayer(player)
}

fun dealerWinCount(): Int {
return this.dealerDealerResult.second.winning
}

fun dealerLoseCount(): Int {
return this.dealerDealerResult.second.losing
}

companion object {
fun ofDealerLose(participants: Participants): ParticipantResults {
return ParticipantResults(
PlayersResults(participants.players.walkover()),
participants.dealer to DealerResult(participants.dealer.score(), 0, 0, participants.count() - 1)
)
}
}
}
19 changes: 12 additions & 7 deletions src/main/kotlin/blackjack/model/Participants.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package blackjack.model

import blackjack.model.pack.Pack

class Participants(
val participants: Set<Player>,
val players: Players,
val dealer: Dealer,
) {
fun count(): Int {
return participants.size
}

fun dealing() {
participants.forEach { it.deal() }
fun dealing(pack: Pack) {
players.dealing(pack)
dealer.dealing(pack)
}

private fun isGameOver(): Boolean {
return participants.none { Referee.isBlackJack(it) }
return players.isGameOver() || Referee.isGameOver(dealer)
}

fun isContinue(): Boolean {
return !isGameOver()
}

fun count(): Int {
return players.count() + 1
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/blackjack/model/Playable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package blackjack.model

import blackjack.model.pack.Pack

interface Playable {
fun score(): Int
fun dealing(pack: Pack)
fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction
}
6 changes: 6 additions & 0 deletions src/main/kotlin/blackjack/model/PlayableReaction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package blackjack.model

enum class PlayableReaction {
HIT,
STAND
}
28 changes: 20 additions & 8 deletions src/main/kotlin/blackjack/model/Player.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
package blackjack.model

import blackjack.model.pack.ShuffledPack
import blackjack.model.pack.Pack

data class Player(
class Player(
val name: String,
val cards: Cards = Cards.emptyCards(),
) {
fun deal() {
cards.add(ShuffledPack.pickCard())
cards.add(ShuffledPack.pickCard())
) : Playable {
override fun dealing(pack: Pack) {
cards.add(pack.pickCard())
cards.add(pack.pickCard())
}

fun hit() {
cards.add(ShuffledPack.pickCard())
override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction {
if (playingStrategy.isHit()) {
this.hit(pack)
return PlayableReaction.HIT
}
return PlayableReaction.STAND
}

fun hit(pack: Pack) {
cards.add(pack.pickCard())
}

override fun score(): Int {
return this.cards.totalScore()
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/blackjack/model/PlayerResult.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package blackjack.model

enum class PlayerResult {
WIN,
LOSE,
DRAW,
}
33 changes: 33 additions & 0 deletions src/main/kotlin/blackjack/model/Players.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package blackjack.model

import blackjack.model.pack.Pack

class Players(
val values: Set<Player>,
) {
constructor(vararg players: Player) : this(players.toSet())

fun dealing(pack: Pack) {
values.forEach { it.dealing(pack) }
}

fun isGameOver(): Boolean {
return values.any { Referee.isGameOver(it) }
}

fun count(): Int {
return values.size
}

fun scoreBattle(dealerScore: Int): Map<Player, PlayerResult> {
return values.associateWith { Referee.playerResult(it, dealerScore) }
}

fun walkover(): Map<Player, PlayerResult> {
return values.associateWith { PlayerResult.WIN }
}

init {
require(values.map { it.name }.distinct().size == values.size) { "Player λ“€μ˜ 이름은 쀑볡이 ν—ˆμš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€" }
}
moto6 marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 29 additions & 0 deletions src/main/kotlin/blackjack/model/PlayersResults.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package blackjack.model

class PlayersResults(
private val value: Map<Player, PlayerResult>,
) {
fun loseCount(): Int {
return value.values.count { it == PlayerResult.LOSE }
}

fun winningCount(): Int {
return value.values.count { it == PlayerResult.WIN }
}

fun drawingCount(): Int {
return value.values.count { it == PlayerResult.DRAW }
}

fun resultOfPlayer(player: Player): PlayerResult {
return requireNotNull(value[player]) { "ν”Œλ ˆμ΄μ–΄λ₯Ό 찾을 수 μ—†μŒ" }
}

fun playerResult(): List<Pair<String, PlayerResult>> {
return value.keys.map { playerNameAndResult(it) }.toList()
}

private fun playerNameAndResult(it: Player): Pair<String, PlayerResult> {
return it.name to requireNotNull(value[it]) { "ν”Œλ ˆμ΄μ–΄ ${it.name} 을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€" }
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/blackjack/model/PlayingStrategy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package blackjack.model

interface PlayingStrategy {
fun isHit(): Boolean
}
Loading