-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด1 - ๋ฏธ์ (๋ณด๋ ์ด๊ธฐํ + ๊ธฐ๋ฌผ ์ด๋)] ๋๋ฌด ๋ฏธ์ ์ ์ถํฉ๋๋ค. #264
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: symflee
Are you sure you want to change the base?
Changes from all commits
e350817
54c52f7
cea7131
a4dd966
2ecd53b
dc5aea1
e80a819
6fae64a
47da921
c332484
0e135c2
0705f6a
f23ebdd
f4e3164
e777f0f
e3019f7
8202ac2
79e0ec1
67523a2
232df9b
507f00b
d1cc672
9b7c1e6
895149b
10fa86b
488a630
f1856ae
fad8f35
6d6c28f
552a14d
9c10571
65d48a8
8ecccff
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 |
|---|---|---|
|
|
@@ -30,3 +30,5 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| REFACTORING.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,172 @@ | ||
| # java-janggi | ||
|
|
||
| ์ฅ๊ธฐ ๋ฏธ์ ์ ์ฅ์ | ||
| ## ๐ ๋ชฉ์ฐจ | ||
|
|
||
| - [๊ฐ์](#-๊ฐ์) | ||
| - [๊ตฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก](#-๊ตฌํ-๊ธฐ๋ฅ-๋ชฉ๋ก) | ||
| - [์ ์ถ๋ ฅ ์๊ตฌ ์ฌํญ](#์ ์ถ๋ ฅ-์๊ตฌ-์ฌํญ) | ||
| - [์ปค๋ฐ ์ปจ๋ฒค์ ](#์ปค๋ฐ-์ปจ๋ฒค์ ) | ||
|
|
||
| --- | ||
|
|
||
| ## 1๏ธโฃ ๊ฐ์ | ||
|
|
||
| ### ๊ธฐ๋ฅ ํ๋ฆ | ||
|
|
||
| ``` | ||
| [๊ฒ์ ์์] | ||
| โ | ||
| โผ | ||
| [์์ฐจ๋ฆผ ์ ๋ ฅ - ReadyState] | ||
| ํ(HAN) ์์ฐจ๋ฆผ ์ ํ (1~4) | ||
| โ ์์ธ โ ์ฌ์ ๋ ฅ | ||
| โผ | ||
| ์ด(CHO) ์์ฐจ๋ฆผ ์ ํ (1~4) | ||
| โ ์์ธ โ ์ฌ์ ๋ ฅ | ||
| โผ | ||
| [๋ณด๋ ์ด๊ธฐํ] | ||
| ์ ๋ ฅ๋ ์์ฐจ๋ฆผ ๊ธฐ์ค์ผ๋ก ๊ธฐ๋ฌผ ๋ฐฐ์น | ||
| โ | ||
| โผ | ||
| [๊ฒ์ ์งํ - PlayingState] โโโโโโโโโโโโโโโโโโ | ||
| ํ์ฌ ํด ์ถ๋ ฅ + ๋ณด๋ ์ถ๋ ฅ โ | ||
| โ โ | ||
| โผ โ | ||
| ์ฐฉ์ ๋ช ๋ น์ด ์ ๋ ฅ ({์ถ๋ฐ์ขํ} {๋์ฐฉ์ขํ}) โ | ||
| โ ์์ธ โ ์ฌ์ ๋ ฅ (ํ์ฌ ํด ์ ์ง) โ | ||
| โผ โ | ||
| ์ด๋ ์ ํจ์ฑ ๊ฒ์ฆ โ | ||
| โโ ์ถ๋ฐ ์ขํ์ ๊ธฐ๋ฌผ ์์ โ ์์ธ โ | ||
| โโ ์ถ๋ฐ ์ขํ๊ฐ ์๋ ๊ธฐ๋ฌผ โ ์์ธ โ | ||
| โโ ๋์ฐฉ ์ขํ์ ์๊ตฐ ๊ธฐ๋ฌผ โ ์์ธ โ | ||
| โโ ๊ธฐ๋ฌผ ์ด๋ ๊ท์น ์๋ฐ โ ์์ธ โ | ||
| โ ์ฑ๊ณต โ | ||
| โผ โ | ||
| ๊ธฐ๋ฌผ ์ด๋ (๋์ฐฉ ์ขํ์ ์๋ ๊ธฐ๋ฌผ ์์ผ๋ฉด ์ ๊ฑฐ) โ | ||
| โ โ | ||
| โผ โ | ||
| ํด ๊ต์ฒด (ํ โ ์ด) โโโโโโโโโโโโโโโโโโโโโโโโโโ | ||
| ``` | ||
|
|
||
| ## 2๏ธโฃ ๊ตฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก | ||
|
|
||
| ### โ 1์ฐจ ๊ตฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก | ||
|
|
||
| #### 1.1๋จ๊ณ: ๋ณด๋ ์ด๊ธฐํ | ||
|
|
||
| - [x] **1. [์ถ๋ ฅ] ์์ฐจ๋ฆผ ์์๋ฅผ ์ถ๋ ฅํ๋ค.** | ||
| - [x] **2. [์ ๋ ฅ] ์์ฐจ๋ฆผ์ ์ ๋ ฅ๋ฐ๋๋ค.** | ||
| - [x] [์ ๋ ฅ] ํ์ ์์ฐจ๋ฆผ์ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ๋น ์ ๋ ฅ์ผ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] 1~4 ์ธ์ ๋ฌธ์๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์ ๋ ฅ] ์ด์ ์์ฐจ๋ฆผ์ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ๋น ์ ๋ ฅ์ผ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] 1~4 ์ธ์ ๋ฌธ์๋ฅผ ์ ๋ ฅํ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] **3. [์ค๊ฐ ๊ณผ์ ] ์ ๋ ฅ๋ฐ์ ์์ฐจ๋ฆผ์ ๊ธฐ์ค์ผ๋ก ๊ธฐ๋ฌผ์ ๋ฐฐ์นํ๋ค.** | ||
| - [x] **4. [์ถ๋ ฅ] ํ์ฌ ๋ณด๋์ ๊ธฐ๋ฌผ ๋ฐฐ์น๋ฅผ ์ถ๋ ฅํ๋ค.** | ||
|
|
||
| #### 1.2๋จ๊ณ: ๊ธฐ๋ฌผ ์ด๋ | ||
|
|
||
| - [x] **5. [์ถ๋ ฅ] ์ฐฉ์ ๋ช ๋ น์ด ํ์๊ณผ ํ์ฌ ์ด๋ ํ์ ํด์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ค.** | ||
| - [x] **6. [์ ๋ ฅ] ํ์ฌ ํด์ ์งํ์์๊ฒ ์ฐฉ์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. (ex. '{์ถ๋ฐ์ขํ} {๋์ฐฉ์ขํ}' 'A0 B1')** | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ๋น ์ ๋ ฅ์ผ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ์ ๋ ฅ๋ฐ์ ๊ฐ์ด ์ง์ ํ์์ธ '{์ถ๋ฐ์ขํ} {๋์ฐฉ์ขํ}'๊ฐ ์๋ ๊ฒฝ์ฐ ` IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ์ ๋ ฅ๋ฐ์ column ๊ฐ์ด A~I ๋ฒ์์ ๊ฐ์ด ์๋ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ์ ๋ ฅ๋ฐ์ row ๊ฐ์ด 0~9 ๋ฒ์์ ๊ฐ์ด ์๋ ๊ฒฝ์ฐ `IllegalArgumentException` ์ ๋ฐ์์ํค๊ณ , ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] **7. [์ค๊ฐ ๊ณผ์ ] ์ฌ์ฉ์๊ฐ ๋ช ๋ นํ ์ฐฉ์๋ฅผ ์ํํ๋ค.** | ||
| - [x] [์์ธ ์ฒ๋ฆฌ] ์๋์ ๊ฒฝ์ฐ ์ ์ด๋์ด ๋ถ๊ฐ๋ฅํ์ง ์ถ๋ ฅํ๊ณ , ํด๋น ํ๋ ์ด์ด์ ํด์ผ๋ก ์ฒ์๋ถํฐ ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค. | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ์ถ๋ฐ ์ขํ์ ๊ธฐ๋ฌผ์ด ์๋ ๊ฒฝ์ฐ | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ์ถ๋ฐ ์ขํ์ ์๋ ๊ธฐ๋ฌผ์ด ์๋ ๊ฒฝ์ฐ | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ๊ฐ ๊ธฐ๋ฌผ ๊ณ ์ ์ ์ด๋ ๊ท์น์ ๋ฐ๋ผ ์ด๋์ด ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ๋์ฐฉ ์ขํ์ ์๊ตฐ ๊ธฐ๋ฌผ์ด ์์ ๊ฒฝ์ฐ | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ๋์ฐฉ ์ขํ์ ์๋ ๊ธฐ๋ฌผ์ด ์์ผ๋ฉด ์์ค๋ค. | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ์ถ๋ฐ ์ขํ์ ์๋ ๊ธฐ๋ฌผ์ ๋์ฐฉ ์ขํ๋ก ์ฎ๊ธด๋ค. | ||
| - [x] [์ค๊ฐ ๊ณผ์ ] ํด์ ๋๊ธด๋ค. | ||
|
|
||
| ## 3๏ธโฃ ์ ์ถ๋ ฅ ์๊ตฌ ์ฌํญ | ||
|
|
||
| ### ์คํ ๊ฒฐ๊ณผ ์์ | ||
|
|
||
| ``` | ||
| [ํ(HAN) ์ง์] ๋ฐฐ์น๋ฅผ ์ ํํ์ธ์. | ||
| 1. ๋ง-์-๋ง-์ (Horse-Elephant-Horse-Elephant) | ||
| 2. ๋ง-์-์-๋ง (Horse-Elephant-Elephant-Horse) | ||
| 3. ์-๋ง-๋ง-์ (Elephant-Horse-Horse-Elephant) | ||
| 4. ์-๋ง-์-๋ง (Elephant-Horse-Elephant-Horse) | ||
| > 1 | ||
|
|
||
| [์ด(CHO) ์ง์] ๋ฐฐ์น๋ฅผ ์ ํํ์ธ์. | ||
| 1. ๋ง-์-๋ง-์ (Horse-Elephant-Horse-Elephant) | ||
| 2. ๋ง-์-์-๋ง (Horse-Elephant-Elephant-Horse) | ||
| 3. ์-๋ง-๋ง-์ (Elephant-Horse-Horse-Elephant) | ||
| 4. ์-๋ง-์-๋ง (Elephant-Horse-Elephant-Horse) | ||
| > 2 | ||
|
|
||
| -------------------------------------- | ||
| ํ์ฌ ํด: [์ด(CHO) ์ง์] | ||
|
|
||
| a b c d e f g h i | ||
| 0 ํ์ฐจ ํ๋ง ํ์ ํ์ฌ ... ํ์ฌ ํ๋ง ํ์ ํ์ฐจ | ||
| 1 ... ... ... ... ํ๊ถ ... ... ... ... | ||
| 2 ... ํํฌ ... ... ... ... ... ํํฌ ... | ||
| 3 ํ๋ณ ... ํ๋ณ ... ํ๋ณ ... ํ๋ณ ... ํ๋ณ | ||
| 4 ... ... ... ... ... ... ... ... ... | ||
| 5 ... ... ... ... ... ... ... ... ... | ||
| 6 ์ด์กธ ... ์ด์กธ ... ์ด์กธ ... ์ด์กธ ... ์ด์กธ | ||
| 7 ... ์ดํฌ ... ... ... ... ... ์ดํฌ ... | ||
| 8 ... ... ... ... ์ด๊ถ ... ... ... ... | ||
| 9 ์ด์ฐจ ์ด๋ง ์ด์ ์ด์ฌ ... ์ด์ฌ ์ด์ ์ด๋ง ์ด์ฐจ | ||
|
|
||
| [์ด(CHO) ์ง์] {์ถ๋ฐ ์ขํ} {๋์ฐฉ ์ขํ} ํ์์ผ๋ก ์ ๋ ฅํด ์๋ฅผ ๋์ธ์. (ex. e6 e5) | ||
| > ์๊ธฐ | ||
|
|
||
| [ERROR] ์ขํ ํ์์ด ํ๋ ธ์ต๋๋ค! | ||
|
|
||
| -------------------------------------- | ||
| ํ์ฌ ํด: [์ด(CHO) ์ง์] | ||
|
|
||
| a b c d e f g h i | ||
| 0 ํ์ฐจ ํ๋ง ํ์ ํ์ฌ ... ํ์ฌ ํ๋ง ํ์ ํ์ฐจ | ||
| 1 ... ... ... ... ํ๊ถ ... ... ... ... | ||
| 2 ... ํํฌ ... ... ... ... ... ํํฌ ... | ||
| 3 ํ๋ณ ... ํ๋ณ ... ํ๋ณ ... ํ๋ณ ... ํ๋ณ | ||
| 4 ... ... ... ... ... ... ... ... ... | ||
| 5 ... ... ... ... ... ... ... ... ... | ||
| 6 ์ด์กธ ... ์ด์กธ ... ์ด์กธ ... ์ด์กธ ... ์ด์กธ | ||
| 7 ... ์ดํฌ ... ... ... ... ... ์ดํฌ ... | ||
| 8 ... ... ... ... ์ด๊ถ ... ... ... ... | ||
| 9 ์ด์ฐจ ์ด๋ง ์ด์ ์ด์ฌ ... ์ด์ฌ ์ด์ ์ด๋ง ์ด์ฐจ | ||
|
|
||
| [์ด(CHO) ์ง์] {์ถ๋ฐ ์ขํ} {๋์ฐฉ ์ขํ} ํ์์ผ๋ก ์ ๋ ฅํด ์๋ฅผ ๋์ธ์. (ex. e6 e5) | ||
| > | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 4๏ธโฃ ์ปค๋ฐ ์ปจ๋ฒค์ | ||
|
|
||
| Following convention : https://gist.github.com/stephenparish/9941e89d80e2bc58a153 | ||
|
|
||
| ```markdown | ||
| # basic structure | ||
| <type>(<scope>): <subject> | ||
| <BLANK LINE> | ||
| <body> | ||
| <BLANK LINE> | ||
| <footer> | ||
|
|
||
| # <type> | ||
| feat (feature) | ||
| fix (bug fix) | ||
| docs (documentation) | ||
| style (formatting, missing semi colons, โฆ) | ||
| refactor | ||
| test (when adding missing tests) | ||
| chore (maintain) | ||
|
|
||
| # <scope> | ||
| console - I/O | ||
| domain - ํต์ฌ ๋ก์ง | ||
| validation - ์ ํจ์ฑ๊ฒ์ฌ | ||
| test - ํ ์คํธ์ฝ๋ ์ถ๊ฐ | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| plugins { | ||
| id 'java' | ||
| id 'jacoco' | ||
| } | ||
|
|
||
| version '1.0-SNAPSHOT' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import io.GameConsole; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| GameConsole gameConsole = new GameConsole(); | ||
| gameConsole.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.game.Turn; | ||
| import domain.movement.Movement; | ||
| import domain.movement.MovementFactory; | ||
| import domain.movement.MovementValidator; | ||
| import domain.movement.Paths; | ||
| import domain.piece.Piece; | ||
| import domain.setup.Arrangements; | ||
| import domain.setup.Coordinate; | ||
| import java.util.Optional; | ||
|
|
||
| public class Board { | ||
| private final Pieces pieces; | ||
|
|
||
| public Board(Pieces pieces) { | ||
| this.pieces = pieces; | ||
| } | ||
|
|
||
| public static Board of(Arrangements arrangements) { | ||
| return new Board(Pieces.of(arrangements)); | ||
| } | ||
|
|
||
| public Board move(Coordinate coordinate, Turn turn) { | ||
| validateMove(coordinate, turn); | ||
| Position from = coordinate.from(); | ||
| Position to = coordinate.to(); | ||
| return new Board(pieces.move(from, to)); | ||
| } | ||
|
|
||
| public Optional<Piece> pieceAt(Position position) { | ||
| return pieces.at(position); | ||
| } | ||
|
|
||
| public boolean isEmpty(Position position) { | ||
| return pieces.at(position).isEmpty(); | ||
| } | ||
|
|
||
| public boolean hasAnyPiece(Position position) { | ||
| return !isEmpty(position); | ||
| } | ||
|
|
||
| public boolean hasFriendOf(Position position, Piece movingPiece) { | ||
| return pieces.at(position) | ||
| .map(movingPiece::isSameTeamAs) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| public boolean hasEnemyOf(Position position, Piece movingPiece) { | ||
| return pieces.at(position) | ||
| .map(targetPiece -> !movingPiece.isSameTeamAs(targetPiece)) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| private void validateMove(Coordinate coordinate, Turn turn) { | ||
| Position from = coordinate.from(); | ||
| Position to = coordinate.to(); | ||
|
|
||
| Piece piece = pieces.at(from) | ||
| .orElseThrow(() -> new IllegalArgumentException("[ERROR] ํด๋น ์ขํ์ ๊ธฐ๋ฌผ์ด ์์ต๋๋ค: " + from)); | ||
|
|
||
| if (!turn.belongsTo(piece)) { | ||
|
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. ์ด๊ณณ์์๋ง ์ด ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋๋ฐ |
||
| throw new IllegalArgumentException("[ERROR] ์ถ๋ฐ ์ขํ์ ๊ธฐ๋ฌผ์ด ์๋ ๊ธฐ๋ฌผ์ ๋๋ค."); | ||
| } | ||
|
|
||
| Movement movement = MovementFactory.create(piece); | ||
| Paths paths = movement.candidatePaths(from); | ||
|
|
||
| MovementValidator validator = new MovementValidator(this); | ||
|
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. ์๋ฐฉํฅ ์์กด์ฑ์ด ์๊ธด๊ฒ ๊ฐ๋ค์? |
||
| if (!validator.isValid(piece, paths, to)) { | ||
| throw new IllegalArgumentException("[ERROR] ์ ํจํ์ง ์์ ์์ง์์ ๋๋ค."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package domain.board; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum Column { | ||
| A, | ||
| B, | ||
| C, | ||
| D, | ||
| E, | ||
| F, | ||
| G, | ||
| H, | ||
| I; | ||
|
|
||
| public boolean canShift(int delta) { | ||
| int next = this.ordinal() + delta; | ||
| return next >= 0 && next < Column.values().length; | ||
|
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. ์์๋ฅผ ์ฌ์ฉํด์ฃผ์ธ์ |
||
| } | ||
|
|
||
| public Column shift(int delta) { | ||
| return Column.values()[this.ordinal() + delta]; | ||
| } | ||
|
|
||
| public static Column toColumn(char character) { | ||
| char upperChar = Character.toUpperCase(character); | ||
|
|
||
| return Arrays.stream(values()) | ||
| .filter(column -> column.name().charAt(0) == upperChar) | ||
| .findAny() | ||
| .orElseThrow(() -> new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅธ ์ด ๊ฐ์ด ์๋๋๋ค.")); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.piece.Piece; | ||
| import domain.setup.Arrangements; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| public class Pieces { | ||
| private final Map<Position, Piece> pieces; | ||
|
|
||
| public Pieces(Map<Position, Piece> pieces) { | ||
|
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. ์ฌ๊ธฐ๋ ๋ฐฉ์ด์ ๋ณต์ฌ๋ฅผ ๊ณ ๋ คํด๋ณด์๋ฉด ์ด๋จ๊น์?
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. ๋ต, ๋ฐฉ์ด์ ๋ณต์ฌ๊ฐ ๋ฐ๋์ ํ์ํ ๊ณณ์ด๋ผ๊ณ ์๊ฐ์ด ๋๋๋ฐ ๋๋ฝ์ด ๋์ด์์๋ค์. |
||
| this.pieces = new HashMap<>(pieces); | ||
| } | ||
|
|
||
| public static Pieces of(Arrangements arrangements) { | ||
| return new Pieces(PositionLayout.build(arrangements)); | ||
| } | ||
|
|
||
| public Pieces move(Position from, Position to) { | ||
| Piece piece = pieces.get(from); | ||
| if (piece == null) { | ||
| throw new IllegalArgumentException("[ERROR] ํด๋น ์์น์ ๊ธฐ๋ฌผ์ด ์์ต๋๋ค: " + from); | ||
| } | ||
| Map<Position, Piece> newMap = new HashMap<>(pieces); | ||
| newMap.remove(from); | ||
| newMap.put(to, piece); | ||
| return new Pieces(newMap); | ||
| } | ||
|
|
||
| public Optional<Piece> at(Position position) { | ||
| return Optional.ofNullable(pieces.get(position)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.movement.Delta; | ||
|
|
||
| public record Position(Column column, Row row) { | ||
| public boolean canShift(Delta delta) { | ||
| return column.canShift(delta.columnDelta().value()) && row.canShift(delta.rowDelta().value()); | ||
| } | ||
|
|
||
| public Position shift(Delta delta) { | ||
| return new Position( | ||
| column.shift(delta.columnDelta().value()), | ||
| row.shift(delta.rowDelta().value()) | ||
| ); | ||
| } | ||
| } |
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.
private ๋ฉ์๋๊ฐ ๊ฝค ํฌ๋ค์.
Board๊ฐ ๊ฐ๊ณ ์๊ธฐ์ ์กฐ๊ธ ๋ฌด๊ฑฐ์ด ์ฑ ์์ด์ง ์๋ ์ถ์ด๋ณด์ฌ์
์ง๋ฌธ์ ๋๋ค. Board์ ์ญํ ๊ณผ ์ฑ ์์ ์ด๋ป๊ฒ / ์ด๋ ๋ฒ์๋ก ์ค๊ณํ์ จ๋์?