Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9c01c02
docs(README): ๋ณด๋“œ ์ดˆ๊ธฐํ™” ์š”๊ตฌ์‚ฌํ•ญ ์ •๋ฆฌ
frombunny Mar 24, 2026
59fcc57
feat(Position): ์ขŒํ‘œ ๊ธฐ๋Šฅ ๊ตฌํ˜„
frombunny Mar 24, 2026
327b8af
feat(InitBoard): ์žฅ๊ธฐํŒ ์ƒ์„ฑ ๊ตฌํ˜„
frombunny Mar 24, 2026
1be6794
feat(InitBoard): ์žฅ๊ธฐํŒ ์ดˆ๊ธฐํ™” ๋ฐฉ๋ฒ•๋“ค์— ๋Œ€ํ•œ ๊ตฌํ˜„
JunHyung1206 Mar 25, 2026
02d30c2
fix(InitBoard): ์žฅ๊ธฐํŒ ์›์  ์ขŒํ‘œ ์ˆ˜์ •
frombunny Mar 25, 2026
bcff3b2
refactor(InitBoard): ๊ธฐ๋ฌผ๋“ค์˜ ํด๋ž˜์Šค๋ช… ๋ณ€๊ฒฝ
JunHyung1206 Mar 25, 2026
07bc1de
refactor(InitBoard): Piece ์ธํ„ฐํŽ˜์ด์Šค ๋„์ž…
JunHyung1206 Mar 26, 2026
f37bd67
feat(PieceMove): ์กธ, ๊ถ, ์‚ฌ์— ๋Œ€ํ•œ ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„
JunHyung1206 Mar 26, 2026
2fdf8a0
feat(PieceMove): ๋งˆ์— ๋Œ€ํ•œ ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„
JunHyung1206 Mar 26, 2026
44b13c5
feat(PieceMove): ์ƒ์— ๋Œ€ํ•œ ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„
JunHyung1206 Mar 26, 2026
f7c7a9d
feat(PieceMove): ์ฐจ์— ๋Œ€ํ•œ ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„
JunHyung1206 Mar 26, 2026
e6d3cfb
feat(PieceMove): ํฌ์— ๋Œ€ํ•œ ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„
JunHyung1206 Mar 26, 2026
1a30917
feat(InitBoard): ์ดˆ/ํ•œ ์ง„์˜์— ๋Œ€ํ•œ ๊ธฐ๋ฌผ ์ •๋ณด ์ถ”๊ฐ€
JunHyung1206 Mar 26, 2026
1c49c85
feat(PieceMove): ๊ธฐ๋ฌผ์˜ ์ด๋™ ๊ฒฝ๋กœ์— ๋Œ€ํ•œ ํด๋ž˜์Šค ์ถ”๊ฐ€
frombunny Mar 27, 2026
4a8fb06
refactor(Piece): Piece๋ฅผ record๋กœ ๋ณ€๊ฒฝ
frombunny Mar 27, 2026
5fbb7ac
feat(Piece): ๊ฐ™์€ ํŒ€์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฉ”์„œ๋“œ ์ž‘์„ฑ
frombunny Mar 27, 2026
ea97418
feat(PieceMove): canMove ๊ตฌํ˜„
frombunny Mar 27, 2026
5109408
feat(PieceMove): ๊ธฐ๋ฌผ์ด ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
JunHyung1206 Mar 27, 2026
5fcb757
docs(README): ๊ธฐ๋ฌผ์˜ ์ด๋™ ๊ธฐ๋Šฅ์‚ฌํ•ญ ์ถ”๊ฐ€
JunHyung1206 Mar 28, 2026
4723ed7
style: ์ฝ”๋“œ ํฌ๋งท ์ˆ˜์ •, ํ•„์š”์—†๋Š” ์ฃผ์„ ์ œ๊ฑฐ
JunHyung1206 Mar 28, 2026
e595d08
fix(PieceMove): ๋ฒ„๊ทธ ์ˆ˜์ •
JunHyung1206 Mar 28, 2026
1d2e22c
feat(view): ์žฅ๊ธฐ์— ๋Œ€ํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ทฐ, ์ปจํŠธ๋กค๋Ÿฌ ์ถ”๊ฐ€
JunHyung1206 Mar 28, 2026
83f9817
docs(README): ํ† ๋ก ์—์„œ ์ž‘์„ฑํ•œ ๊ทœ์น™, ๋ฏธ์…˜ ์ค‘ ๊ธฐ๋ก ์ž‘์„ฑ
JunHyung1206 Mar 28, 2026
ec81880
style: ์™€์ผ๋“œ ์นด๋“œ ์ œ๊ฑฐ
JunHyung1206 Mar 28, 2026
9e98fcc
test(PieceMove): ์ƒ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์˜ค๋ฅ˜ ์ˆ˜์ •
JunHyung1206 Mar 29, 2026
5a2beb6
feat(Position): ์ขŒํ‘œ ์ƒ์„ฑ ๋ฐ ๊ฒ€์ฆ ๋กœ์ง ๊ตฌํ˜„
frombunny Mar 30, 2026
563868b
feat(Board): ๋ณด๋“œ ์ดˆ๊ธฐํ™” ๊ตฌํ˜„
frombunny Apr 1, 2026
779dd7e
refactor(Position): ๋งค์ง๋„˜๋ฒ„ ์ƒ์ˆ˜ ์ฒ˜๋ฆฌ
frombunny Apr 1, 2026
0fc9a24
test(Board): ๋ณด๋“œ ์ดˆ๊ธฐํ™” ํ…Œ์ŠคํŠธ ๋ฆฌํŒฉํ† ๋ง
frombunny Apr 1, 2026
1439b54
feat(Board): ๋ณด๋“œ ๊ตฌํ˜„
frombunny Apr 1, 2026
1705213
feat(Piece): Piece์— ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ ๋„์ž…
frombunny Apr 1, 2026
11e40a6
feat(Position): ์ขŒํ‘œ ์ฐจ์ด ๊ณ„์‚ฐ ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 1, 2026
8f6a7db
feat(Direction): ๋ฐฉํ–ฅ ํŒ์ • ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 2, 2026
b36fa6e
feat(MoveStrategy): ์ฐจ ์ด๋™ ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 2, 2026
4368531
refactor: ํŒจํ‚ค์ง€ ์ด๋™
frombunny Apr 2, 2026
0637768
refactor: ์ฝ”๋“œ ํฌ๋งทํŒ… ์ˆ˜์ •
frombunny Apr 2, 2026
d9c59fc
feat(MoveStrategy): ๊ถ/์‚ฌ ์ด๋™ ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 2, 2026
4087a05
feat(MoveStrategy): ํฌ ์ด๋™ ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 2, 2026
6d434a0
feat(MoveStrategy): ์กธ/๋ณ‘ ์ด๋™ ๋กœ์ง ๊ตฌํ˜„
frombunny Apr 2, 2026
780e132
refactor: ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์„ ์–ธ ์ œ๊ฑฐ
frombunny Apr 2, 2026
877247c
feat(MoveStrategy): ๋งˆ ์ด๋™ ์ „๋žต ๊ตฌํ˜„
frombunny Apr 2, 2026
a311337
feat(MoveStrategy): ๋งˆ ์ด๋™ ์ „๋žต ๊ตฌํ˜„
frombunny Apr 2, 2026
99610dc
feat(MoveStrategy): ์ƒ ์ด๋™ ์ „๋žต ๊ตฌํ˜„
frombunny Apr 2, 2026
aae6b44
feat(MoveStrategy): ์ƒ ์ด๋™ ์ „๋žต ๊ตฌํ˜„
frombunny Apr 2, 2026
561cda7
test(PathInfo): PathInfo ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 2, 2026
3549d35
test(Position): Position ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 2, 2026
74fc93a
test(Piece): Piece ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 2, 2026
43e9627
test(Board): Board ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 2, 2026
906399c
test(PathGenerator): PathGenerator ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 2, 2026
a17bc6b
fix(Board): ์žฅ๊ธฐํŒ ํ…Œ์ŠคํŠธ ์˜ค๋ฅ˜ ์ˆ˜์ •
frombunny Apr 2, 2026
2a4b1e5
feat(view): ์ž…์ถœ๋ ฅ ๊ตฌํ˜„
frombunny Apr 2, 2026
8a3671f
feat(Controller): ์ปจํŠธ๋กค๋Ÿฌ ๊ตฌํ˜„
frombunny Apr 2, 2026
700e8ea
feat(Game): ์ŠนํŒจ ํŒ์ • ๊ตฌํ˜„
frombunny Apr 2, 2026
4a6f08f
refactor: ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์„ ์–ธ ์ œ๊ฑฐ
frombunny Apr 2, 2026
809c2ae
view: ์ƒ์ฐจ๋ฆผ ์„ ํƒ ๊ตฌํ˜„
frombunny Apr 2, 2026
033710a
test(MoveStrategy): ๋งˆ,์ƒ ๊ธฐ๋ฌผ ์ด๋™ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ถ”๊ฐ€
frombunny Apr 3, 2026
9701db2
fix(MoveStrategy): ํฌ ์ด๋™ ์‹œ ๊ฒฝ๋กœ์— ๊ธฐ๋ฌผ์ด ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์œผ๋ฉด ์ด๋™ํ•  ์ˆ˜ ์—†๋„๋ก ์ˆ˜์ •
frombunny Apr 3, 2026
4e68aac
test(MoveStrategy): ํฌ ์ด๋™ ๊ฒฝ๋กœ์— ๊ธฐ๋ฌผ์ด ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์„ ๊ฒฝ์šฐ์˜ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
frombunny Apr 3, 2026
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
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# java-janggi

์žฅ๊ธฐ ๋ฏธ์…˜ ์ €์žฅ์†Œ
## 1.1 ์žฅ๊ธฐํŒ ์ดˆ๊ธฐํ™”

- [x] ์žฅ๊ธฐํŒ์€ 9ํ–‰ * 10์—ด ํฌ๊ธฐ์ด๋‹ค. (x์ถ•์€ ๊ฐ€๋กœ, y์ถ•์€ ์„ธ๋กœ์ด๋‹ค.)
- [x] x์ขŒํ‘œ๋Š” 0 ์ด์ƒ 8 ์ดํ•˜์˜ ๋ฒ”์œ„๋ฅผ ๊ฐ€์ง„๋‹ค. (์ด 9์นธ)
- [x] y์ขŒํ‘œ๋Š” 0 ์ด์ƒ 9 ์ดํ•˜์˜ ๋ฒ”์œ„๋ฅผ ๊ฐ€์ง„๋‹ค. (์ด 10์นธ)
- [x] ์žฅ๊ธฐํŒ์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ์ขŒํ‘œ์— ์ ‘๊ทผํ•  ๊ฒฝ์šฐ, IllegalArgumentException์„ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.
- [x] ์žฅ๊ธฐํŒ์˜ ์ขŒ์ธก ํ•˜๋‹จ์„ (0, 0)์œผ๋กœ ์ •์˜ํ•œ๋‹ค.

- [x] ์žฅ๊ธฐํŒ์„ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.
- [x] ์ƒ์ฐจ๋ฆผ์— ๋งž๋„๋ก ๊ธฐ๋ฌผ์„ ๋ฐฐ์น˜ํ•œ๋‹ค.
- [x] ์™ผ์ƒ์ฐจ๋ฆผ : ์ƒ๋งˆ์ƒ๋งˆ
- [x] ์˜ค๋ฅธ์ƒ์ฐจ๋ฆผ : ๋งˆ์ƒ๋งˆ์ƒ
- [x] ๋ฐ”๊นฅ์ƒ์ฐจ๋ฆผ : ๋งˆ์ƒ์ƒ๋งˆ
- [x] ์•ˆ์ƒ์ฐจ๋ฆผ : ์ƒ๋งˆ๋งˆ์ƒ

## 1.2 ๊ธฐ๋ฌผ ์ด๋™

- [x] `๊ถ`์€ ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ, ์•ž์ชฝ, ๋’ค์ชฝ์œผ๋กœ 1์นธ์”ฉ ์›€์ง์ผ ์ˆ˜ ์žˆ๋‹ค.
- [x] ๊ฐ€๋กœ๋ง‰๋Š” ๊ธฐ๋ฌผ์ด ์ ์˜ ๊ฒƒ์ผ ๊ฒฝ์šฐ ์žก์•„๋‚ด๊ณ  ๊ทธ ๊ธฐ๋ฌผ์ด ์žˆ๋˜ ๊ณณ๊นŒ์ง€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [x] `์‚ฌ`๋Š” ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ, ์•ž์ชฝ, ๋’ค์ชฝ์œผ๋กœ 1์นธ์”ฉ ์›€์ง์ผ ์ˆ˜ ์žˆ๋‹ค.
- [x] ๊ฐ€๋กœ๋ง‰๋Š” ๊ธฐ๋ฌผ์ด ์ ์˜ ๊ฒƒ์ผ ๊ฒฝ์šฐ ์žก์•„๋‚ด๊ณ  ๊ทธ ๊ธฐ๋ฌผ์ด ์žˆ๋˜ ๊ณณ๊นŒ์ง€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [x] `์ฐจ`๋Š” ์žฅ๊ธฐํŒ ์œ„์˜ ๊ณง์€ ์„ ์„ ๋”ฐ๋ผ ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ์›ํ•˜๋Š” ๋งŒํผ ์ด๋™ ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [x] ๋‹จ, ๋‹ค๋ฅธ ๊ธฐ๋ฌผ์„ ๋›ฐ์–ด๋„˜์„ ์ˆ˜๋Š” ์—†๋‹ค.
- [x] ๊ฐ€๋กœ๋ง‰๋Š” ๊ธฐ๋ฌผ์ด ์žˆ๋Š” ์ง€์ ์˜ ๋ฐ”๋กœ ์•ž๊นŒ์ง€, ํ˜น์€ ๊ฐ€๋กœ๋ง‰๋Š” ๊ธฐ๋ฌผ์ด ์ ์˜ ๊ฒƒ์ผ ๊ฒฝ์šฐ ์žก์•„๋‚ด๊ณ  ๊ทธ ๊ธฐ๋ฌผ์ด ์žˆ๋˜ ๊ณณ๊นŒ์ง€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [x] `ํฌ`๋Š” ์žฅ๊ธฐํŒ ์œ„์˜ ๊ณง์€ ์„ ์„ ๋”ฐ๋ผ ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ์›ํ•˜๋Š” ๋งŒํผ ์ด๋™ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ๋ฐ˜๋“œ์‹œ ๊ธฐ๋ฌผ์„ ํ•œ ๊ฐœ ๋›ฐ์–ด๋„˜์–ด์•ผ๋งŒ ๊ทธ ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
- [x] ๋‹จ, ๊ฒฝ๋กœ์— ๋‘ ๊ฐœ ์ด์ƒ์˜ ๊ธฐ๋ฌผ์ด ์กด์žฌํ•˜๋ฉด ์ด๋™ํ•  ์ˆ˜ ์—†๋‹ค.
- [x] ๋‹จ, ํฌ๋ผ๋ฆฌ๋Š” ์„œ๋กœ ๋›ฐ์–ด๋„˜์„ ์ˆ˜ ์—†๋‹ค.
- [x] ๋‹จ, ํฌ๋ผ๋ฆฌ๋Š” ์„œ๋กœ ์žก์„ ์ˆ˜ ์—†๋‹ค.
- [x] `๋งˆ`๋Š” ์ˆ˜์ง ๋˜๋Š” ์ˆ˜ํ‰ ๋ฐฉํ–ฅ์œผ๋กœ ํ•œ ์นธ ๊ฐ”๋‹ค๊ฐ€ 45๋„๋ฅผ ๊บพ์–ด์„œ ๋Œ€๊ฐ์„ ์œผ๋กœ ํ•œ ์นธ ๋” ์ด๋™ํ•œ๋‹ค.
- [x] ๊ฒฝ๋กœ์— ๋‹ค๋ฅธ ๊ธฐ๋ฌผ์ด ์žˆ์„ ๊ฒฝ์šฐ, ์ด๋™ํ•  ์ˆ˜ ์—†๋‹ค.
- [x] `์ƒ`์€ ์ˆ˜์ง ๋˜๋Š” ์ˆ˜ํ‰ ๋ฐฉํ–ฅ์œผ๋กœ ํ•œ ์นธ ๊ฐ”๋‹ค๊ฐ€ 45๋„๋ฅผ ๊บพ์–ด์„œ ๋Œ€๊ฐ์„ ์œผ๋กœ ๋‘ ์นธ ๋” ์ด๋™ํ•œ๋‹ค.
- [x] ๊ฒฝ๋กœ์— ๋‹ค๋ฅธ ๊ธฐ๋ฌผ์ด ์žˆ์„ ๊ฒฝ์šฐ, ์ด๋™ํ•  ์ˆ˜ ์—†๋‹ค.
- [x] `์กธ, ๋ณ‘`์€ ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ, ์•ž์ชฝ์œผ๋กœ 1์นธ์”ฉ ์›€์ง์ผ ์ˆ˜ ์žˆ์œผ๋‚˜, ํ›„ํ‡ดํ•  ์ˆ˜ ์—†๋‹ค.
19 changes: 19 additions & 0 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import controller.GameController;
import domain.board.Board;
import domain.board.BoardInitializer;
import view.InputView;

public class Application {
public static void main(String[] args) {
Board board = new Board(BoardInitializer.init(InputView.readBoardSetting()));
GameController gameController = new GameController();

while (!board.isGameOver()) {
gameController.printBoard(board);
gameController.move(board);
}

gameController.printBoard(board);
gameController.printWinner(board);
}
}
45 changes: 45 additions & 0 deletions src/main/java/controller/GameController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

package controller;

import domain.board.Board;
import domain.board.Position;
import view.InputView;
import view.OutputView;

public class GameController {
public void move(Board board) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

board๋ฅผ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~

while (true) {
try {
Position departure = parsePosition(InputView.readDeparturePosition());
Position destination = parsePosition(InputView.readDestinationPosition());
board.move(departure, destination);
return;
} catch (IllegalArgumentException exception) {
OutputView.printError(exception.getMessage());
}
}
}

public void printBoard(Board board) {
OutputView.printBoard(board);
}

public void printWinner(Board board) {
OutputView.printWinner(board.winner());
}

private Position parsePosition(String value) {
String[] tokens = value.split(",");
if (tokens.length != 2) {
throw new IllegalArgumentException("์ขŒํ‘œ๋Š” x,y ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}

try {
int column = Integer.parseInt(tokens[0].trim());
int row = Integer.parseInt(tokens[1].trim());
return new Position(column, row);
} catch (NumberFormatException exception) {
throw new IllegalArgumentException("์ขŒํ‘œ๋Š” ์ˆซ์ž๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}
}
}
101 changes: 101 additions & 0 deletions src/main/java/domain/board/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package domain.board;

import domain.path.PathInfo;
import domain.piece.Camp;
import domain.piece.Piece;
import domain.piece.PieceType;

import java.util.List;
import java.util.Map;

public class Board {
private final Map<Position, Piece> pieces;
private boolean gameOver;
private Camp winner;

public Board(Map<Position, Piece> pieces) {
this.pieces = pieces;
}

public boolean isExistPieceAt(Position position) {
return pieces.containsKey(position);
}

public Piece pieceAt(Position position) {
if (!isExistPieceAt(position)) {
throw new IllegalArgumentException("ํ•ด๋‹น ์œ„์น˜์— ๊ธฐ๋ฌผ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
}

return pieces.get(position);
}

public boolean isGameOver() {
return gameOver;
}

public Camp winner() {
if (!gameOver) {
throw new IllegalStateException("์•„์ง ๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}

return winner;
}

public void move(Position departure, Position destination) {
validateGameStatus();
validateDepartureAndDestinationPosition(departure, destination);

Piece departurePiece = pieceAt(departure);
List<PathInfo> path = getPath(departure, destination, departurePiece);

departurePiece.validateBlockingPiece(path, destination);

if (isExistPieceAt(destination)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

false์ธ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๊ฐ€ ์—†๋Š”๊ฑธ๋ณด๋‹ˆ ๋นˆ ๊ณต๊ฐ„์œผ๋กœ ๊ธฐ๋ฌผ์ด ์ด๋™ํ•˜๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๊ฐ€ ์—†๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

handleCapture(pieceAt(departure), destination);
}
Comment on lines +48 to +55
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

executeMove ๋ฉ”์„œ๋“œ ๋‚ด๋ถ€์— ๋„ฃ์–ด๋„ ๋˜๋Š” ๋กœ์ง ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ํ™•์‹คํžˆ executeMove ๋ฉ”์„œ๋“œ๋กœ ์ด๋™์‹œํ‚ค๋‹ˆ ํ›จ์”ฌ ๊น”๋”ํ•ด์ง„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..!


executeMove(departure, destination, departurePiece);
}

private void validateGameStatus() {
if (gameOver) {
throw new IllegalStateException("์ด๋ฏธ ์ข…๋ฃŒ๋œ ๊ฒŒ์ž„์ž…๋‹ˆ๋‹ค.");
}
}

private void handleCapture(Piece departurePiece, Position destination) {
Piece destinationPiece = pieceAt(destination);
validateCapture(departurePiece, destinationPiece);
updateGameOver(departurePiece, destinationPiece);
}

private void validateDepartureAndDestinationPosition(Position departure, Position destination) {
if (departure.equals(destination)) {
throw new IllegalArgumentException("์ถœ๋ฐœ ์œ„์น˜์™€ ๋„์ฐฉ ์œ„์น˜๊ฐ€ ๊ฐ™์Šต๋‹ˆ๋‹ค.");
}
}

private void validateCapture(Piece departurePiece, Piece destinationPiece) {
if (departurePiece.isSameCamp(destinationPiece)) {
throw new IllegalArgumentException("๊ฐ™์€ ์ง„์˜์˜ ๊ธฐ๋ฌผ์€ ์žก์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}

private List<PathInfo> getPath(Position departure, Position destination, Piece piece) {
return piece.getPath(departure, destination).stream()
.map(pos -> new PathInfo(pos, pieces.get(pos)))
.toList();
}

private void updateGameOver(Piece departurePiece, Piece destinationPiece) {
if (destinationPiece.isSameType(PieceType.GENERAL)) {
gameOver = true;
winner = departurePiece.getCamp();
}
}

private void executeMove(Position from, Position to, Piece piece) {
pieces.remove(from);
pieces.put(to, piece);
}
}
99 changes: 99 additions & 0 deletions src/main/java/domain/board/BoardInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package domain.board;

import domain.piece.Camp;
import domain.piece.Piece;
import domain.piece.PieceType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BoardInitializer {
private static final int CHO_BASE_ROW = 0;
private static final int CHO_GENERAL_ROW = CHO_BASE_ROW + 1;
private static final int CHO_CANNON_ROW = CHO_BASE_ROW + 2;
private static final int CHO_SOLDIER_ROW = CHO_BASE_ROW + 3;

private static final int HAN_BASE_ROW = 9;
private static final int HAN_GENERAL_ROW = HAN_BASE_ROW - 1;
private static final int HAN_CANNON_ROW = HAN_BASE_ROW - 2;
private static final int HAN_SOLDIER_ROW = HAN_BASE_ROW - 3;

private static final int GENERAL_COLUMN = 4;
private static final List<Integer> GUARD_COLUMNS = List.of(3, 5);
private static final List<Integer> CHARIOT_COLUMNS = List.of(0, 8);
private static final List<Integer> CANNON_COLUMNS = List.of(1, 7);
private static final List<Integer> HORSE_AND_ELEPHANT_COLUMNS = List.of(1, 2, 6, 7);
private static final List<Integer> SOLDIER_COLUMNS = List.of(0, 2, 4, 6, 8);

public static Map<Position, Piece> init(BoardSetting boardSetting) {
Map<Position, Piece> pieces = new HashMap<>();

pieces.putAll(createGeneral());
pieces.putAll(createGuard());
pieces.putAll(createChariot());
pieces.putAll(createCannon());
pieces.putAll(createHorseAndElephant(boardSetting));
pieces.putAll(createSoldier());

return pieces;
}

private static Map<Position, Piece> createGeneral() {
Map<Position, Piece> pieces = new HashMap<>();
pieces.put(new Position(GENERAL_COLUMN, CHO_GENERAL_ROW), Piece.of(Camp.CHO, PieceType.GENERAL));
pieces.put(new Position(GENERAL_COLUMN, HAN_GENERAL_ROW), Piece.of(Camp.HAN, PieceType.GENERAL));

return pieces;
}

private static Map<Position, Piece> createGuard() {
Map<Position, Piece> pieces = new HashMap<>();
for (Integer column : GUARD_COLUMNS) {
pieces.put(new Position(column, CHO_BASE_ROW), Piece.of(Camp.CHO, PieceType.GUARD));
pieces.put(new Position(column, HAN_BASE_ROW), Piece.of(Camp.HAN, PieceType.GUARD));
}

return pieces;
}

private static Map<Position, Piece> createChariot() {
Map<Position, Piece> pieces = new HashMap<>();
for (Integer column : CHARIOT_COLUMNS) {
pieces.put(new Position(column, CHO_BASE_ROW), Piece.of(Camp.CHO, PieceType.CHARIOT));
pieces.put(new Position(column, HAN_BASE_ROW), Piece.of(Camp.HAN, PieceType.CHARIOT));
}

return pieces;
}

private static Map<Position, Piece> createCannon() {
Map<Position, Piece> pieces = new HashMap<>();
for (Integer column : CANNON_COLUMNS) {
pieces.put(new Position(column, CHO_CANNON_ROW), Piece.of(Camp.CHO, PieceType.CANNON));
pieces.put(new Position(column, HAN_CANNON_ROW), Piece.of(Camp.HAN, PieceType.CANNON));
}

return pieces;
}

private static Map<Position, Piece> createHorseAndElephant(BoardSetting boardSetting) {
Map<Position, Piece> pieces = new HashMap<>();
for (int i = 0; i < boardSetting.piecesArrangement().size(); i++) {
pieces.put(new Position(HORSE_AND_ELEPHANT_COLUMNS.get(i), CHO_BASE_ROW), Piece.of(Camp.CHO, boardSetting.piecesArrangement().get(i)));
pieces.put(new Position(HORSE_AND_ELEPHANT_COLUMNS.get(i), HAN_BASE_ROW), Piece.of(Camp.HAN, boardSetting.piecesArrangement().get(i)));
}

return pieces;
}

private static Map<Position, Piece> createSoldier() {
Map<Position, Piece> pieces = new HashMap<>();
for (Integer column : SOLDIER_COLUMNS) {
pieces.put(new Position(column, CHO_SOLDIER_ROW), Piece.of(Camp.CHO, PieceType.SOLDIER));
pieces.put(new Position(column, HAN_SOLDIER_ROW), Piece.of(Camp.HAN, PieceType.SOLDIER));
}

return pieces;
}
}
35 changes: 35 additions & 0 deletions src/main/java/domain/board/BoardSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package domain.board;

import domain.piece.PieceType;

import java.util.List;

import static domain.piece.PieceType.ELEPHANT;
import static domain.piece.PieceType.HORSE;

public enum BoardSetting {
LEFT_ELEPHANT_SET_UP(List.of(ELEPHANT, HORSE, ELEPHANT, HORSE)),
RIGHT_ELEPHANT_SET_UP(List.of(HORSE, ELEPHANT, HORSE, ELEPHANT)),
OUTER_ELEPHANT_SET_UP(List.of(HORSE, ELEPHANT, ELEPHANT, HORSE)),
INNER_ELEPHANT_SET_UP(List.of(ELEPHANT, HORSE, HORSE, ELEPHANT));

private final List<PieceType> piecesArrangement;

BoardSetting(List<PieceType> pieceTypes) {
this.piecesArrangement = pieceTypes;
}

public List<PieceType> piecesArrangement() {
return piecesArrangement;
}

public static BoardSetting from(String value) {
return switch (value.trim()) {
case "1", "์™ผ์ƒ์ฐจ๋ฆผ" -> LEFT_ELEPHANT_SET_UP;
case "2", "์˜ค๋ฅธ์ƒ์ฐจ๋ฆผ" -> RIGHT_ELEPHANT_SET_UP;
case "3", "๋ฐ”๊นฅ์ƒ์ฐจ๋ฆผ" -> OUTER_ELEPHANT_SET_UP;
case "4", "์•ˆ์ƒ์ฐจ๋ฆผ" -> INNER_ELEPHANT_SET_UP;
default -> throw new IllegalArgumentException("์ƒ์ฐจ๋ฆผ์€ 1~4 ๋˜๋Š” ์ด๋ฆ„์œผ๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
};
}
}
38 changes: 38 additions & 0 deletions src/main/java/domain/board/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package domain.board;

public record Position(int column, int row) {
private static final int MIN_POSITION = 0;
private static final int MAX_COLUMN = 8;
private static final int MAX_ROW = 9;

public Position {
validateColumn(column);
validateRow(row);
}

public Position move(int deltaX, int deltaY) {
return new Position(this.column + deltaX, this.row + deltaY);
}

public int calculateDeltaX(Position destination) {
return destination.column - this.column;
}

public int calculateDeltaY(Position destination) {
return destination.row - this.row;
}

private void validateColumn(int column) {
if (column < MIN_POSITION || column > MAX_COLUMN) {
throw new IllegalArgumentException(
String.format("[ERROR] x์ขŒํ‘œ๋Š” %d์—์„œ %d ์‚ฌ์ด์ž…๋‹ˆ๋‹ค.", MIN_POSITION, MAX_COLUMN));
}
}

private void validateRow(int row) {
if (row < MIN_POSITION || row > MAX_ROW) {
throw new IllegalArgumentException(
String.format("[ERROR] y์ขŒํ‘œ๋Š” %d์—์„œ %d ์‚ฌ์ด์ž…๋‹ˆ๋‹ค.", MIN_POSITION, MAX_ROW));
}
}
}
Loading