Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cb93bfc
docs: readme tset
picetea44 Mar 25, 2026
0f8fb4d
feat: Position ๋„๋ฉ”์ธ ๊ตฌํ˜„
picetea44 Mar 25, 2026
ec1afcb
feat: ๊ธฐ๋ฌผ ๊ด€๋ จ ๋„๋ฉ”์ธ ๊ตฌํ˜„
gahyeonnni Mar 25, 2026
81434bd
feat: ์ดˆ๊ธฐ ๋ณด๋“œ ๊ตฌ์„ฑ ๋ฐ ์ถ”์ƒํ™” ๋ณ€๊ฒฝ
picetea44 Mar 25, 2026
4a7f437
feat: ์—ด๊ณผ ํ–‰ ๋น„๊ต ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
gahyeonnni Mar 26, 2026
ee11a83
feat: ์‹ค์ œ ์ด๋™ ๊ธฐ๋ฌผ ๋„๋ฉ”์ธ ๊ตฌํ˜„
gahyeonnni Mar 26, 2026
b91473b
feat: ์‹ค์ œ ์ด๋™ ๊ธฐ๋ฌผ ๋„๋ฉ”์ธ ๊ตฌํ˜„
gahyeonnni Mar 26, 2026
5ce6271
feat: ๋งˆ,ํฌ,์ฐจ ์œ ํšจ ์ด๋™ ๋ฒ”์œ„ ๊ตฌํ˜„
picetea44 Mar 26, 2026
9198a53
feat: ์ƒ, ๊ถ, ์กธ, ์‚ฌ ์œ ํšจ ์ด๋™ ๋ฒ”์œ„ ๊ตฌํ˜„
gahyeonnni Mar 26, 2026
7e8456c
test: ๊ธฐ๋ฌผ๋ณ„ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„
picetea44 Mar 26, 2026
9179f23
feat: ์ดˆ๊ธฐ formation ์ž…๋ ฅ ๊ธฐ๋Šฅ ๊ตฌํ˜„
gahyeonnni Mar 26, 2026
68304cd
feat: BoardFactory ๊ธฐ๋Šฅ ์ถ”๊ฐ€
picetea44 Mar 26, 2026
0d17919
feat: ๋ฐฐ์น˜ ์ „๋žต ๊ตฌํ˜„
gahyeonnni Mar 26, 2026
ccfa0e4
feat: ์ฐจ๋ฆผ ์ž…๋ ฅ ํ›„ ๋ณด๋“œ ์ถœ๋ ฅ ๊ตฌํ˜„
picetea44 Mar 26, 2026
95ed613
refactor: ๊ณต๋ฐฑ ์ˆ˜์ •
picetea44 Mar 26, 2026
212f889
feat: Cha ์ด๋™ ๊ฒฝ๋กœ ๊ตฌํ˜„1
picetea44 Mar 27, 2026
b586fd8
feat: ํฌ,์ฐจ,๊ถ,์‚ฌ ์ด๋™ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
gahyeonnni Mar 27, 2026
f1ee429
test: ๊ถ,์‚ฌ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ž‘์„ฑ
picetea44 Mar 27, 2026
bf366d0
feat: ๋งˆ ๊ธฐ๋ฌผ ์ด๋™ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜ ๋กœ์ง ๊ตฌํ˜„
picetea44 Mar 27, 2026
6db9326
feat: ์ƒ ๊ธฐ๋ฌผ ์ด๋™ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
gahyeonnni Mar 27, 2026
fbb1143
feat: ๋ณ‘ ๊ธฐ๋ฌผ ์ด๋™ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
gahyeonnni Mar 27, 2026
99c9e0e
feat: ํ๋ฆ„ ์ œ์–ด ํ…Œ์ŠคํŠธ
gahyeonnni Mar 27, 2026
55ee04d
feat: ์ปจํŠธ๋กค๋Ÿฌ ์ˆ˜์ •
picetea44 Mar 27, 2026
b387b44
feat: ํ๋ฆ„ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„
gahyeonnni Mar 27, 2026
06de619
refactor: ๊ธฐ๋ฌผ ์œ„์น˜ ์ด๋™ ์ž…๋ ฅ์— ๋Œ€ํ•œ ํŒŒ์‹ฑ ์ฑ…์ž„ ๋ถ„๋ฆฌ (Position)
picetea44 Mar 28, 2026
e8388ee
refactor: Turn ๊ฐœ๋… ๋„์ž…
picetea44 Mar 28, 2026
804af3d
refactor: Board ๋‚ด๋ถ€ ๋กœ์ง ์บก์Аํ™” ์ง„ํ–‰
picetea44 Mar 28, 2026
08f237b
refactor: ํŒ€ ํŒ๋ณ„ ๋กœ์ง ๊ฐœ์„  ๋ฐ ์ด๋™ ๊ทœ์น™ ๊ณผ์ • ์ˆ˜์ •
picetea44 Mar 28, 2026
3d7803c
refactor: ๋„ค์ด๋ฐ ์ˆ˜์ •
gahyeonnni Mar 28, 2026
91ee3f1
refactor: ๋ณด๋“œ ์ถœ๋ ฅ์‹œ ์—ด๊ณผ ํ–‰ ์ˆซ์ž ์ถœ๋ ฅ
gahyeonnni Mar 28, 2026
6f4a476
refactor: ์ถœ๋ ฅ ๋ฉ”์„ธ์ง€ ์ˆ˜์ •
gahyeonnni Mar 28, 2026
9dec8bf
refactor: ๋„๋ฉ”์ธ ํŒจํ‚ค์ง€ ์žฌ๋ถ„๋ฅ˜
gahyeonnni Mar 28, 2026
45de3b0
refactor: ๋ฉ”์„œ๋“œ ๋กœ์ง ํ๋ฆ„ ์ˆ˜์ •
gahyeonnni Mar 28, 2026
9dbbbdd
refactor: ์žฌ์‹œ๋„ ํฌํ•จ ๊ฒŒ์ž„ ํ๋ฆ„ ์ˆ˜์ •
gahyeonnni Mar 29, 2026
16ad9c7
feat: ํฌ ์ด๋™ ๋กœ์ง ๊ตฌํ˜„
gahyeonnni Mar 29, 2026
7bc74d0
refactor: AbstractBoardFactory if ๋ถ„๊ธฐ ์ œ๊ฑฐ
gahyeonnni Mar 29, 2026
5343fff
test: ๊ธฐ๋ฌผ ๊ด€๋ จ ํ…Œ์ŠคํŠธ ์ˆ˜์ •
gahyeonnni Mar 29, 2026
036506b
test: Board ํด๋ž˜์Šค ๊ด€๋ จ Test ์ž‘์„ฑ
gahyeonnni Mar 29, 2026
78593ee
test: Board, Turn, Position ๋ˆ„๋ฝ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ
picetea44 Mar 29, 2026
32db79b
docs: ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ ์ •๋ฆฌ
gahyeonnni Mar 29, 2026
7ef7e9d
refactor: EmptyPiece ์‹ฑ๊ธ€ํ†ค ํ™”
picetea44 Mar 31, 2026
ccae384
refactor: Row, Column ๋งค์ง ๋„˜๋ฒ„ ์ œ๊ฑฐ
picetea44 Mar 31, 2026
494396b
refactor: ์˜คํƒˆ์ž, ์—๋Ÿฌ์ถœ๋ ฅ ์ฑ…์ž„ ์•„์›ƒํ’‹ ๋ทฐ์— ์œ„์ž„
picetea44 Mar 31, 2026
168cc30
refactor: dx, dy ์ถ•์•ฝ์–ด ์‚ญ์ œ ๋ฐ static ์ถ”๊ฐ€
picetea44 Mar 31, 2026
b526872
refactor: ์ปจํŠธ๋กค๋Ÿฌ ์ฑ…์ž„ ๋ถ„๋ฆฌ ๋ฐ JanggiGame ํด๋ž˜์Šค ์ถ”๊ฐ€
picetea44 Mar 31, 2026
726d94c
refactor: Board null ๋ฐ˜ํ™˜ ๊ฐ€๋Šฅ์„ฑ ์ œ๊ฑฐ ๋ฐ ์ถ•์•ฝ์–ด ์ œ๊ฑฐ
picetea44 Apr 1, 2026
28ebeff
refactor: Board์— ๋ถˆํ•„์š”ํ•œ ๋‹ค์šด์บ์ŠคํŒ… ์ œ๊ฑฐ, searchRoute() Piece๋กœ ์Šน๊ฒฉ, isCannon() ๋””โ€ฆ
picetea44 Apr 1, 2026
745799b
refactor: AbstractBoardFactory ์ž…๋ ฅ ์ฑ…์ž„ ์ œ๊ฑฐ
picetea44 Apr 2, 2026
8bcf443
refactor: ActivePiece isSameTeam ์ œ๊ฑฐ ๋ฐ ์บ์ŠคํŒ… ์ œ๊ฑฐ
picetea44 Apr 2, 2026
9c423a6
refactor: PositionTest ๊ตฌ์ฒด์ ์ธ ์˜ˆ์™ธ ๋ฉ”์„ธ์ง€ ํ™•์ธ ์ ์šฉ
picetea44 Apr 2, 2026
b1455ff
refactor: ์ „์ฒด ํŒŒ์ผ ์ถ•์•ฝ์–ด ์ œ๊ฑฐ
picetea44 Apr 2, 2026
e73c692
refactor: searchRoute ์ด๋™ ํŒ๋ณ„ ์ฑ…์ž„ ๊ธฐ๋ฌผ์— ์œ„์ž„
picetea44 Apr 2, 2026
d151d75
refactor: searchRoute -> calculateRoute๋กœ ๋ฉ”์„œ๋“œ ๋ช… ๋ณ€๊ฒฝ
picetea44 Apr 2, 2026
92b4ee9
refactor: isCannon ๋ฉ”์„œ๋“œ ์ œ๊ฑฐ
picetea44 Apr 2, 2026
2466494
test: ๋ฌด์˜๋ฏธํ•œ ํ…Œ์ŠคํŠธ ๊ฒ€์ฆ ๊ฐœ์„ 
picetea44 Apr 2, 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
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# java-janggi
## ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ ์ฒดํฌ๋ฆฌ์ŠคํŠธ

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

- [x] ๋‘ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๊ฐ๊ฐ ์ง„ํ˜•์„ ์„ ํƒํ•œ๋‹ค
- [x] ์ง„ํ˜• ์„ ํƒ์ง€: ์™ผ์ƒ๋งˆ(๊ท€๋งˆ), ์˜ค๋ฅธ์ƒ๋งˆ(๊ท€๋งˆ), ์›์•™๋งˆ, ์–‘๊ท€๋งˆ
- [x] ์„ ํƒํ•œ ์ง„ํ˜•์— ๋”ฐ๋ผ ๋งˆ(้ฆฌ)์™€ ์ƒ(่ฑก)์˜ ์œ„์น˜๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค

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

- [x] ์ฐจ(่ปŠ): ์ง์„ (๊ฐ€๋กœ/์„ธ๋กœ) ์ด๋™, ์ด๋™ ๊ฒฝ๋กœ์— ๊ธฐ๋ฌผ์ด ์—†์–ด์•ผ ํ•œ๋‹ค
- [x] ๋งˆ(้ฆฌ): ์ง์„  1์นธ + ๋Œ€๊ฐ์„  1์นธ ์ด๋™, ์ฒซ ๋ฒˆ์งธ ์นธ์— ๊ธฐ๋ฌผ์ด ์—†์–ด์•ผ ํ•œ๋‹ค
- [x] ์ƒ(่ฑก): ์ง์„  1์นธ + ๋Œ€๊ฐ์„  2์นธ ์ด๋™, ์ด๋™ ๊ฒฝ๋กœ 2์นธ์— ๊ธฐ๋ฌผ์ด ์—†์–ด์•ผ ํ•œ๋‹ค
- [x] ๊ถ(ๅฐ‡/ๅธฅ): ์ƒํ•˜์ขŒ์šฐ 1์นธ ์ด๋™
- [x] ์‚ฌ(ๅฃซ): ์ƒํ•˜์ขŒ์šฐ 1์นธ ์ด๋™
- [x] ํฌ(ๅŒ…): ์ง์„  ์ด๋™, ๋ฐ˜๋“œ์‹œ ๊ธฐ๋ฌผ 1๊ฐœ๋ฅผ ๋›ฐ์–ด๋„˜์–ด์•ผ ํ•˜๋ฉฐ ํฌ๋ฅผ ๋„˜๊ฑฐ๋‚˜ ํฌ๋ฅผ ์žก์„ ์ˆ˜ ์—†๋‹ค
- [x] ๋ณ‘/์กธ(ๅ…ต/ๅ’): ์•ž ๋˜๋Š” ์ขŒ์šฐ 1์นธ ์ด๋™

### ์ด๋™ ์œ ํšจ์„ฑ ๊ฒ€์ฆ

- [x] ์ด๋™ ๋ถˆ๊ฐ€๋Šฅํ•œ ์œ„์น˜๋กœ ์ด๋™ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
- [x] ์ด๋™ ๊ฒฝ๋กœ ์ค‘๊ฐ„์— ๊ธฐ๋ฌผ์ด ์žˆ์„ ๊ฒฝ์šฐ ์ด๋™ ๋ถˆ๊ฐ€ (ํฌ ์ œ์™ธ)
- [x] ์•„๊ตฐ ๊ธฐ๋ฌผ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ด๋™ ๋ถˆ๊ฐ€
- [x] ์ ๊ตฐ ๊ธฐ๋ฌผ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ด๋™ ์‹œ ํ•ด๋‹น ๊ธฐ๋ฌผ ์žก๊ธฐ
- [x] ํฌ์˜ ๊ฒฝ์šฐ ์ด๋™ ๊ฒฝ๋กœ์— ์ •ํ™•ํžˆ 1๊ฐœ์˜ ๊ธฐ๋ฌผ์ด ์žˆ์–ด์•ผ ์ด๋™ ๊ฐ€๋Šฅ
- [x] ํฌ๋Š” ํฌ๋ฅผ ๋›ฐ์–ด๋„˜๊ฑฐ๋‚˜ ํฌ๋ฅผ ์žก์„ ์ˆ˜ ์—†๋‹ค

### ๊ฒŒ์ž„ ์ง„ํ–‰

- [x] ์ดˆ(CHO)๊ฐ€ ๋จผ์ € ์‹œ์ž‘ํ•˜๊ณ  ์ดํ›„ ๋ฒˆ๊ฐˆ์•„ ์ง„ํ–‰ํ•œ๋‹ค
- [x] ๋งค ํ„ด ํ˜„์žฌ ๋ณด๋“œ ์ƒํƒœ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค
- [x] ์ž˜๋ชป๋œ ์ž…๋ ฅ ์‹œ ์žฌ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค

### ์ถœ๋ ฅ

- [x] 10x9 ๋ณด๋“œ๋ฅผ ์ฝ˜์†”์— ์ถœ๋ ฅํ•œ๋‹ค
- [x] ์ดˆ(CHO)๋Š” ํŒŒ๋ž€์ƒ‰, ํ•œ(HAN)์€ ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•œ๋‹ค
- [x] ๋นˆ ์นธ์€ `ใ…ก`๋กœ ํ‘œ์‹œํ•œ๋‹ค

---
12 changes: 12 additions & 0 deletions src/main/java/JanggiApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import controller.JanggiController;
import domain.piece.ConsolePieceAppearance;
import view.InputView;
import view.OutputView;

public class JanggiApplication {
public static void main(String[] args) {
JanggiController janggiController = new JanggiController(new InputView(),
new OutputView(new ConsolePieceAppearance()));
janggiController.run();
}
}
18 changes: 18 additions & 0 deletions src/main/java/controller/FormationConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package controller;

import domain.board.FormationType;

public final class FormationConverter {

private FormationConverter() {}

public static FormationType convert(int formationType) {
if (formationType == 1) return FormationType.LEFT_GIWMA;
if (formationType == 2) return FormationType.RIGHT_GIWMA;
if (formationType == 3) return FormationType.WONANGMA;
if (formationType == 4) return FormationType.YANGGWIMA;

throw new IllegalArgumentException("์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ์ƒ์ฐจ๋ฆผ ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.");
};

}
46 changes: 46 additions & 0 deletions src/main/java/controller/JanggiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package controller;

import domain.board.FormationType;
import domain.game.JanggiGame;
import domain.game.Team;
import domain.position.Position;
import java.util.List;
import view.InputView;
import view.OutputView;

public class JanggiController {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์งˆ๋ฌธ์ธ๋ฐ์š”. controller๋Š” ์–ด๋””์„œ ์ฐฉ์•ˆํ•˜์‹  ๋„ค์ด๋ฐ์ผ๊นŒ์š”? ์™œ controller์ธ๊ฐ€์š”?

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.

์ด๋ฒˆ์— ๋น„๋ฐฅ์ด ์งˆ๋ฌธํ•ด์ฃผ์‹  ๋•๋ถ„์— ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์–ด๋–ค ์—ญํ• ์„ ๊ฐ€์ ธ์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ๋‹ค์‹œ ์ •๋ฆฌํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์ž๋ฃŒ๋ฅผ ์ฐพ์•„๋ณด๋Š” ๊ณผ์ •์—์„œ ๊ธ€๋งˆ๋‹ค ์„ค๋ช…์ด ์กฐ๊ธˆ์”ฉ ๋‹ฌ๋ผ์„œ ๊ธฐ์ค€์„ ์žก๋Š” ๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์–ด๋ ค์›€์„ ๋А๊ผˆ๊ณ , ๊ทธ๋ž˜์„œ ๋‚˜๋ฆ„๋Œ€๋กœ ๊ธฐ์ค€์„ ์„ธ์›Œ ์ •๋ฆฌํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

์šฐ์„  ์ปจํŠธ๋กค๋Ÿฌ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ง„์ž…์ ์ด์ž ํ๋ฆ„์„ ์ œ์–ดํ•˜๋Š” ์—ญํ• ์ด๋ผ๊ณ  ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค. ์™ธ๋ถ€(View, ํด๋ผ์ด์–ธํŠธ)์™€ ๋‚ด๋ถ€(Model, Service) ์‚ฌ์ด์—์„œ ์ค‘๊ฐ„ ๋‹ค๋ฆฌ ์—ญํ• ์„ ํ•˜๋ฉด์„œ, ์ž…๋ ฅ์„ ๋„๋ฉ”์ธ์ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ๋ฐ˜๋Œ€๋กœ ๊ฒฐ๊ณผ๋ฅผ ์™ธ๋ถ€์— ๋งž๊ฒŒ ๋ณ€ํ™˜ํ•˜๋Š” โ€œ๋ฒˆ์—ญ๊ฐ€โ€ ์—ญํ• ์„ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์ž˜๋ชป๋œ ์š”์ฒญ์„ ์ดˆ๊ธฐ์— ๊ฑธ๋Ÿฌ๋‚ด๊ณ  ํ๋ฆ„์„ ์ œ์–ดํ•˜๋Š” โ€œ๋ฌธ์ง€๊ธฐโ€ ์—ญํ• ๋„ ํ•จ๊ป˜ ๊ฐ€์ง„๋‹ค๊ณ  ์ •๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.

์„œ๋น„์Šค ๋ ˆ์ด์–ด์˜ ์œ ๋ฌด์— ๋”ฐ๋ผ์„œ๋„ ์—ญํ• ์˜ ๋ฌด๊ฒŒ๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค๊ณ  ๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์„œ๋น„์Šค๊ฐ€ ์—†๋Š” ๊ตฌ์กฐ์—์„œ๋Š” ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋„๋ฉ”์ธ ๊ฐ์ฒด๋“ค์„ ์ง์ ‘ ์กฐํ•ฉํ•˜๋ฉด์„œ ํ๋ฆ„์„ ์ด๋„๋Š” ์—ญํ• ๊นŒ์ง€ ๋‹ด๋‹นํ•˜๊ฒŒ ๋˜๊ณ , ์„œ๋น„์Šค ๋ ˆ์ด์–ด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ๊ทธ ์ฑ…์ž„์„ ์„œ๋น„์Šค์— ์œ„์ž„ํ•˜๊ณ  ์ปจํŠธ๋กค๋Ÿฌ๋Š” ๋ผ์šฐํŒ…์— ์ง‘์ค‘ํ•˜๋Š” ๊ตฌ์กฐ๊ฐ€ ๋” ์ ์ ˆํ•˜๋‹ค๊ณ  ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.

๋˜ ํ•˜๋‚˜ ๊ณ ๋ฏผํ–ˆ๋˜ ๋ถ€๋ถ„์€, ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ View๋กœ ์–ด๋–ป๊ฒŒ ์ „๋‹ฌํ•ด์•ผ ํ•˜๋Š”์ง€์˜€์Šต๋‹ˆ๋‹ค. ๋„๋ฉ”์ธ ๋ชจ๋ธ์„ ๊ทธ๋Œ€๋กœ ๋„˜๊ธฐ๋Š” ๋ฐฉ์‹์€ View๊ฐ€ ๋„๋ฉ”์ธ ๋‚ด๋ถ€๋ฅผ ์•Œ๊ฒŒ ๋˜๋ฉด์„œ ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’์•„์ง„๋‹ค๊ณ  ๋А๊ผˆ๊ณ , ์ด๋ฅผ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด DTO๋กœ ๋ณ€ํ™˜ํ•ด์„œ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ์‹์ด ๋” ์ ์ ˆํ•˜๋‹ค๊ณ  ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค. DTO๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋„๋ฉ”์ธ์„ ๋ณดํ˜ธํ•  ์ˆ˜ ์žˆ๊ณ , View์™€์˜ ์˜์กด์„ฑ๋„ ๋Š์„ ์ˆ˜ ์žˆ์–ด์„œ ๋ณ€๊ฒฝ์— ๋” ์œ ์—ฐํ•˜๊ฒŒ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๋‚˜๋ฆ„๋Œ€๋กœ ๊ธฐ์ค€์„ ์„ธ์›Œ ์ •๋ฆฌํ•ด๋ณด์•˜๋Š”๋ฐ, ํ˜น์‹œ ์ œ๊ฐ€ ๋†“์น˜๊ณ  ์žˆ๊ฑฐ๋‚˜ ์ž˜๋ชป ์ดํ•ดํ•œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ๋น„๋ฐฅ์˜ ์˜๊ฒฌ์„ ๋“ค์–ด๋ณด๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์•„ ์ €๋Š” ์ง€๊ธˆ controller์— ๋Œ€ํ•ด ๊ต์œก์„ ๋ฐ›์€๊ฑด๊ฐ€ ํ•ด์„œ ์—ฌ์ญค๋ณธ๊ฑฐ์˜€๋Š”๋ฐ์š”

์ง€๊ธˆ์€ ์ด ๋ถ€๋ถ„๋ณด๋‹ค ๋‹ค๋ฅธ ๋ถ€๋ถ„์— ์ง‘์ค‘ํ•˜์‹œ๋Š”๊ฒŒ ๋” ๋‚ซ์ง€ ์•Š๋‚˜ ์‹ถ์Šต๋‹ˆ๋‹ค.

์ฐพ์•„๋ณด์‹  ๋‚ด์šฉ๋“ค์€ ์ž˜ ์ •๋ฆฌํ•ด์„œ ๊ณ„์†ํ•ด์„œ ๋ฐœ์ „์‹œํ‚ค๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ‘

private final InputView inputView;
private final OutputView outputView;

public JanggiController(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}

public void run() {
JanggiGame game = createGame();
outputView.printBoard(game.getBoard());
while (game.isRunning()) {
playTurn(game);
}
}

private JanggiGame createGame() {
FormationType choFormation = FormationConverter.convert(inputView.initialFormation(Team.CHO));
FormationType hanFormation = FormationConverter.convert(inputView.initialFormation(Team.HAN));
return JanggiGame.of(choFormation, hanFormation);
}

private void playTurn(JanggiGame game) {
while (true) {
try {
List<Position> positions = inputView.askMovePiecePosition(game.currentTurn());
game.move(positions.get(0), positions.get(1));
outputView.printBoard(game.getBoard());
return;
} catch (IllegalArgumentException e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ปจํŠธ๋กค๋Ÿฌ์—์„œ System.out.println์„ ์ง์ ‘ ํ˜ธ์ถœํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ์ถœ๋ ฅ ์ฑ…์ž„์€ OutputView์— ์žˆ์ง€ ์•Š์„๊นŒ์š”?

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.

๋งž๋Š” ๋ง์”€์ด์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ถœ๋ ฅ ์ฑ…์ž„์ด ์ปจํŠธ๋กค๋Ÿฌ์— ์žˆ์—ˆ๋„ค์š”! OutputView๋กœ ์˜ฎ๊ฒผ์Šต๋‹ˆ๋‹ค

outputView.printError(e.getMessage());
}
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/domain/board/AbstractBoardFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package domain.board;

import domain.game.Team;
import domain.piece.Piece;
import domain.piece.PieceType;
import domain.position.Position;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractBoardFactory implements BoardFactory {

private static final Map<FormationType, AbstractBoardFactory> factories = Map.of(
FormationType.LEFT_GIWMA, new LeftGwimaFactory(),
FormationType.RIGHT_GIWMA, new RightGwimaFactory(),
FormationType.WONANGMA, new WonangmaFactory(),
FormationType.YANGGWIMA, new YanggwimaFactory()
);

public static AbstractBoardFactory from(FormationType type) {
AbstractBoardFactory factory = factories.get(type);
if (factory == null) {
throw new IllegalStateException("ํ•ด๋‹น ํƒ€์ž…์˜ ํŒฉํ† ๋ฆฌ๊ฐ€ ๋“ฑ๋ก๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.");
}
return factory;
}

@Override
public Map<Position, Piece> createFormation(Team team) {
Map<Position, Piece> pieces = new HashMap<>();
setFixedPieces(pieces, team);
setVariablePieces(pieces, team);
return pieces;
}

private void setFixedPieces(Map<Position, Piece> pieces, Team team) {
placePieces(pieces, team, team.getBackRow(), PieceType.CHA);
placePieces(pieces, team, team.getBackRow(), PieceType.SA);
placePieces(pieces, team, team.getGeneralRow(), PieceType.GENERAL);
placePieces(pieces, team, team.getCannonRow(), PieceType.PHO);
placePieces(pieces, team, team.getSoldierRow(), PieceType.BYEONG);
}

private void placePieces(Map<Position, Piece> pieces, Team team, int row, PieceType type) {
for (int column : type.getInitialColumns()) {
pieces.put(new Position(row, column), type.createPiece(team));
}
}

protected abstract void setVariablePieces(Map<Position, Piece> pieces, Team team);
}
43 changes: 43 additions & 0 deletions src/main/java/domain/board/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package domain.board;

import domain.piece.EmptyPiece;
import domain.piece.Piece;
import domain.position.Position;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Board {
private final Map<Position, Piece> pieces;

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

public void move(Position source, Position destination) {
Piece piece = pieceAt(source);
validateCanMove(piece, source, destination);
List<Position> route = piece.calculateRoute(source, destination);
List<Piece> piecesOnRoute = route.stream()
.map(this::pieceAt)
.collect(Collectors.toList());
piece.validateRoute(piecesOnRoute, pieceAt(destination));
applyMove(source, destination, piece);
}

private void validateCanMove(Piece piece, Position source, Position destination) {
if (!piece.canMove(source, destination)) {
throw new IllegalArgumentException("์ด๋™ํ•  ์ˆ˜ ์—†๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.");
}
}

private void applyMove(Position source, Position destination, Piece piece) {
pieces.put(destination, piece);
pieces.put(source, EmptyPiece.getInstance());
}

public Piece pieceAt(Position position) {
return pieces.getOrDefault(position, EmptyPiece.getInstance());
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pieceAt์ด ํ˜ธ์ถœ๋  ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ์œ„์น˜์— ๊ธฐ๋ฌผ์ด ์—†์œผ๋ฉด new EmptyPiece()๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, OutputView.printBoard์—์„œ 10ร—9 = 90์นธ์„ ๋งค๋ฒˆ ์กฐํšŒํ•˜๋‹ˆ๊นŒ ๋นˆ ์นธ๋งˆ๋‹ค ์ƒˆ ๊ฐ์ฒด๊ฐ€ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค. EmptyPiece๋Š” ์ƒํƒœ๊ฐ€ ์—†์œผ๋‹ˆ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์žฌ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ณ ๋ คํ•ด๋ณด์‹œ๋ฉด ์–ด๋–จ๊นŒ์š”?

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.

์•ž์„œ ๋งํ•ด์ฃผ์‹  ์‹ฑ๊ธ€ํ†ค ๊ฐ์ฒด์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ดค์Šต๋‹ˆ๋‹ค.

ํ™•์‹คํžˆ ๊ธฐ์กด ์ œ ์ฝ”๋“œ์—์„œ๋Š” ํ•ญ์ƒ ์ƒˆ๋กœ์šด EmptyPiece๊ฐ€ ์ƒ์„ฑ๋˜๊ณ  ์žˆ์—ˆ๊ณ  ์ด๋กœ์ธํ•ด ๋ถˆํ•„์š”ํ•œ ๋ฆฌ์†Œ์Šค ๋‚ญ๋น„๊ฐ€ ์ผ์–ด๋‚˜๊ณ  ์žˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. EmptyPiece์— ์‹ฑ๊ธ€ํ†ค์„ ์ ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ํ•ด๋‹น ์ธ์Šคํ„ด์Šค๋Š” ๋Ÿฐํƒ€์ž„ ๋™์•ˆ ๋‹จ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋งŒ ์ƒ์„ฑ๋˜๊ณ  getInstance()๋ฅผ ํ†ตํ•ด ํ•„์š”ํ• ๋•Œ๋งˆ๋‹ค ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ๋”์šฑ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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

import domain.position.Position;
import domain.piece.Piece;
import domain.game.Team;
import java.util.Map;

public interface BoardFactory {
Map<Position, Piece> createFormation(Team team);
}
8 changes: 8 additions & 0 deletions src/main/java/domain/board/FormationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package domain.board;

public enum FormationType {
LEFT_GIWMA,
RIGHT_GIWMA,
WONANGMA,
YANGGWIMA
}
21 changes: 21 additions & 0 deletions src/main/java/domain/board/LeftGwimaFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain.board;

import domain.position.Position;
import domain.piece.Piece;
import domain.piece.PieceType;
import domain.game.Team;
import java.util.Map;

public class LeftGwimaFactory extends AbstractBoardFactory {
@Override
protected void setVariablePieces(Map<Position, Piece> pieces, Team team) {
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(0)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(1)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(2)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(3)),
PieceType.MA.createPiece(team));
}
}
23 changes: 23 additions & 0 deletions src/main/java/domain/board/RightGwimaFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package domain.board;

import domain.position.Position;
import domain.piece.Piece;
import domain.piece.PieceType;
import domain.game.Team;
import java.util.Map;

public class RightGwimaFactory extends AbstractBoardFactory {
@Override
protected void setVariablePieces(Map<Position, Piece> pieces, Team team) {
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(0)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(1)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(2)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(3)),
PieceType.SANG.createPiece(team));
}
}


21 changes: 21 additions & 0 deletions src/main/java/domain/board/WonangmaFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain.board;

import domain.position.Position;
import domain.piece.Piece;
import domain.piece.PieceType;
import domain.game.Team;
import java.util.Map;

public class WonangmaFactory extends AbstractBoardFactory {
@Override
protected void setVariablePieces(Map<Position, Piece> pieces, Team team) {
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(0)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(1)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(2)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(3)),
PieceType.SANG.createPiece(team));
}
}
21 changes: 21 additions & 0 deletions src/main/java/domain/board/YanggwimaFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain.board;

import domain.position.Position;
import domain.piece.Piece;
import domain.piece.PieceType;
import domain.game.Team;
import java.util.Map;

public class YanggwimaFactory extends AbstractBoardFactory {
@Override
protected void setVariablePieces(Map<Position, Piece> pieces, Team team) {
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(0)),
PieceType.MA.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(1)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(2)),
PieceType.SANG.createPiece(team));
pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(3)),
PieceType.MA.createPiece(team));
}
}
45 changes: 45 additions & 0 deletions src/main/java/domain/game/JanggiGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package domain.game;

import domain.board.AbstractBoardFactory;
import domain.board.Board;
import domain.board.FormationType;
import domain.piece.Piece;
import domain.position.Position;
import java.util.HashMap;
import java.util.Map;

public class JanggiGame {
private Turn turn;
private final Board board;

public JanggiGame(Turn turn, Board board) {
this.turn = turn;
this.board = board;
}

public static JanggiGame of(FormationType choFormation, FormationType hanFormation) {
Map<Position, Piece> pieces = new HashMap<>();
pieces.putAll(AbstractBoardFactory.from(choFormation)
.createFormation(Team.CHO));
pieces.putAll(AbstractBoardFactory.from(hanFormation)
.createFormation(Team.HAN));
return new JanggiGame(Turn.first(),new Board(pieces));
}

public void move(Position source, Position destination) {
board.move(source, 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.

board.move()๋ฅผ ํ˜ธ์ถœํ•œ ๋’ค ๋ฐ”๋กœ turn = turn.next()๋ฅผ ํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ํ˜„์žฌ ํ„ด์˜ ๊ธฐ๋ฌผ์ธ์ง€ ๊ฒ€์ฆํ•˜๋Š” ๋กœ์ง์ด ๋ณด์ด์ง€ ์•Š์•„์š”. ์ƒ๋Œ€๋ฐฉ ๊ธฐ๋ฌผ์„ ๋‚ด ํ„ด์— ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ, ์ด ๋ถ€๋ถ„์€ ์–ด๋””์„œ ๊ฒ€์ฆ๋˜๊ณ  ์žˆ๋‚˜์š”?

turn = turn.next();
}

public boolean isRunning() {
return true; // TODO: ์ข…๋ฃŒ ์กฐ๊ฑด ๊ตฌํ˜„
}

public Team currentTurn() {
return turn.current();
}

public Board getBoard() {
return board;
}
}
Loading