-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด1 - ๋ฏธ์ (๋ณด๋ ์ด๊ธฐํ + ๊ธฐ๋ฌผ ์ด๋)] ์ฝ์ฝ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #262
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: yejinkimis
Are you sure you want to change the base?
Changes from all commits
2c15f8e
38f7091
eec72c2
4eece5c
8d1d684
488805e
74217a1
1966e66
9775ac1
9832ec2
af8fa6c
e7d1eaf
f3b5bea
4677afa
0de8449
627b906
79e6716
e3b8c05
abe756a
b08d536
c7c986c
8d5d4e8
976e2f4
0b63577
2592641
2351f64
a629d79
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,84 @@ | ||
| # java-janggi | ||
|
|
||
| ์ฅ๊ธฐ ๋ฏธ์ ์ ์ฅ์ | ||
|
|
||
| **์ฃผ์ ๊ธฐ๋ฅ** | ||
|
|
||
| - [x] ํ๋ ์ด์ด๋ โ์ ์ฐจ๋ฆผโ์ ๊ฒฐ์ ํ ์ ์๋ค. | ||
| - [x] ๊ธฐ๋ฌผ์ ์๋์ผ๋ก ๋ฐฐ์น๋๋ค. | ||
| - [x] ํ์ฌ ์ฅ๊ธฐํ์ ํํฉ์ ๋ณผ ์ ์๋ค. | ||
| - [x] ์ด๋๋ผ(์ )/ํ๋๋ผ(ํ) ๋ฒ๊ฐ์๊ฐ๋ฉฐ ํ๋ ์ดํ๋ค. | ||
| - [x] ํ๋ ์ด์ด๋ ๊ธฐ๋ฌผ์ ์ด๋ ๊ท์น์ ๋ฐ๋ผ ์ด๋์ํฌ ์ ์๋ค. | ||
| - [x] ์๋ ํ๋ ์ด์ด์ ๊ธฐ๋ฌผ์ ์ก์ ์ ์๋ค. | ||
| - [ ] ์๋ ํ๋ ์ด์ด์ ์์ ์ก์ผ๋ฉด ์น๋ฆฌํ๊ณ , ๊ฒ์์ ์ข ๋ฃ๋๋ค. | ||
|
|
||
| ### **์คํ ์์** | ||
|
|
||
| ``` | ||
| ์ด๋๋ผ ์ ์ฐจ๋ฆผ์ ๊ฒฐ์ ํด์ฃผ์ธ์. | ||
| 1. [๋ง ์ ๋ง ์] | ||
| 2. [๋ง ์ ์ ๋ง] | ||
| 3. [์ ๋ง ์ ๋ง] | ||
| 4. [์ ๋ง ๋ง ์] | ||
|
|
||
| 2 | ||
|
|
||
| ํ๋๋ผ ์ ์ฐจ๋ฆผ์ ๊ฒฐ์ ํด์ฃผ์ธ์. | ||
| 1. [๋ง ์ ๋ง ์] | ||
| 2. [๋ง ์ ์ ๋ง] | ||
| 3. [์ ๋ง ์ ๋ง] | ||
| 4. [์ ๋ง ๋ง ์] | ||
|
|
||
| 3 | ||
|
|
||
| ๊ธฐ๋ฌผ์ด ๋ฐฐ์น ๋์์ต๋๋ค. | ||
| 0 1 2 3 4 5 6 7 8 | ||
| 0 ่ป ้ฆฌ ่ฑก ๅฃซ ยท ๅฃซ ้ฆฌ ่ฑก ่ป | ||
| 1 ยท ยท ยท ยท ๆผข ยท ยท ยท ยท | ||
| 2 ยท ็ ฒ ยท ยท ยท ยท ยท ็ ฒ ยท | ||
| 3 ๅ ต ยท ๅ ต ยท ๅ ต ยท ๅ ต ยท ๅ ต | ||
| 4 ยท ยท ยท ยท ยท ยท ยท ยท ยท | ||
| 5 ยท ยท ยท ยท ยท ยท ยท ยท ยท | ||
| 6 ๅ ยท ๅ ยท ๅ ยท ๅ ยท ๅ | ||
| 7 ยท ็ฎ ยท ยท ยท ยท ยท ็ฎ ยท | ||
| 8 ยท ยท ยท ยท ๆฅ ยท ยท ยท ยท | ||
| 9 ่ป ้ฆฌ ็ธ ๅฃซ ยท ๅฃซ ็ธ ้ฆฌ ่ป | ||
|
|
||
| ์ด๋๋ผ ํ๋ ์ด์ด๋ ๋ง์ ์ ํํด์ฃผ์ธ์.(์ ๋ ฅ์์ ์ขํ: 0, 9) | ||
| ์ขํ: 0, 9 | ||
|
|
||
| ์ด๋๋ผ ํ๋ ์ด์ด๋ ์ ํํ ๋ง์ ์์ง์ผ ์์น๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์.(์ ๋ ฅ์์ ์ขํ: 0, 7) | ||
| ์ขํ: 0, 7 | ||
|
|
||
| ์ด๋๋์์ต๋๋ค. | ||
| 0 1 2 3 4 5 6 7 8 | ||
| 0 ่ป ้ฆฌ ่ฑก ๅฃซ ยท ๅฃซ ้ฆฌ ่ฑก ่ป | ||
| 1 ยท ยท ยท ยท ๆผข ยท ยท ยท ยท | ||
| 2 ยท ็ ฒ ยท ยท ยท ยท ยท ็ ฒ ยท | ||
| 3 ๅ ต ยท ๅ ต ยท ๅ ต ยท ๅ ต ยท ๅ ต | ||
| 4 ยท ยท ยท ยท ยท ยท ยท ยท ยท | ||
| 5 ยท ยท ยท ยท ยท ยท ยท ยท ยท | ||
| 6 ๅ ยท ๅ ยท ๅ ยท ๅ ยท ๅ | ||
| 7 ่ป ็ฎ ยท ยท ยท ยท ยท ็ฎ ยท | ||
| 8 ยท ยท ยท ยท ๆฅ ยท ยท ยท ยท | ||
| 9 ยท ้ฆฌ ็ธ ๅฃซ ยท ๅฃซ ็ธ ้ฆฌ ่ป | ||
| ``` | ||
|
|
||
| **์ ๋ ฅ** | ||
|
|
||
| - [x] โ์ ์ฐจ๋ฆผโ ๋ฐฐ์น ํ์ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - [x] ์ ํํ ๊ธฐ๋ฌผ์ ์ขํ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - [x] `[ERROR]` ํด๋น ์ขํ์ ๊ธฐ๋ฌผ์ด ์์ ๋ | ||
| - [x] `[ERROR]` ์ ํํ ๊ธฐ๋ฌผ์ด ํ๋ ์ด์ด์ ๊ธฐ๋ฌผ์ด ์๋ ๋ | ||
| - [x] ์ด๋ํ ์ขํ๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. | ||
| - [x] `[ERROR]` ์ด๋ํ ์ขํ๊ฐ ๋ณด๋ ํฌ๊ธฐ ๋ด์ ์ ํจํ์ง ์์ ๋ | ||
| - [x] `[ERROR]` ํด๋น ์ขํ์ ํ๋ ์ด์ด์ ํ ๊ธฐ๋ฌผ์ด ์์ ๋ | ||
| - [x] `[ERROR]` ์ด๋ ๊ท์น์ ๋ฐ๋ผ ์ด๋ํ ์ ์์ ๋ | ||
|
|
||
| **์ถ๋ ฅ** | ||
|
|
||
| - [x] 4 ์ข ๋ฅ์ โ์ ์ฐจ๋ฆผโ ๋ฐฐ์น๋ฅผ ์ถ๋ ฅํ๋ค. | ||
| - [x] ๊ธฐ๋ฌผ์ด ๋ฐฐ์น๋ ๋ณด๋๋ฅผ ์ถ๋ ฅํ๋ค. | ||
| - [x] ํ์ฌ ํด์ ์ถ๋ ฅํ๋ค. | ||
| - [x] ํด์ด ๋๋๊ณ ๊ธฐ๋ฌผ ์ด๋์ด ๋ ๋ณด๋๋ฅผ ์ถ๋ ฅํ๋ค. | ||
| - [ ] ์ต์ข ์นํจ๋ฅผ ์ถ๋ ฅํ๋ค. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
|
|
||
| JanggiController janggiController = new JanggiController(inputView, outputView); | ||
| janggiController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import domain.Board; | ||
| import domain.Camp; | ||
| import domain.ElephantFormation; | ||
| import domain.Position; | ||
| import dto.BoardStatusDto; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class JanggiController { | ||
|
|
||
| InputView inputView; | ||
| OutputView outputView; | ||
|
|
||
|
|
||
| JanggiController(InputView inputView, OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void run() { | ||
| Board board = generateBoard(); | ||
| printBoard(board); | ||
|
|
||
| playJanggi(board); | ||
| } | ||
|
|
||
| private Board generateBoard() { | ||
| Board board = new Board(); | ||
| int choElephantFormation = inputView.askElephantFormation(Camp.CHO); | ||
| int hanElephantFormation = inputView.askElephantFormation(Camp.HAN); | ||
| board.generatePiecesBy(Camp.CHO, mappingElephantFormation(choElephantFormation)); | ||
| board.generatePiecesBy(Camp.HAN, mappingElephantFormation(hanElephantFormation)); | ||
| return board; | ||
| } | ||
|
|
||
| private void playJanggi(Board board) { | ||
| Camp camp = Camp.CHO; | ||
| while (true) { | ||
| try{ | ||
| Position fromPosition = askFromPosition(camp, board); | ||
| Position toPosition = inputView.askToPosition(camp); | ||
| board.move(fromPosition, toPosition); | ||
| } catch (IllegalArgumentException e) { | ||
| outputView.printErrorMessage(e); | ||
| continue; | ||
| } | ||
| printBoard(board); | ||
| camp = turnCamp(camp); | ||
|
|
||
| //Todo: ์ฌ์ดํด2 ์์ด ์กํ๋ฉด, ๊ฒ์์ด ์ข ๋ฃ | ||
| } | ||
| } | ||
|
|
||
| private Camp turnCamp(Camp camp) { | ||
| if (camp.equals(Camp.CHO)) { | ||
| return Camp.HAN; | ||
| } | ||
| return Camp.CHO; | ||
| } | ||
|
|
||
| private Position askFromPosition(Camp camp, Board board) { | ||
| while (true) { | ||
| Position fromPosition = inputView.askFromPosition(camp); | ||
| if (!board.isPieceOfCamp(fromPosition, camp)) { | ||
| outputView.printWrongChoice(); | ||
| continue; | ||
| } | ||
| return fromPosition; | ||
| } | ||
| } | ||
|
|
||
| private void printBoard(Board board) { | ||
| BoardStatusDto boardStatus = board.getBoardStatus(); | ||
| outputView.printBoardStatus(boardStatus); | ||
| } | ||
|
|
||
| private ElephantFormation mappingElephantFormation(int userInput) { | ||
| return ElephantFormation.getFormationType(userInput); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package domain; | ||
|
|
||
| import domain.pieces.Piece; | ||
| import dto.BoardStatusDto; | ||
| import dto.PositionStatusDto; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class Board implements ExistBoard { | ||
|
|
||
| private final Map<Position, Piece> board = new HashMap<>(); | ||
|
|
||
| public void generatePiecesBy(Camp camp, ElephantFormation elephantFormation) { | ||
| PieceGenerator pieceGenerator = new PieceGenerator(); | ||
| Map<Position, Piece> pieces = pieceGenerator.generatePieces(camp, elephantFormation); | ||
|
|
||
| board.putAll(pieces); | ||
| } | ||
|
|
||
| public void locatePiece(Position position, Piece piece) { | ||
| if (!isExist(position)) { | ||
| board.put(position, piece); | ||
| return; | ||
| } | ||
|
|
||
| if (getPieceFrom(position).isSameCamp(piece)) { | ||
| throw new IllegalArgumentException("[ERROR] ๊ฐ์ ํ์ ์ก์ ์ ์์ต๋๋ค!"); | ||
| } | ||
|
|
||
| board.put(position, piece); | ||
| } | ||
|
|
||
| public Piece getPieceFrom(Position position) { | ||
| return board.get(position); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isExist(Position position) { | ||
| return board.containsKey(position); | ||
| } | ||
|
|
||
| public void move(Position fromPosition, Position toPosition) { | ||
| if (fromPosition.equals(toPosition)) { | ||
| throw new IllegalArgumentException("[ERROR] ์ ์๋ฆฌ ์ด๋์ ๋ถ๊ฐ๋ฅํฉ๋๋ค."); | ||
|
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. IllegalArgumentException๋ ์์คํ ์ ์ธ ์์ธ์ ๊ฐ๊น์ต๋๋ค. ๊ฐ๋ฐ์๊ฐ ๋ญ๊ฐ ์ฝ๋ ์์ฑ์ค์ ์๋ชป๋ ์ธ์๋ฅผ ๋ฃ๋๋ค๋ ์์ผ๋ก์. ์ด ๋ถ๋ถ์ด๋ ๋ค๋ฅธ ๋ถ๋ถ๋ค์์๋ IllegalArgumentException๋ณด๋ค๋ ๋น์ง๋์ค ์์ธ๋ผ๋ ๊ฒฝ์ฐ๊ฐ ๋ ํด ๊ฒ ๊ฐ์๋ฐ ๋ฐ๋ก ์ฌ์ฉ์ ํ๋๊ฒ ๋ง์ง ์์๊น์? ๋ ํ๊ฐ์ง ๋จ์ ์ ๋ชจ๋ ์์ธ๋ค์ด ๊ตฌ๋ถ์์ด IllegalArgumentException๋ก ๋์ง๊ธฐ ๋๋ฌธ์ ์์ธ ๋ฉ์ธ์ง๋ฅผ ํ์ธํ์ง ์๋ํ ๊ตฌ๋ถํ๊ธฐ ์ด๋ ต๊ณ ๊ทธ๋ก์ธํ ์ค์๊ฐ ๋ฐ์ํ๊ธฐ ์ฝ์ต๋๋ค! ์ด ๋ถ๋ถ ๊ณ ๋ฏธํด๋ณด์๋ฉด ์ข์๊ฒ ๊ฐ์์! |
||
| } | ||
|
|
||
| Piece piece = board.get(fromPosition); | ||
| boolean canMove = piece.canMove(fromPosition, toPosition, this); | ||
| if (canMove) { | ||
| locatePiece(toPosition, piece); | ||
| board.remove(fromPosition); | ||
| return; | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("[ERROR] ์ด๋ํ ์ ์์ต๋๋ค"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isDifferentPieceType(Position position, Piece piece) { | ||
| if (!board.containsKey(position)) { | ||
| return true; | ||
| } | ||
|
|
||
| return board.get(position).isDifferentPieceType(piece); | ||
| } | ||
|
|
||
| public BoardStatusDto getBoardStatus() { | ||
| List<List<PositionStatusDto>> boardStatusDto = new ArrayList<>(); | ||
| for (int y = Position.MIN_Y_VALUE; y <= Position.MAX_Y_VALUE; y++) { | ||
| List<PositionStatusDto> xPositionStatus = new ArrayList<>(); | ||
| for (int x = Position.MIN_X_VALUE; x <= Position.MAX_X_VALUE; x++) { | ||
| Position position = new Position(x, y); | ||
|
|
||
| PositionStatusDto positionStatusDto = getPositionStatusDto(position); | ||
| xPositionStatus.add(positionStatusDto); | ||
| } | ||
| boardStatusDto.add(xPositionStatus); | ||
| } | ||
| return new BoardStatusDto(boardStatusDto); | ||
| } | ||
|
|
||
| private PositionStatusDto getPositionStatusDto(Position position) { | ||
| if (!board.containsKey(position)) { | ||
| return new PositionStatusDto(position, PieceType.NONE, Camp.CHO); | ||
| } | ||
|
|
||
| Piece piece = board.get(position); | ||
| PieceType pieceType = piece.getPieceType(); | ||
| Camp camp = piece.getCamp(); | ||
| return new PositionStatusDto(position, pieceType, camp); | ||
| } | ||
|
|
||
| public boolean isPieceOfCamp(Position position, Camp camp) { | ||
| if (!board.containsKey(position)) { | ||
| return false; | ||
| } | ||
|
|
||
| return board.get(position).isSameCamp(camp); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package domain; | ||
|
|
||
| public enum Camp { | ||
| HAN("ํ๋๋ผ"), | ||
| CHO("์ด๋๋ผ"); | ||
|
Comment on lines
+4
to
+5
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. ๋๋ฉ์ธ enum์ view ๊ด๋ จ ๋ก์ง์ด ๋ค์ด๊ฐ๋ ๊ด์ฐฎ์๊น์? ํ๋ฌธ์ผ๋ก ํ๊ธฐํ๋ค๊ฑฐ๋ ์์ด๋ก ํ๊ธฐํ๋ค ๋ฑ์ ์๊ตฌ์ฌํญ์ด ์๊ธฐ๋ฉด ์ด๋ป๊ฒ ๋ ๊น์? |
||
|
|
||
| private final String campName; | ||
|
|
||
| Camp(String campName) { | ||
| this.campName = campName; | ||
| } | ||
|
|
||
| public String getCampName() { | ||
| return campName; | ||
| } | ||
| } | ||
|
|
||
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.
from์ ์ป์ ๋๋ board๋ฅผ ํตํด์ ๊ฒ์ฆํ๋ ๊ฒ ๊ฐ์๋ฐ, to๋ฅผ ๊ตฌํ ๋๋ ๊ทธ๋ฅ inputView์๊ฒ ์ง์ ๋ฌผ์ด๋ณด๋ค์? ํต์ผ์ฑ์ ์ฃผ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์๋ฐ, to position์ ๊ธฐ๋ฌผ์ด ์๋์ง ์๋์ง ๋ฑ์ ๋ฌผ์ด๋ณด๋ ๋ฐฉ์์ ์ฌ๊ธฐ์ ์ถ๊ฐํ ์ ์์ง ์์๊น์? ๋ฆฌํธ๋ผ์ด๋ ์ถ๊ฐํด์์
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.
move ๋ด๋ถ์ ์๋ ๊ฒ์ฆ ๋ก์ง์ ๋ฐ์ผ๋ก ๋นผ๋ ์๊ธฐ๋ ์๋๋๋ค. Move ์์ฒด์ ์ธ ๊ฒ์ฆ ๋ก์ง์ ๊ทธ๋๋ก ๋๋ from๊ณผ to๋ฅผ ์ป์ด์ค๋ ๋ฐฉ์์ ํต์ผ์ฑ์ ์ฃผ๋ฉด ์ข๊ฒ ๋ค๋ ์๊ธฐ์์ต๋๋ค.