-
Notifications
You must be signed in to change notification settings - Fork 13
체스게임 1단계 미션 리뷰 요청드립니다. #12
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: jiwoo-kimm
Are you sure you want to change the base?
Changes from 22 commits
3a12a76
667d30a
05e7c1d
2d33803
cc54492
8bc0bd5
f6c2eb4
22d29d1
c877ccd
adc18b6
f3c877a
12da4ca
44ecf39
4498862
a40508d
c30f242
483c149
c2f0dea
c17c852
5d69a67
be1d67e
aba4a3a
0401fb6
bdb9729
ffec341
8e2830b
778b8d6
cdc9cda
a0a341c
b3770b2
d97f271
cd61bd7
9931625
2026dac
8a8ccbb
ea4b38f
46a6daa
b574593
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 +1,101 @@ | ||
| # java-chess 게임 | ||
|
|
||
| ## 구현해야할 목록 | ||
|
|
||
| - [x] 입력 | ||
| - [x] 명령어 입력 | ||
| - [x] 출력 | ||
| - [x] 시작 안내 문구 출력 | ||
| - [x] 체스판 전체 출력 | ||
| - [x] 점수와 결과 출력 | ||
|
|
||
| - [x] 체스게임(ChessGame) | ||
| - [x] 체스판 | ||
| - [x] 현재 플레이어 | ||
| - [x] 게임 시작&종료 상태 제어 | ||
|
|
||
| - 기능 | ||
| - [x] 명령어 검증 및 처리 | ||
| - [x] start : 게임 실행 | ||
| - [x] end : 게임 종료 | ||
| - [x] move : 인자로 전달받은 source 위치에서 target 위치로 기물 이동 | ||
|
|
||
| - [x] 체스판(Board) | ||
| - [x] 체스판 | ||
| - [x] 생성 시 32개의 기물 초기화 | ||
|
|
||
| - 기능 | ||
| - [x] 인자로 전달받은 위치에 기물이 있는지 확인 | ||
| - [x] ERROR : 존재하지 않을 경우 | ||
| - [x] 같은 색상 기물인지 확인 | ||
| - [x] ERROR : 다른 색상일 경우 | ||
| - [x] 시작과 도착 위치의 기물이 다른 색상인지 확인 | ||
| - [x] ERROR : 같은 색상일 경우 | ||
| - [x] source 위치에서 target 위치로 기물 이동 | ||
| - [x] ERROR : source 위치에 기물이 없는 경우 | ||
| - [x] ERROR : 자신의 기물이 아닌 경우 | ||
| - [x] ERROR : source, target 위치의 기물 색상이 같을 경우 | ||
| - [x] ERROR : source, target 위치가 같을 경우 | ||
| - [x] ERROR : 이동 경로에 기물이 존재할 경우 | ||
|
|
||
| - [x] 기물(Piece) | ||
| - [x] 색상 | ||
|
|
||
| - [x] 기물 위치(Position) | ||
| - [x] 파일 | ||
| - [x] 랭크 | ||
| - [x] 64개의 캐싱된 위치 | ||
|
|
||
| - 기능 | ||
| - [x] 전달받은 인자에 해당하는 위치 객체 반환 | ||
|
|
||
| - [x] 기물 색상(Color) | ||
| - [x] 색상 | ||
|
|
||
| - [x] 기물 이름 매퍼 | ||
| - [x] 기물 종류에 따라 이름을 매핑 | ||
|
|
||
| - [x] 플레이어(Player) | ||
| - [x] 자신의 기물 | ||
| - [x] 자신이 공격 가능한 범위 | ||
|
|
||
| - 기능 | ||
| - [x] 기물을 이동시킨다. | ||
| - [x] 기물의 이동 경로를 반환한다. | ||
| - [x] 입력받은 위치에 기물이 있는지 확인한다. | ||
|
|
||
| ## 이동 규칙 | ||
|
|
||
| - [x] 폰 (1 or 0.5) | ||
| - [x] 적 방향 직선 1칸 이동 | ||
| - [x] ERROR : 직선 방향 2칸 이상일 경우 | ||
| - [x] ERROR : 좌, 우 이동이 포함될 경우 | ||
| - [x] 처음 이동 시에는 2칸 이동 가능 | ||
| - [x] ERROR : 직선 방향 3칸 이상일 경우 | ||
| - [x] ERROR : 좌, 우 이동이 포함될 경우 | ||
|
|
||
| - [x] 공격 : 적 방향 좌, 우 대각선 1칸 | ||
| - [x] ERROR : 직선 1칸 && 좌 또는 우 1칸이 아닐 경우 | ||
|
|
||
| - [x] 룩 (5) | ||
| - [x] 모든 직선 방향으로 원하는 만큼 이동 가능 | ||
| - [x] ERROR : 룩 이동 패턴으로 이동할 수 없는 위치일 경우 | ||
|
|
||
| - [x] 나이트 (2.5) | ||
| - [x] 모든 직선 방향 1칸 + 이동한 직선 방향의 좌, 우 대각선 1칸으로 이동 가능 | ||
| - [x] ERROR : 나이트 이동 패턴으로 이동할 수 없는 위치일 경우 | ||
| - [x] 진행 방향이 가로막혀도 적, 아군 상관없이 뛰어넘을 수 있다. | ||
|
|
||
| - [x] 비숍 (3) | ||
| - [x] 모든 대각선 방향으로 원하는 만큼 이동 가능 | ||
| - [x] ERROR : 비숍 이동 패턴으로 이동할 수 없는 위치일 경우 | ||
|
|
||
| - [x] 퀸 (9) | ||
| - [x] 모든 방향 1칸 + α 이동 (모든 대각선 방향으로는 원하는 만큼 이동 가능) | ||
|
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. 넵 퀸 이동 규칙을 완전히 착각해버렸어요ㅠㅠ 수정했습니다! |
||
| - [x] ERROR : 퀸 이동 패턴으로 이동할 수 없는 위치일 경우 | ||
|
|
||
| - [x] 킹 | ||
| - [x] 모든 방향 1칸 이동 | ||
| - [x] ERROR : 킹 이동 패턴으로 이동할 수 없는 위치일 경우 | ||
| - [x] 상대의 공격 범위로는 이동 불가능 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package chess; | ||
|
|
||
| import chess.controller.ChessController; | ||
| import chess.view.ConsoleInputView; | ||
| import chess.view.ConsoleOutputView; | ||
| import chess.view.InputView; | ||
| import chess.view.OutputView; | ||
|
|
||
| public class ConsoleApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| OutputView outputView = new ConsoleOutputView(); | ||
| InputView inputView = new ConsoleInputView(); | ||
| ChessController chessController = new ChessController(inputView, outputView); | ||
| chessController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package chess.controller; | ||
|
|
||
| import chess.controller.dto.BoardDto; | ||
| import chess.domain.ChessGame; | ||
| import chess.domain.board.Status; | ||
| import chess.domain.command.Command; | ||
| import chess.view.InputView; | ||
| import chess.view.OutputView; | ||
|
|
||
| public class ChessController { | ||
|
|
||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| public ChessController(final InputView inputView, final OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void run() { | ||
| outputView.printGuide(); | ||
| ChessGame chessGame = new ChessGame(); | ||
|
|
||
| while (chessGame.isRunning()) { | ||
| try { | ||
| outputView.printTurn(chessGame.isWhiteTurn()); | ||
| Command command = new Command(inputView.getCommand()); | ||
| runCommand(chessGame, command); | ||
| printBoard(chessGame); | ||
| } catch (UnsupportedOperationException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| printBoard(chessGame); | ||
| printStatus(chessGame); | ||
| } | ||
|
|
||
| private void runCommand(final ChessGame chessGame, final Command command) { | ||
| try { | ||
| if (command.isStart()) { | ||
| return; | ||
| } | ||
|
|
||
| if (command.isEnd()) { | ||
| chessGame.end(); | ||
| return; | ||
| } | ||
|
|
||
| if (command.isMove()) { | ||
| chessGame.move(command.getMoveParameters()); | ||
| return; | ||
| } | ||
|
|
||
| if (command.isStatus()) { | ||
| printStatus(chessGame); | ||
| return; | ||
| } | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return; | ||
| } | ||
|
|
||
| throw new UnsupportedOperationException("유효하지 않은 명령어입니다."); | ||
| } | ||
|
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. controller가 너무 많은 역할을 부담하고 있는건 아닐까요?
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. 넵!
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. 근데 제가 |
||
|
|
||
| private void printBoard(final ChessGame chessGame) { | ||
| BoardDto boardDto = new BoardDto(chessGame.getBoard()); | ||
| outputView.printBoard(boardDto); | ||
| } | ||
|
|
||
| private void printStatus(final ChessGame chessGame) { | ||
| Status status = chessGame.getStatus(); | ||
| outputView.printStatus(status); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package chess.controller.dto; | ||
|
|
||
| import chess.domain.board.Board; | ||
| import chess.domain.board.File; | ||
| import chess.domain.board.Rank; | ||
| import chess.domain.piece.Piece; | ||
| import chess.domain.piece.type.PieceType; | ||
| import chess.domain.player.Position; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class BoardDto { | ||
| private List<PositionDto> positionDtos = new ArrayList<>(); | ||
|
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. positionsDto를 먼저 초기화 하는 �이유가 있을까요?
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. 넵! 생성자에서 불변 리스트를 만들도록 수정했습니다 |
||
|
|
||
| public BoardDto(final Board board) { | ||
|
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. borad라는 도메인 객체와 출력을 위한 dto를 분리하는 좋은 방향을 잡으셨네요 👍 |
||
| Arrays.stream(Rank.values()).forEach(rank -> Arrays.stream( | ||
| File.values()).forEach(file -> addPositionDto(file, rank, board))); | ||
| } | ||
|
|
||
| private void addPositionDto(final File file, final Rank rank, final Board board) { | ||
| Position position = Position.from(file, rank); | ||
|
|
||
| if (board.isEmpty(position)) { | ||
| PositionDto positionDto = new PositionDto(position.getFile()); | ||
| positionDtos.add(positionDto); | ||
| return; | ||
| } | ||
|
|
||
| Piece piece = board.findBy(position); | ||
| String name = PieceType.findNameBy(piece); | ||
| PositionDto positionDto = new PositionDto(position.getFile(), name); | ||
| positionDtos.add(positionDto); | ||
| } | ||
|
|
||
| public List<PositionDto> getPositionDtos() { | ||
| return Collections.unmodifiableList(positionDtos); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package chess.controller.dto; | ||
|
|
||
| import chess.domain.board.File; | ||
|
|
||
| public class PositionDto { | ||
|
|
||
| private static final String DEFAULT_NAME = "."; | ||
|
|
||
| private final boolean isLastFile; | ||
| private final String name; | ||
|
|
||
| public PositionDto(final File file, final String name) { | ||
| this.isLastFile = (file == File.h); | ||
| this.name = name; | ||
| } | ||
|
|
||
| public PositionDto(final File file) { | ||
| this(file, DEFAULT_NAME); | ||
| } | ||
|
|
||
| public boolean isLastFile() { | ||
| return isLastFile; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package chess.domain; | ||
|
|
||
| import chess.domain.board.Board; | ||
| import chess.domain.board.Status; | ||
| import chess.domain.command.MoveParameters; | ||
|
|
||
| public class ChessGame { | ||
|
|
||
| private final Board board = new Board(); | ||
| private boolean isRunning = true; | ||
| private boolean isWhiteTurn = true; | ||
|
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. 조금 더 객체지향적으로 가져가보면 어떨까요? 만약 이 게임이 4인용이 되어서 2:2로 팀전을 하면 어떻게 될까요?
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. 넵! 일단 Color 객체로 표현하도록 하고, |
||
|
|
||
| public ChessGame() { | ||
| } | ||
|
|
||
| public void move(final MoveParameters moveParameters) { | ||
| board.move(moveParameters, isWhiteTurn); | ||
| isWhiteTurn = !isWhiteTurn; | ||
|
|
||
| if (board.isEnd()) { | ||
| isRunning = false; | ||
| } | ||
| } | ||
|
|
||
| public void end() { | ||
| isRunning = false; | ||
| } | ||
|
|
||
| public Status getStatus() { | ||
| return board.getStatus(); | ||
| } | ||
|
|
||
| public boolean isRunning() { | ||
| return isRunning; | ||
| } | ||
|
|
||
| public Board getBoard() { | ||
| return board; | ||
| } | ||
|
|
||
| public boolean isWhiteTurn() { | ||
| return isWhiteTurn; | ||
| } | ||
| } | ||
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.
각 기물 뒤에 나온 숫자가 점수인 것으로 보이는데,
점수 계산에 대한 것도 기능 목록으로 빼면 어떨까요?
해당 코드만 보고 이해하는 사람에게는 어떤 숫자를 의미하는지 알기가 어려울 것 같아요.
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.
넵! Player 기능목록에 점수 계산도 추가했습니다