-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด1 - ๋ฏธ์ (๋ณด๋ ์ด๊ธฐํ + ๊ธฐ๋ฌผ ์ด๋)] ๋ฐ๋ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #257
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: frombunny
Are you sure you want to change the base?
Changes from all commits
9c01c02
59fcc57
327b8af
1be6794
02d30c2
bcff3b2
07bc1de
f37bd67
2fdf8a0
44b13c5
f7c7a9d
e6d3cfb
1a30917
1c49c85
4a8fb06
5fbb7ac
ea97418
5109408
5fcb757
4723ed7
e595d08
1d2e22c
83f9817
ec81880
9e98fcc
5a2beb6
563868b
779dd7e
0fc9a24
1439b54
1705213
11e40a6
8f6a7db
b36fa6e
4368531
0637768
d9c59fc
4087a05
6d434a0
780e132
877247c
a311337
99610dc
aae6b44
561cda7
3549d35
74fc93a
43e9627
906399c
a17bc6b
2a4b1e5
8a3671f
700e8ea
4a6f08f
809c2ae
033710a
9701db2
4e68aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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์นธ์ฉ ์์ง์ผ ์ ์์ผ๋, ํํดํ ์ ์๋ค. |
| 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); | ||
| } | ||
| } |
| 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) { | ||
| 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("์ขํ๋ ์ซ์๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค."); | ||
| } | ||
| } | ||
| } | ||
| 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)) { | ||
|
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. false์ธ ํ ์คํธ ์ผ์ด์ค๊ฐ ์๋๊ฑธ๋ณด๋ ๋น ๊ณต๊ฐ์ผ๋ก ๊ธฐ๋ฌผ์ด ์ด๋ํ๋ ๊ฒฝ์ฐ์ ๋ํ ํ ์คํธ ์ผ์ด์ค๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค~ |
||
| handleCapture(pieceAt(departure), destination); | ||
| } | ||
|
Comment on lines
+48
to
+55
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. executeMove ๋ฉ์๋ ๋ด๋ถ์ ๋ฃ์ด๋ ๋๋ ๋ก์ง ๊ฐ์ต๋๋ค.
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. ํ์คํ 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); | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } |
| 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 ๋๋ ์ด๋ฆ์ผ๋ก ์ ๋ ฅํด์ผ ํฉ๋๋ค."); | ||
| }; | ||
| } | ||
| } |
| 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)); | ||
| } | ||
| } | ||
| } |
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.
board๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ๋ณ๊ฒฝํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์~