Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d4bacf5
feat(Position): Position ๋„๋ฉ”์ธ ๊ตฌํ˜„
haechanmoon Mar 25, 2026
cc4a35d
docs(readme): v1.1 ํŒ€ ์ถ”๊ฐ€ ๋ฐ ๊ธฐ๋ฌผ์ด ๊ทœ์น™์„ ๊ฐ–๊ณ ์žˆ๊ฒŒํ•จ
haechanmoon Mar 25, 2026
4d014e3
feat(Team): ์ดˆ๋‚˜๋ผ์™€ ํ•œ๋‚˜๋ผ enum์œผ๋กœ ๊ด€๋ฆฌ
haechanmoon Mar 25, 2026
782e1dc
docs(readme): v1.2 ๊ตฌํ˜„์˜ ์–ด๋ ค์›€์— ๋”ฐ๋ฅธ ๋„๋ฉ”์ธ ๋ณ€๊ฒฝ -> ๋Œ์•„๊ฐ€๋Š” ์ฝ”๋“œ๋ฅผ ์šฐ์„  ๋งŒ๋“ค์–ด๋ณด๊ธฐ
haechanmoon Mar 26, 2026
68a19d2
feat: ํ•ด๋‹น ๊ธฐ๋ฌผ์€ ํŒ€๊ณผ ๊ธฐ๋ฌผ ํƒ€์ž…์„ ๊ฐ€์ง„๋‹ค. TDD ๊ตฌํ˜„
haechanmoon Mar 26, 2026
0dac849
feat: ์ƒ์ฐจ๋ฆผ์€ ๋งˆ์ƒ๋งˆ์ƒ์œผ๋กœ ๊ณ ์ •ํ•˜์—ฌ ๋ณด๋“œ ์ดˆ๊ธฐํ™”
haechanmoon Mar 26, 2026
7aade2e
feat: ๊ฐ ๊ธฐ๋ฌผ์€ ๊ณ ์œ ์˜ ๊ทœ์น™์„ ๊ฐ€์ง„๋‹ค.
haechanmoon Mar 27, 2026
8e805d5
refactor: MoveRule ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
haechanmoon Mar 27, 2026
ed501e2
feat: ์กธ์˜ ์ด๋™๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
haechanmoon Mar 30, 2026
e55e727
test: ๋งˆ์˜ ์ด๋™๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
haechanmoon Mar 30, 2026
27ffdfc
fix(board): ์ƒ์„ฑ์ž์—์„œ ๋ณด๋“œ์ดˆ๊ธฐํ™” ์ œ๊ฑฐ
haechanmoon Mar 30, 2026
361391c
test: ์ƒ,์‚ฌ,์™•์˜ ์ด๋™๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
haechanmoon Mar 30, 2026
a49a2c4
feat: ์ฐจ์˜ ์ด๋™๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
haechanmoon Mar 30, 2026
adac323
feat: ํฌ์˜ ์ด๋™๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
haechanmoon Mar 30, 2026
08f4aad
test: DisplayName๊ณผ ๋ฉ”์„œ๋“œ๋ช… ๋ณ€๊ฒฝ
haechanmoon Mar 30, 2026
f7f0f3e
feat: ๋ทฐ์™€ ์ปจํŠธ๋กค๋Ÿฌ ๊ธฐ๋Šฅ ๊ตฌํ˜„
haechanmoon Mar 30, 2026
61a6903
feat: ์žฌ์ž…๋ ฅ ๋กœ์ง ๊ตฌํ˜„
haechanmoon Mar 30, 2026
3ed382f
refactor: ์ฝ”๋“œ ์Šคํƒ€์ผ ๊ฐœ์„ 
haechanmoon Mar 30, 2026
6f2249e
test(BoardTest): ํฌ ์ด๋™ ๋ถˆ๊ฐ€ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ ๊ฒ€์ฆ ํ…Œ์ŠคํŠธ๋กœ ์ˆ˜์ •
haechanmoon Mar 31, 2026
2e77c24
style(BoardTest): ์ฝ”๋“œ ํฌ๋งคํŒ…
haechanmoon Mar 31, 2026
e0ab761
refactor: ์ฑ…์ž„๊ณผ ์„ฑ๊ฒฉ์— ๋งž๊ฒŒ JanggiController -> JanggiGame ์œผ๋กœ ์ด๋ฆ„ ๋ณ€๊ฒฝ๊ฒฝ
haechanmoon Mar 31, 2026
a03d4ee
refactor(JanggiGame): ๋ฉ”์„œ๋“œ 10์ค„ ์ดํ•˜ ๋˜๋„๋ก ์ˆ˜์ •
haechanmoon Mar 31, 2026
740cc33
refactor: ๋ณด๋“œ ์ดˆ๊ธฐํ™” ๋กœ์ง BoardFactory๋กœ ์ด๋™
haechanmoon Apr 1, 2026
52041ea
refactor(Board): for๋ฌธ์„ stream ์œผ๋กœ ๋ณ€๊ฒฝ
haechanmoon Apr 2, 2026
de84fcc
refactor(PieceType): ๋ฏธ์‚ฌ์šฉ ํ•„๋“œ ์ œ๊ฑฐ
haechanmoon Apr 2, 2026
d0a52be
refactor(ZolMoveRule): ๋ถˆํ•„์š” ํ–‰ ์ œ๊ฑฐ
haechanmoon Apr 2, 2026
50a774f
style: ์ฝ”๋“œ ์Šคํƒ€์ผ ๋ณ€๊ฒฝ
haechanmoon Apr 2, 2026
d0557f7
refactor(Board): ๋ฉ”์„œ๋“œ๊ฐ€ ํ•œ๊ฐ€์ง€ ์ผ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ถ„๋ฆฌ
haechanmoon Apr 2, 2026
7635d5f
refactor(OutputView): ์ค‘๋ณต๋˜๋Š” ์ฝ”๋“œ ์ œ๊ฑฐ
haechanmoon Apr 2, 2026
1a9affe
refactor: ๋„๋ฉ”์ธ์—์„œ View๋กœ์ง ๋ถ„๋ฆฌ
haechanmoon 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: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
# java-janggi

์žฅ๊ธฐ ๋ฏธ์…˜ ์ €์žฅ์†Œ

version : 1.2 (๊ตฌํ˜„์˜ ์–ด๋ ค์›€์— ๋”ฐ๋ฅธ ๋„๋ฉ”์ธ ๋ณ€๊ฒฝ : ๋Œ์•„๊ฐ€๋Š” ์ฝ”๋“œ๋ฅผ ์šฐ์„  ๋งŒ๋“ค์–ด๋ณด๊ธฐ)

# ์‹œ๋‚˜๋ฆฌ์˜ค

1. ํ•œ๋‚˜๋ผ ์‚ฌ์šฉ์ž๊ฐ€ ์ƒ์ฐจ๋ฆผ์„ ์„ ํƒํ•œ๋‹ค.
2. ์ดˆ๋‚˜๋ผ ์‚ฌ์šฉ์ž๊ฐ€ ์ƒ์ฐจ๋ฆผ์„ ์„ ํƒํ•œ๋‹ค.
3. ์ดˆ๋‚˜๋ผ ์‹œ์ž‘
1. ์ด๋™ํ•  ๊ธฐ๋ฌผ์˜ ์ขŒํ‘œ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค. (๋ฌด๋ฅด๊ธฐ : q)

ํ˜„์žฌ ๋ณด๋“œ๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

ex) ์กธ์„ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์กธ์€ ํ˜„์žฌ (1,1)์— ์žˆ์Šต๋‹ˆ๋‹ค.

2. ํ•ด๋‹น ๊ธฐ๋ฌผ์ด ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ์ขŒํ‘œ๋ฅผ ๋ณด์—ฌ์ค€๋‹ค. (๊ธฐ๋ฌผ ๋‹ค์‹œ์„ ํƒ : r)
- ๋งŒ์•ฝ์— ์•„๋ฌด๋ฐ๋„ ์ด๋™ ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉด ๋‹ค์‹œ a๋กœ ๋Œ์•„๊ฐ€์„œ ์„ ํƒํ•˜๊ฒŒ ํ•œ๋‹ค.
3. ๋ณด์—ฌ์ง„ ์ขŒํ‘œ ์ค‘ ์ด๋™ํ•  ์ขŒํ‘œ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.
- ์ด๋™ํ•  ์ขŒํ‘œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.(์˜ˆ์‹œ: 3, 5)
4. ํ•ด๋‹น ์ขŒํ‘œ๋กœ ์ด๋™ํ•œ๋‹ค.
4. ํ•œ๋‚˜๋ผ ์‹œ์ž‘

์ดˆ๋‚˜๋ผ์™€ ๋™์ผ

# ๋„๋ฉ”์ธ ๊ตฌํ˜„ ๋ฆฌ์ŠคํŠธ

- **๋ณด๋“œ**
- [x] ์ƒ์ฐจ๋ฆผ์€ ๋งˆ์ƒ๋งˆ์ƒ์œผ๋กœ ๊ณ ์ •ํ•˜์—ฌ ์ดˆ๊ธฐํ™” ํ•œ๋‹ค. (์ถ”ํ›„ ์ถ”๊ฐ€ ์˜ˆ์ •)
- [x] ํ•ด๋‹น ๊ธฐ๋ฌผ์˜ ์ด๋™ ๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•œ๋‹ค
- ๋ฉฑ์— ๋‹ค๋ฅธ ๊ธฐ๋ฌผ์ด ์žˆ์œผ๋ฉด ์•ˆ ๋˜๋Š” ๊ฒฝ์šฐ: ๋งˆ,์ƒ, ์กธ/๋ณ‘, ์ฐจ, ์žฅ, ์‚ฌ
- ๋ฉฑ ์‚ฌ์ด์— ํ•˜๋‚˜์˜ ๊ธฐ๋ฌผ์ด ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ: ํฌ
- ๊ทธ ๊ธฐ๋ฌผ์ด ํฌ์—ฌ์„œ๋Š” ์•ˆ ๋œ๋‹ค.
- ์ด๋™ํ•˜๊ณ ์ž ํ•˜๋Š” ์ขŒํ‘œ ์ž์ฒด๊ฐ€ ํฌ or ์•„๊ตฐ์ด๋ฉด ์•ˆ ๋œ๋‹ค.
- [x] ๊ธฐ๋ฌผ์„ ์ด๋™์‹œํ‚จ๋‹ค.
- **์ขŒํ‘œ**
- [x] ๋ณด๋“œ ๋‚ด์˜ ์ขŒํ‘œ ๋ฒ”์œ„๋ฅผ ๊ฒ€์ฆํ•œ๋‹ค.
- **๊ธฐ๋ฌผ**
- [x] ํ•ด๋‹น ๊ธฐ๋ฌผ์€ ํŒ€๊ณผ ๊ธฐ๋ฌผ ํƒ€์ž…์„ ๊ฐ€์ง„๋‹ค.
- [x] PieceType(enum) ์ž‘์„ฑ
- [x] ํŒ€ Team(enum) ์ž‘์„ฑ
- **๊ทœ์น™**
- [x] ๊ฐ ๊ธฐ๋ฌผ์€ ๊ณ ์œ ์˜ ๊ทœ์น™์„ ๊ฐ€์ง„๋‹ค.
Empty file removed src/main/java/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions src/main/java/janggi/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package janggi;

import janggi.controller.JanggiGame;

public class Application {
public static void main(String[] args) {
JanggiGame janggiGame = new JanggiGame();
janggiGame.run();
}
}
71 changes: 71 additions & 0 deletions src/main/java/janggi/controller/JanggiGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package janggi.controller;

import janggi.domain.Piece;
import janggi.domain.Position;
import janggi.domain.board.Board;
import janggi.domain.board.BoardFactory;
import janggi.view.InputView;
import janggi.view.OutputView;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public class JanggiGame {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ด ๋ถ€๋ถ„์€ ํ›„์ˆœ์œ„๋กœ ๋‘๊ณ  ์ž‘์—…ํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค)

๊ฒŒ์ž„ ์ž์ฒด๋„ ํ•˜๋‚˜์˜ ๋„๋ฉ”์ธ ๊ฐ์ฒด๋กœ ๋ฐ”๋ผ๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”.
์ง€๊ธˆ ๊ตฌ์กฐ๋Š” ๊ฒŒ์ž„ ์ง„ํ–‰๊ณผ ์ž…์ถœ๋ ฅ ๊ฐ•๊ฒฐํ•ฉ ๋˜์–ด ์žˆ๋Š”๋ฐ Application์ด ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์„ ๋‹ด๋‹นํ•˜๊ณ  Game์€ ๊ฒŒ์ž„ ์ง„ํ–‰์— ํ•„์š”ํ•œ ์ƒํƒœ์™€ ๊ทœ์น™๋งŒ ๊ด€๋ฆฌํ•˜๋„๋ก ๋‚˜๋ˆ„๋ฉด ์ฑ…์ž„์ด ๋” ์„ ๋ช…ํ•ด์งˆ ๊ฒƒ ๊ฐ™์•„์š”. ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด ์ดํ›„์— ํ„ด ๊ด€๋ฆฌ๋‚˜ ์ข…๋ฃŒ ์กฐ๊ฑด ๊ฐ™์€ ๊ทœ์น™๋„ UI์™€ ๋…๋ฆฝ์ ์œผ๋กœ ๋‹ค๋ฃจ๊ธฐ ์‰ฌ์›Œ์งˆ ๊ฒƒ ๊ฐ™์•„์š”.


private final InputView inputView = new InputView();
private final OutputView outputView = new OutputView();
private boolean isChoTurn = true;

public void run() {
Board board = initializeBoard();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

JanggiGame์ด ๊ฒŒ์ž„ ์ง„ํ–‰์„ ๋‹ด๋‹นํ•œ๋‹ค๋ฉด,๊ทธ ์•ˆ์—์„œ ๊ณ„์† ์‚ฌ์šฉํ•˜๋Š” Board๋Š” ์ธ์Šคํ„ด์Šค ํ•„๋“œ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ์–ด๋–จ๊นŒ์š”? ํ˜„์žฌ๋Š” ์—ฌ๋Ÿฌ ๋ฉ”์„œ๋“œ์—์„œ ๊ณ„์† Board๋ฅผ ์ธ์ž๋กœ ์ „๋‹ฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ๊ฒŒ์ž„์ด ์ง์ ‘ ๊ด€๋ฆฌํ•˜๋Š” ์ƒํƒœ๋ผ๋ฉด ํ•„๋“œ๋กœ ๋‘๋Š” ์ชฝ์ด ๊ฐ์ฒด์˜ ์—ญํ• ์„ ๋” ์ž์—ฐ์Šค๋Ÿฌ์›Œ ๋ณด์—ฌ์š”.

outputView.printBoard(board.getBoard());
while (true) {
isChoTurn = playTurn(board);
}
}

private boolean playTurn(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.

ํ„ด์— ๋Œ€ํ•œ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ์€ ์žˆ๋Š”๋ฐ, ์‹ค์ œ ํ„ด ๊ฐœ๋…์ด ๋„๋ฉ”์ธ์— ์—†๋Š” ๊ฒƒ ๊ฐ™์•„์š”. ํ•œ๋‚˜๋ผ ์ฐจ๋ก€์—๋„ ์ดˆ๋‚˜๋ผ ๋ง์„ ์›€์ง์ผ ์ˆ˜ ์žˆ๋„ค์š”

outputView.printTurnMessage(isChoTurn);
Position movePiecePosition = choosePieceToMove(board);
List<Position> availablePositions = board.findAvailablePositions(movePiecePosition);
outputView.printAvailablePositions(board.getBoard(), availablePositions);
Position targetPosition = chooseTargetPosition(board, movePiecePosition);
board.movePiece(movePiecePosition, targetPosition);
outputView.printBoard(board.getBoard());
isChoTurn = !isChoTurn;
return isChoTurn;
}

private Board initializeBoard() {
Map<Position, Piece> initBoard = BoardFactory.settingUpBoard();
return new Board(initBoard);
}

private Position chooseTargetPosition(Board board, Position movePiecePosition) {
return retry(() -> {
outputView.printMoveChoiceInfo();
Position position = inputView.readPosition();
board.validateDestination(movePiecePosition, position);
return position;
});
}

private Position choosePieceToMove(Board board) {
return retry(() -> {
outputView.printMoveInfo();
Position position = inputView.readPosition();
board.findAvailablePositions(position);
return position;
});
}

private <T> T retry(Supplier<T> inputFunction) {
while (true) {
try {
return inputFunction.get();
} catch (IllegalArgumentException e) {
OutputView.printErrorMessage(e.getMessage());
}
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/janggi/domain/Direction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package janggi.domain;

public enum Direction {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

up, down ๋“ฑ ๋ณด๋‹ค ๋” ์ข‹์€ ์˜ˆ์‹œ๊ฐ€ ์žˆ์–ด์š”. ๋‚˜์นจ๋ฐ˜์„ ํ™œ์šฉํ•ด๋ด…์‹œ๋‹ค~

UP(0, -1),
DOWN(0, 1),
LEFT(-1, 0),
RIGHT(1, 0),
UP_LEFT(-1, -1),
UP_RIGHT(1, -1),
DOWN_LEFT(-1, 1),
DOWN_RIGHT(1, 1),
;

private final int x;
private final int y;

Direction(int x, int y) {
this.x = x;
this.y = y;
}

public int getX() {
return x;
}

public int getY() {
return y;
}
}
7 changes: 7 additions & 0 deletions src/main/java/janggi/domain/MoveRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package janggi.domain;

import java.util.List;

public interface MoveRule {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ง€๊ธˆ์˜ MoveRule์€ ๊ฐ ๊ธฐ๋ฌผ์˜ ์ด๋™ ๊ทœ์น™์„ ์ง์ ‘ ํŒ๋‹จํ•˜๊ธฐ๋ณด๋‹ค๋Š” ์ด๋™ ๋ฐฉํ–ฅ ๋ชฉ๋ก๋งŒ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์‹ค์ œ ๊ฒฝ๋กœ ๊ณ„์‚ฐ๊ณผ ์žฅ์• ๋ฌผ ๊ฒ€์‚ฌ ์ด๋™ ๊ฐ€๋Šฅ ์—ฌ๋ถ€ ํŒ๋‹จ์€ ๋Œ€๋ถ€๋ถ„ Board๊ฐ€ ๋‹ด๋‹นํ•˜๊ณ  ์žˆ์–ด์š”. ๊ทธ๋ž˜์„œ Board์—์„œ isPo() ๊ฐ™์€ ํƒ€์ž… ๋ถ„๊ธฐ๊ฐ€ ๋‚˜์˜ค๊ณ  ์ด๋™ ๊ทœ์น™์ด MoveRule์ด๋‚˜ Piece์— ์ถฉ๋ถ„ํžˆ ๋จธ๋ฌผ์ง€ ๋ชปํ•˜๊ณ  Board ์ชฝ์— ๋งŽ์ด ๋ชจ์—ฌ ์žˆ๋Š” ๋“ฏํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฐ ๊ตฌ์กฐ๋ผ๋ฉด MoveRule์ด ์ง€๊ธˆ ์ •๋ง ์˜๋ฏธ ์žˆ๋Š” ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ•œ ๋ฒˆ ๊ณ ๋ฏผํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”. ๋งŒ์•ฝ ์ด๋™ ๊ทœ์น™์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ์ฒด๋ผ๋ฉด, ๋‹จ์ˆœํžˆ ๋ฐฉํ–ฅ๋งŒ ๋„˜๊ฒจ์ฃผ๊ธฐ๋ณด๋‹ค ํ˜„์žฌ ๋ณด๋“œ ์ƒํƒœ์—์„œ ์–ด๋””๊นŒ์ง€ ์ด๋™ ๊ฐ€๋Šฅํ•œ์ง€๊นŒ์ง€ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜๋Š” ์ชฝ์ด ๋” ์ž์—ฐ์Šค๋Ÿฌ์›Œ ๋ณด์ž…๋‹ˆ๋‹ค. Piece๊ฐ€ ์ž์‹ ์˜ ์ด๋™ ๊ฐ€๋Šฅ ์œ„์น˜๋ฅผ ์ง์ ‘ ํŒ๋‹จํ•˜๋„๋ก ๋งŒ๋“ค์–ด๋ณด๋Š” ๊ฒƒ๋„ ๋ฐฉ๋ฒ•์ผ ๊ฒƒ ๊ฐ™์€๋ฐ์š”. ์กฐํ•ฉ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด Piece๊ฐ€ MoveRule์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ฐ€ ์ด๋™ ๊ฐ€๋Šฅ ์œ„์น˜ ๊ณ„์‚ฐ์„ ์œ„์ž„ํ•  ์ˆ˜ ์žˆ๊ณ , ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด Board๋Š” ํŒ์˜ ์ƒํƒœ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์—ญํ• ์— ๋” ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

List<Route> findRoutes(Team team);
}
48 changes: 48 additions & 0 deletions src/main/java/janggi/domain/Piece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package janggi.domain;

import java.util.List;
import java.util.Objects;

public class Piece {

private final Team team;
private final PieceType pieceType;

public Piece(Team team, PieceType pieceType) {
this.team = team;
this.pieceType = pieceType;
}

public PieceType getPieceType() {
return pieceType;
}

public Team getTeam() {
return team;
}

public boolean isCha() {
return pieceType == PieceType.CHA;
}

public boolean isPo() {
return pieceType == PieceType.PO;
}

public List<Route> findRoutes() {
return pieceType.getMoveRule().findRoutes(this.team);
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Piece piece)) {
return false;
}
return team == piece.team && pieceType == piece.pieceType;
}

@Override
public int hashCode() {
return Objects.hash(team, pieceType);
}
}
35 changes: 35 additions & 0 deletions src/main/java/janggi/domain/PieceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package janggi.domain;

import janggi.domain.moveRules.ChaMoveRule;
import janggi.domain.moveRules.KingMoveRule;
import janggi.domain.moveRules.MaMoveRule;
import janggi.domain.moveRules.PoMoveRule;
import janggi.domain.moveRules.SaMoveRule;
import janggi.domain.moveRules.SangMoveRule;
import janggi.domain.moveRules.ZolMoveRule;

public enum PieceType {
KING("์™•", new KingMoveRule()),
SA("์‚ฌ", new SaMoveRule()),
SANG("์ƒ", new SangMoveRule()),
MA("๋งˆ", new MaMoveRule()),
CHA("์ฐจ", new ChaMoveRule()),
PO("ํฌ", new PoMoveRule()),
ZOL("์กธ", new ZolMoveRule());

private final String name;
private final MoveRule moveRule;

PieceType(String name, MoveRule moveRule) {
this.name = name;
this.moveRule = moveRule;
}

public String getName() {
return name;
}

public MoveRule getMoveRule() {
return moveRule;
}
}
51 changes: 51 additions & 0 deletions src/main/java/janggi/domain/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package janggi.domain;

import java.util.Objects;

public class Position {

private static final int MIN_X = 1;
private static final int MAX_X = 9;
private static final int MIN_Y = 1;
private static final int MAX_Y = 10;

private final int x;
private final int y;
Comment on lines +12 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

x,y ๊ฐ€ ์ขŒํ‘œ๋ฅผ ์˜๋ฏธํ•˜๋Š”๊ฑด ์•Œ์ง€๋งŒ ๋” ์˜๋ฏธ ์žˆ๋Š” ์ด๋ฆ„์€ ์—†์„๊นŒ์š”?
๋‹จ์ˆœ ์ˆ˜ํ•™ ์ขŒํ‘œ๋ณด๋‹ค row col๊ณผ ๊ฐ™์€ ์ด๋ฆ„๋„ ์žˆ๊ฒ ๋„ค์š”


public Position(int x, int y) {
validateBoundary(x, y);
this.x = x;
this.y = y;
}

public static boolean isInsideBoundary(int x, int y) {
return x >= MIN_X && x <= MAX_X && y >= MIN_Y && y <= MAX_Y;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Position position)) {
return false;
}
return x == position.x && y == position.y;
}

@Override
public int hashCode() {
return Objects.hash(x, y);
}

private void validateBoundary(int x, int y) {
if (x < MIN_X || x > MAX_X || y < MIN_Y || y > MAX_Y) {
throw new IllegalArgumentException("[ERROR] ๋ณด๋“œ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค.");
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/janggi/domain/Route.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package janggi.domain;

import java.util.List;
import java.util.Objects;

public class Route {

private final List<Direction> routes;

public Route(List<Direction> routes) {
this.routes = routes;
}

public List<Direction> getRoutes() {
return routes;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Route route)) {
return false;
}
return Objects.equals(routes, route.routes);
}

@Override
public int hashCode() {
return Objects.hashCode(routes);
}
}
7 changes: 7 additions & 0 deletions src/main/java/janggi/domain/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package janggi.domain;

public enum Team {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ํŒ€ ๊ด€๋ จํ•ด์„œ ๋ฉ”์„œ๋“œ๋“ค์„ ์‘์ง‘ํ•ด๋ด…์‹œ๋‹ค. ๊ฐ™์€ ํŒ€ ํŒ๋‹จ ๋“ฑ

CHO,
HAN,
;
}
Loading