-
Notifications
You must be signed in to change notification settings - Fork 79
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
[1단계 - 보드 초기화, 기물 이동] 윌슨(박형균) 미션 제출합니다. #40
Changes from all commits
5b26e65
46d3565
392eec0
39e1459
dc4aec8
6448dd8
56f7a91
733bc05
873e99d
cedbe32
0201a24
865d9b9
94ba1f2
4726799
bbca0a9
e014055
ef5e7f0
a617810
49fa706
d1de6cb
643db30
adce400
8ea0b2c
471d4e8
b20ae07
5714adc
446c45e
72068ac
58dcbb5
4c1aa67
6c9db55
a09a943
81e9984
a224ab3
da3198e
09c9fcc
b517669
543ffde
1a6750a
aa0fa69
e87ffc4
1564053
57c867e
6999184
5c77bda
7c03318
8971b00
689cc58
5e2170c
77ed67d
47995de
f2e53e7
95820bc
bc1d1dc
0a03292
8dd4cef
a2f2781
47ee3cd
42e19ff
fb988b8
b15c53e
a1fef29
1e5d703
23545b0
67bdd69
5ee128b
60fd543
a121444
53e9e5c
6e85953
48373a0
7fdc907
cf74248
8fcd07d
6d7a389
e8b8b08
5657669
728790d
dac11aa
4348045
9922508
d4e8d98
388ea70
d4cfb5d
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,51 @@ | ||||||||||||||||||||||||||||||
# java-janggi | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
장기 미션 저장소 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
## 미션을 수행하며 반드시 고민할 것 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### ✅ 장기의 말(駒)들은 어떻게 객체로 나누어야 하는가? | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
장기가 이동할 수 있는 경로를 정의한 인터페이스를 각 기물 종류마다 구현한다. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### ✅ 각 말의 이동 규칙을 어떻게 설계할 것인가? | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Enum으로 상,하,좌,우,대각선 4방향을 정의하고, 각 기물이 해당 Enum을 이용해서 이동 규칙을 구현한다. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Comment on lines
+11
to
+14
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. 🧹 Nitpick (assertive) 기물 이동 규칙의 확장 가능성도 고민해보세요. Enum을 이용해서 4방향·대각선을 정의해두셨지만, 각 기물마다 특수 이동 규칙(포의 뛰어넘기, 마/상 이동 등)을 어떻게 Enum과 함께 처리할지 문서에서도 추가로 언급해주시면 이해도가 더 높아질 것 같습니다. |
||||||||||||||||||||||||||||||
### ✅ 객체 간의 책임을 어떻게 나눌 것인가? | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
- 객체가 주체성을 갖고 행동하는가? (_'객체의 결합도가 낮고 응집도가 높은가?'_) | ||||||||||||||||||||||||||||||
- 객체안의 메서드들을 테스트할 수 있는지 판단 (_'메서드가 public으로 유지 될 수 있는가?'_) | ||||||||||||||||||||||||||||||
- 객체안의 메서드들이 필드 멤버를 온전히 사용하고 있는지 확인 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### ✅ 어떤 원칙을 적용해야 더 좋은 설계를 할 수 있을까? | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
#### TDD 사이클이 한번 끝날때 마다 아래 항목들을 검사한다. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
- 각 객체의 책임이 적절히 할당이 되었는가? | ||||||||||||||||||||||||||||||
- 메서드 시그니처가 자연스러운가? | ||||||||||||||||||||||||||||||
- getter의 사용이 적절한가? (_'진짜 여기서 getter를 써야만할까?'_) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Comment on lines
+21
to
+28
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. 🧹 Nitpick (assertive) 헤딩의 마침표를 제거해 마크다운 린트 에러를 피하세요. 현재 "#### TDD 사이클이 한번 끝날때 마다 아래 항목들을 검사한다." 헤딩 끝에 마침표가 있어 lint 에러(MD026)가 발생합니다. 아래와 같이 수정해 보시는 걸 권장드립니다. -#### TDD 사이클이 한번 끝날때 마다 아래 항목들을 검사한다.
+#### TDD 사이클이 한번 끝날때 마다 아래 항목들을 검사한다 📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.17.2)23-23: Trailing punctuation in heading (MD026, no-trailing-punctuation) |
||||||||||||||||||||||||||||||
## 기능 구현 목록 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### 보드 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
- [ ] 특정 위치에서 이동 가능한 위치 리스트를 반환한다 | ||||||||||||||||||||||||||||||
- [ ] 점수를 계산 한다 | ||||||||||||||||||||||||||||||
- [ ] 예외 처리 | ||||||||||||||||||||||||||||||
- [ ] 해당 위치에 기물이 없으면 예외 | ||||||||||||||||||||||||||||||
Comment on lines
+31
to
+36
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. 보드판은 구현이 아직 안된걸까요? 👀 |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### 기물들의 위치 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
- [x] 기물들의 위치를 초기화 한다 | ||||||||||||||||||||||||||||||
- [x] 특정 위치에 어떤 기물이 있는지 반환한다 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Comment on lines
+38
to
+42
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. 🧹 Nitpick (assertive) 초기화 로직 문서에 에러 처리나 중복 초기화 방안도 덧붙이면 좋겠습니다. 현재 기물 위치 초기화를 수행하는 항목이 있지만, 똑같은 위치나 이미 배치된 위치 등을 다시 초기화할 때의 처리 방안도 함께 기술하시면 유지보수나 협업 시 혼동이 줄어듭니다. |
||||||||||||||||||||||||||||||
### 기물 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
- [x] 이동 가능한 위치를 리스트로 반환 | ||||||||||||||||||||||||||||||
- [x] 포 (`Cannon`) | ||||||||||||||||||||||||||||||
- [x] 차 (`Chariot`) | ||||||||||||||||||||||||||||||
- [x] 상 (`Elephant`) | ||||||||||||||||||||||||||||||
- [x] 졸/병 (`Guard`) | ||||||||||||||||||||||||||||||
- [x] 마 (`Horse`) | ||||||||||||||||||||||||||||||
- [x] 대상 기물을 먹을 수 있는지 판단 | ||||||||||||||||||||||||||||||
Comment on lines
+43
to
+51
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. 🧹 Nitpick (assertive) 기물별 이동·공격 규칙을 더욱 구체적으로 문서화해 보세요. 각 기물의 이동 가능 경로, 공격 방식 등을 문서에서 조금 더 구체적으로 다루면 새로 참여하는 개발자들도 로직을 빠르게 이해할 수 있을 듯합니다. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||||||||
import game.JanggiGame; | ||||||||||||||||||||||||||||||||||||||||||||
import view.InputView; | ||||||||||||||||||||||||||||||||||||||||||||
import view.OutputView; | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
public class Application { | ||||||||||||||||||||||||||||||||||||||||||||
public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||||||||||||
JanggiGame janggiGame = new JanggiGame( | ||||||||||||||||||||||||||||||||||||||||||||
new InputView(), | ||||||||||||||||||||||||||||||||||||||||||||
new OutputView() | ||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||
janggiGame.run(); | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+5
to
+12
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. 🧹 Nitpick (assertive) 애플리케이션 진입점이 잘 구성되어 있습니다. JanggiGame 인스턴스를 생성하고 필요한 뷰 컴포넌트를 주입하는 구조가 적절합니다. 의존성 주입 패턴이 잘 적용되어 있습니다. 다음 개선사항을 고려해보세요:
public static void main(String[] args) {
+ try {
JanggiGame janggiGame = new JanggiGame(
new InputView(),
new OutputView()
);
janggiGame.run();
+ } catch (Exception e) {
+ System.err.println("게임 실행 중 오류가 발생했습니다: " + e.getMessage());
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||||||||||||||||||||||||||||||||
package domain; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
import domain.chessPiece.ChessPiece; | ||||||||||||||||||||||||||||||||||||
import domain.hurdlePolicy.HurdlePolicy; | ||||||||||||||||||||||||||||||||||||
import domain.path.Path; | ||||||||||||||||||||||||||||||||||||
import domain.position.ChessPiecePositions; | ||||||||||||||||||||||||||||||||||||
import domain.position.ChessPosition; | ||||||||||||||||||||||||||||||||||||
import domain.score.Score; | ||||||||||||||||||||||||||||||||||||
import domain.type.ChessTeam; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
import java.util.EnumMap; | ||||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||||
import java.util.Map; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public class Board { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private final ChessPiecePositions chessPiecePositions; | ||||||||||||||||||||||||||||||||||||
private final Map<ChessTeam, Score> scores = new EnumMap<>(ChessTeam.class); | ||||||||||||||||||||||||||||||||||||
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. 따로 Score를 두신 이유가 있을까요? 🤔 (물론 지금도 요구사항에는 만족하지만) |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public Board(final ChessPiecePositions chessPiecePositions) { | ||||||||||||||||||||||||||||||||||||
this.chessPiecePositions = chessPiecePositions; | ||||||||||||||||||||||||||||||||||||
scores.putAll(Map.of( | ||||||||||||||||||||||||||||||||||||
ChessTeam.RED, Score.zero(), | ||||||||||||||||||||||||||||||||||||
ChessTeam.BLUE, Score.zero() | ||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+25
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. 아래와 같이 생성자를 통해 scores 필드를 바로 초기화해볼 수도 있을 것 같아요.
Suggested change
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public boolean isExistPieceAt(ChessPosition position) { | ||||||||||||||||||||||||||||||||||||
return chessPiecePositions.existChessPieceByPosition(position); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public void move(final ChessTeam currentTeam, final ChessPosition from, final ChessPosition to) { | ||||||||||||||||||||||||||||||||||||
validateTeam(currentTeam, from); | ||||||||||||||||||||||||||||||||||||
validateDestination(from, to); | ||||||||||||||||||||||||||||||||||||
if (chessPiecePositions.existChessPieceByPosition(to)) { | ||||||||||||||||||||||||||||||||||||
killTarget(currentTeam, to); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
chessPiecePositions.move(from, to); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public List<ChessPosition> getAvailableDestination(final ChessPosition position) { | ||||||||||||||||||||||||||||||||||||
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. 가능한 getter나 setter의 느낌이나는 메서드보다는 행위를 잘 표현해주는 네이밍을 고민해보시면 좋을 것 같아요. |
||||||||||||||||||||||||||||||||||||
ChessPiece chessPiece = chessPiecePositions.getChessPieceByPosition(position); | ||||||||||||||||||||||||||||||||||||
final List<Path> coordinatePaths = chessPiece.getCoordinatePaths(position); | ||||||||||||||||||||||||||||||||||||
final HurdlePolicy hurdlePolicy = chessPiece.getHurdlePolicy(); | ||||||||||||||||||||||||||||||||||||
return hurdlePolicy.pickDestinations(chessPiece.getTeam(), coordinatePaths, chessPiecePositions); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+43
to
+45
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. hurdlePolicy를 두는 것은 괜찮은 시도인 것 같아요. 😃 그렇다면 chessPiece 객체에게 메시지를 보내서 chessPiece보고 수행해달라고 변경해볼 수 있을 것 같고
Suggested change
저는 말씀하신 순환참조 문제를 해결하려면 Board 객체가 이동가능한 목적지를 직접 계산해주는 것도 괜찮을 것 같다고 생각해요. 🤔 |
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public void validateTeam(final ChessTeam currentTeam, final ChessPosition from) { | ||||||||||||||||||||||||||||||||||||
ChessPiece chessPiece = chessPiecePositions.getChessPieceByPosition(from); | ||||||||||||||||||||||||||||||||||||
if (currentTeam != chessPiece.getTeam()) { | ||||||||||||||||||||||||||||||||||||
throw new IllegalArgumentException("상대편의 기물을 움직일 수 없습니다."); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private void killTarget(ChessTeam currentTeam, ChessPosition to) { | ||||||||||||||||||||||||||||||||||||
ChessPiece target = chessPiecePositions.getChessPieceByPosition(to); | ||||||||||||||||||||||||||||||||||||
updateScore(currentTeam, target); | ||||||||||||||||||||||||||||||||||||
chessPiecePositions.removeChessPieceByPosition(to); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private void updateScore(ChessTeam currentTeam, ChessPiece target) { | ||||||||||||||||||||||||||||||||||||
Score score = target.getScore(); | ||||||||||||||||||||||||||||||||||||
Score updatedScore = scores.get(currentTeam).add(score); | ||||||||||||||||||||||||||||||||||||
scores.put(currentTeam, updatedScore); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private void validateDestination(final ChessPosition from, final ChessPosition to) { | ||||||||||||||||||||||||||||||||||||
List<ChessPosition> destinations = getAvailableDestination(from); | ||||||||||||||||||||||||||||||||||||
if (!destinations.contains(to)) { | ||||||||||||||||||||||||||||||||||||
throw new IllegalArgumentException("이동할 수 없는 경로입니다."); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public Map<ChessPosition, ChessPiece> getPositions() { | ||||||||||||||||||||||||||||||||||||
return chessPiecePositions.getChessPieces(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.direction.Direction; | ||
import domain.hurdlePolicy.CannonHurdlePolicy; | ||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.position.ChessPosition; | ||
import domain.type.ChessPieceType; | ||
import domain.type.ChessTeam; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Cannon extends UnlimitedMoveChessPiece { | ||
private static final List<Direction> directions = List.of( | ||
Direction.UP, | ||
Direction.DOWN, | ||
Direction.LEFT, | ||
Direction.RIGHT | ||
); | ||
private final HurdlePolicy hurdlePolicy = new CannonHurdlePolicy(); | ||
|
||
public Cannon(final ChessTeam team) { | ||
super(team, directions); | ||
} | ||
|
||
public static Map<ChessPosition, ChessPiece> initPieces() { | ||
return Map.of( | ||
new ChessPosition(2, 1), new Cannon(ChessTeam.RED), | ||
new ChessPosition(2, 7), new Cannon(ChessTeam.RED), | ||
new ChessPosition(7, 1), new Cannon(ChessTeam.BLUE), | ||
new ChessPosition(7, 7), new Cannon(ChessTeam.BLUE) | ||
); | ||
} | ||
|
||
@Override | ||
public HurdlePolicy getHurdlePolicy() { | ||
return hurdlePolicy; | ||
} | ||
|
||
@Override | ||
public ChessPieceType getChessPieceType() { | ||
return ChessPieceType.CANNON; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.direction.Direction; | ||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.hurdlePolicy.StopAtHurdlePolicy; | ||
import domain.position.ChessPosition; | ||
import domain.type.ChessPieceType; | ||
import domain.type.ChessTeam; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Chariot extends UnlimitedMoveChessPiece { | ||
|
||
private static final List<Direction> directions = List.of( | ||
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.
|
||
Direction.UP, | ||
Direction.DOWN, | ||
Direction.LEFT, | ||
Direction.RIGHT | ||
); | ||
private final HurdlePolicy hurdlePolicy = new StopAtHurdlePolicy(); | ||
|
||
public Chariot(final ChessTeam team) { | ||
super(team, directions); | ||
} | ||
|
||
public static Map<ChessPosition, ChessPiece> initPieces() { | ||
return Map.of( | ||
new ChessPosition(0, 0), new Chariot(ChessTeam.RED), | ||
new ChessPosition(0, 8), new Chariot(ChessTeam.RED), | ||
new ChessPosition(9, 0), new Chariot(ChessTeam.BLUE), | ||
new ChessPosition(9, 8), new Chariot(ChessTeam.BLUE) | ||
); | ||
} | ||
|
||
@Override | ||
public HurdlePolicy getHurdlePolicy() { | ||
return hurdlePolicy; | ||
} | ||
|
||
@Override | ||
public ChessPieceType getChessPieceType() { | ||
return ChessPieceType.CHARIOT; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.path.Path; | ||
import domain.position.ChessPiecePositions; | ||
import domain.score.Score; | ||
import domain.type.ChessPieceType; | ||
import domain.position.ChessPosition; | ||
import domain.type.ChessTeam; | ||
|
||
import java.util.List; | ||
|
||
public interface ChessPiece { | ||
List<ChessPosition> getDestinations(ChessPosition startPosition, ChessPiecePositions positions); | ||
ChessPieceType getChessPieceType(); | ||
ChessTeam getTeam(); | ||
Score getScore(); | ||
List<Path> getCoordinatePaths(final ChessPosition startPosition); | ||
HurdlePolicy getHurdlePolicy(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.direction.Direction; | ||
import domain.direction.Directions; | ||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.hurdlePolicy.UnpassableHurdlePolicy; | ||
import domain.position.ChessPosition; | ||
import domain.type.ChessPieceType; | ||
import domain.type.ChessTeam; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Elephant extends LimitedMoveChessPiece { | ||
private static final List<Directions> directions = List.of( | ||
new Directions(List.of(Direction.UP, Direction.RIGHT_UP, Direction.RIGHT_UP)), | ||
new Directions(List.of(Direction.UP, Direction.LEFT_UP, Direction.LEFT_UP)), | ||
new Directions(List.of(Direction.LEFT, Direction.LEFT_UP, Direction.LEFT_UP)), | ||
new Directions(List.of(Direction.LEFT, Direction.LEFT_DOWN, Direction.LEFT_DOWN)), | ||
new Directions(List.of(Direction.RIGHT, Direction.RIGHT_UP, Direction.RIGHT_UP)), | ||
new Directions(List.of(Direction.RIGHT, Direction.RIGHT_DOWN, Direction.RIGHT_DOWN)), | ||
new Directions(List.of(Direction.DOWN, Direction.LEFT_DOWN, Direction.LEFT_DOWN)), | ||
new Directions(List.of(Direction.DOWN, Direction.RIGHT_DOWN, Direction.RIGHT_DOWN)) | ||
); | ||
private final HurdlePolicy hurdlePolicy = new UnpassableHurdlePolicy(); | ||
|
||
public Elephant(final ChessTeam team) { | ||
super(team, directions); | ||
} | ||
|
||
public static Map<ChessPosition, ChessPiece> initPieces() { | ||
return Map.of( | ||
new ChessPosition(0, 2), new Elephant(ChessTeam.RED), | ||
new ChessPosition(0, 6), new Elephant(ChessTeam.RED), | ||
new ChessPosition(9, 2), new Elephant(ChessTeam.BLUE), | ||
new ChessPosition(9, 6), new Elephant(ChessTeam.BLUE) | ||
); | ||
} | ||
|
||
@Override | ||
public HurdlePolicy getHurdlePolicy() { | ||
return hurdlePolicy; | ||
} | ||
|
||
@Override | ||
public ChessPieceType getChessPieceType() { | ||
return ChessPieceType.ELEPHANT; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.direction.Direction; | ||
import domain.direction.Directions; | ||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.hurdlePolicy.UnpassableHurdlePolicy; | ||
import domain.position.ChessPosition; | ||
import domain.type.ChessPieceType; | ||
import domain.type.ChessTeam; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Horse extends LimitedMoveChessPiece { | ||
private static final List<Directions> directions = List.of( | ||
new Directions(List.of(Direction.UP, Direction.RIGHT_UP)), | ||
new Directions(List.of(Direction.UP, Direction.LEFT_UP)), | ||
new Directions(List.of(Direction.LEFT, Direction.LEFT_UP)), | ||
new Directions(List.of(Direction.LEFT, Direction.LEFT_DOWN)), | ||
new Directions(List.of(Direction.RIGHT, Direction.RIGHT_UP)), | ||
new Directions(List.of(Direction.RIGHT, Direction.RIGHT_DOWN)), | ||
new Directions(List.of(Direction.DOWN, Direction.LEFT_DOWN)), | ||
new Directions(List.of(Direction.DOWN, Direction.RIGHT_DOWN)) | ||
); | ||
private final HurdlePolicy hurdlePolicy = new UnpassableHurdlePolicy(); | ||
|
||
public Horse(final ChessTeam team) { | ||
super(team, directions); | ||
} | ||
|
||
public static Map<ChessPosition, ChessPiece> initPieces() { | ||
return Map.of( | ||
new ChessPosition(0, 1), new Horse(ChessTeam.RED), | ||
new ChessPosition(0, 7), new Horse(ChessTeam.RED), | ||
new ChessPosition(9, 1), new Horse(ChessTeam.BLUE), | ||
new ChessPosition(9, 7), new Horse(ChessTeam.BLUE) | ||
); | ||
} | ||
|
||
@Override | ||
public HurdlePolicy getHurdlePolicy() { | ||
return hurdlePolicy; | ||
} | ||
|
||
@Override | ||
public ChessPieceType getChessPieceType() { | ||
return ChessPieceType.HORSE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package domain.chessPiece; | ||
|
||
import domain.hurdlePolicy.HurdlePolicy; | ||
import domain.position.ChessPiecePositions; | ||
import domain.position.ChessPosition; | ||
import domain.score.Score; | ||
import domain.type.ChessTeam; | ||
import domain.path.Path; | ||
|
||
import java.util.List; | ||
|
||
public abstract class JanggiChessPiece implements ChessPiece { | ||
|
||
private final ChessTeam team; | ||
|
||
protected JanggiChessPiece(ChessTeam team) { | ||
this.team = team; | ||
} | ||
|
||
@Override | ||
public final List<ChessPosition> getDestinations(ChessPosition startPosition, ChessPiecePositions positions) { | ||
List<Path> coordinates = getCoordinatePaths(startPosition); | ||
HurdlePolicy hurdlePolicy = getHurdlePolicy(); | ||
return hurdlePolicy.pickDestinations(team, coordinates, positions); | ||
} | ||
|
||
|
||
@Override | ||
public abstract List<Path> getCoordinatePaths(ChessPosition startPosition); | ||
|
||
@Override | ||
public abstract HurdlePolicy getHurdlePolicy(); | ||
|
||
@Override | ||
public final ChessTeam getTeam() { | ||
return team; | ||
} | ||
|
||
@Override | ||
public final Score getScore() { | ||
return getChessPieceType().score; | ||
} | ||
} |
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.
프롤로그 작성이 누락된 것 같아요. 🥲
아무래도 첫 리뷰 요청 마감 기간이 있다보니 시간이 조금 빠듯하셔서 프롤로그까지 작성하시기가 어려우셨을 것 같아요.
다음 리뷰 요청 전에는 프롤로그 작성도 같이 부탁드릴게요. 🙏😉