Skip to content

체스게임 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

Open
wants to merge 38 commits into
base: jiwoo-kimm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3a12a76
feat: 피스 생성 테스트 및 구현
seongbeenkim Aug 16, 2021
667d30a
feat: 피스 위치 캐싱 테스트 및 구현
seongbeenkim Aug 16, 2021
05e7c1d
feat: 체스판 32개의 피스 초기화, 생성 테스트 및 구현
seongbeenkim Aug 16, 2021
2d33803
feat: 기물 종류에 따라 이름을 매핑하는 기물 이름 매퍼 테스트 및 구현
seongbeenkim Aug 17, 2021
cc54492
feat: 체스판 전체 출력하는 기능 구현
seongbeenkim Aug 17, 2021
8bc0bd5
feat: 체스 게임 시작&종료 명령어 입력 테스트 및 구현
seongbeenkim Aug 17, 2021
f6c2eb4
feat: 기물 이동 시 공통 예외 케이스 테스트 및 구현
seongbeenkim Aug 17, 2021
22d29d1
feat: 비숍 이동 규칙 테스트 및 구현
seongbeenkim Aug 17, 2021
c877ccd
feat: 룩 이동 규칙 테스트 및 구현
seongbeenkim Aug 17, 2021
adc18b6
feat: 퀸 이동 규칙 테스트 및 구현
seongbeenkim Aug 17, 2021
f3c877a
feat: 킹 이동 규칙 테스트 및 구현
seongbeenkim Aug 17, 2021
12da4ca
feat: 나이트 이동 규칙 테스트 및 구현
seongbeenkim Aug 17, 2021
44ecf39
feat: 폰 이동 규칙 테스트 및 구현
seongbeenkim Aug 19, 2021
4498862
feat: 체스판에서 피스 이동 테스트 및 구현
seongbeenkim Aug 19, 2021
a40508d
refactor: 피스 색상별 체스판 분리
seongbeenkim Aug 19, 2021
c30f242
feat: 비숍, 룩 공격 가능한 경로 반환하는 테스트 및 기능 구현
seongbeenkim Aug 19, 2021
483c149
feat: 폰 제외한 기물 패턴 테스트 및 기능 구현
seongbeenkim Aug 20, 2021
c2f0dea
feat: 기물 이동 시 공격 가능 위치를 갱신하는 테스트 및 기능 구현
seongbeenkim Aug 20, 2021
c17c852
feat: 킹 이동제한조건 테스트 및 기능 구현, 예외 처리 및 게임 흐름 제어
jiwoo-kimm Aug 20, 2021
5d69a67
feat: 점수 계산 기능 테스트 및 구현
seongbeenkim Aug 20, 2021
be1d67e
feat: 점수 및 게임 결과 출력 기능 구현
jiwoo-kimm Aug 20, 2021
aba4a3a
refactor: 패키지 구조 및 테스트 케이스 정리
jiwoo-kimm Aug 20, 2021
0401fb6
feat: 웹 체스 MVC 구조 및 초기화면 세팅
jiwoo-kimm Aug 29, 2021
bdb9729
feat: 기물 이동, 현재 점수, 안내 메시지 출력 구현
jiwoo-kimm Aug 30, 2021
ffec341
feat: 게임 종료, 결과 출력 기능 구현
jiwoo-kimm Aug 31, 2021
8e2830b
refactor: ChessGame 도메인 삭제, ChessService로 통합
jiwoo-kimm Aug 31, 2021
778b8d6
refactor: ChessService의 isGameFinished flag 제거, Status의 isKingDead fl…
jiwoo-kimm Aug 31, 2021
cdc9cda
fix: 퀸 이동 패턴 수정
jiwoo-kimm Sep 3, 2021
a0a341c
refactor: ChessGame 도메인 삭제, ChessService로 통합, 게임종료플래그
jiwoo-kimm Sep 3, 2021
b3770b2
refactor: Controller 역할을 Service, Command, Operation으로 분리
jiwoo-kimm Sep 3, 2021
d97f271
refactor: Board 가독성 개선, 메서드 길이 제한 확인
jiwoo-kimm Sep 3, 2021
cd61bd7
refactor: 기물 이동 리팩토링
jiwoo-kimm Sep 5, 2021
9931625
test: 공격 경로 탐색 테스트 수정
jiwoo-kimm Sep 5, 2021
2026dac
refactor: Player -> Team 으로 명칭 변경
jiwoo-kimm Sep 15, 2021
8a8ccbb
refactor: Team 정적 팩토리 생성자 도입
jiwoo-kimm Sep 15, 2021
ea4b38f
refactor: Board → ChessGame 으로 명칭 변경
jiwoo-kimm Sep 15, 2021
46a6daa
refactor: 기물 이동 메서드 이름 수정
jiwoo-kimm Sep 15, 2021
b574593
refactor: 플레이어의 플레이 순서 관리 추가
jiwoo-kimm Sep 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,127 @@
# java-chess 게임

## 구현해야할 목록

### 입력

- [x] 명령어 입력
- [x] 예외: `null` 입력

### 출력

- [x] 시작 안내 문구 출력
- [x] 체스판 스냅샷 출력
- [x] 차례 출력
- [x] 점수 출력
- [x] 승자 출력

### 서비스

#### `ChessService`

- [x] `Command`에 따라 기능 수행
- [x] 게임 현재 상황 DTO

### 도메인

#### `Operation`

- [x] 명령어 검증
- [x] start: 게임 실행
- [x] status: 팀별 점수
- [x] move: 기물 이동
- [x] end: 강제 종료

#### `Board`

- [x] 기물 이동
- [x] 예외
- [x] 움직일 기물이 자신 팀 소유가 아닌 경우
- [x] `source`와 `target`이 같은 위치인 경우
- [x] 본인의 기물을 공격하는 경우
- [x] 이동 경로가 다른 기물에 가로막힌 경우
- [x] `King`: `target`이 적이 공격 가능한 위치인 경우
- [x] `Pawn`: `target`에 적이 없는데 대각선으로 이동하는 경우
- [x] 자신의 기물 이동
- [x] 공격인 경우 적 기물 제거
- [x] 차례 변경
- [x] 현재 차례 관리
- [x] 위치 정보
- [x] 특정 위치가 비었는지 확인
- [x] 특정 위치에 있는 기물 확인
- [x] 각 팀 점수 계산
- [x] 승자 확인
- [x] 예외: 두 `King`이 모두 살아 있는 경우

#### `Team`

- [x] 기물 이동
- [x] 기물 이동 경로 검색
- [x] 현위치에서 공격 가능한 모든 경로 검색
- [x] 적에게 공격받은 경우 기물 제거
- [x] 기물 검색
- [x] 점수 계산

#### `Piece`

- [x] 이동 경로 검색
- [x] 현위치에서 공격 가능한 모든 경로 검색
- [x] 색상 확인
- [x] 타입 확인
- [x] `Pawn`
- [x] `King`

#### `MovePattern`

- [x] 각 기물 타입에 맞는 패턴 검색
- [x] `Pawn`은 색상에 맞는 패턴 검색
- [x] 본인 패턴 중 `gap`에 맞는 `MoveUnit` 검색
- [x] 본인 패턴으로 공격 가능한 모든 경로 검색

#### `MoveLimit`

- [x] 한 칸만 이동 가능한지 확인

#### `MoveUnits`

- [x] 본인 리스트에서 매칭되는 `MoveUnit` 검색
- [x] 예외: 매칭되는 `MoveUnit`이 없는 경우
- [x] 이동 단위 별로 이동 가능한 모든 경로 검색

#### `MoveUnit`

- [x] `MoveUnit`의 좌표가 `gap`에 매칭되는지 확인

#### `Position`

- [x] 64개 위치 캐싱 및 검색
- [x] `Gap` 계산
- [x] 이동 단위로 타겟까지 이동할 때 지나가는 모든 위치 검색
- [x] 이동 단위로 이동 가능한 체스판의 모든 위치 검색
- [x] 이동 단위로 한 번 더 이동 가능한지 확인
- [x] 이동 단위로 이동

## 이동 규칙
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 기물 뒤에 나온 숫자가 점수인 것으로 보이는데,
점수 계산에 대한 것도 기능 목록으로 빼면 어떨까요?
해당 코드만 보고 이해하는 사람에게는 어떤 숫자를 의미하는지 알기가 어려울 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! Player 기능목록에 점수 계산도 추가했습니다


- [x] 폰 (1 or 0.5)
- [x] 적 방향 직선 1칸 이동
- [x] 처음 이동 시에는 2칸 이동 가능
- [x] 공격 시에는 적 방향 좌, 우 대각선 1칸 이동

- [x] 룩 (5)
- [x] 모든 직선 방향으로 원하는 만큼 이동

- [x] 나이트 (2.5)
- [x] 모든 직선 방향 1칸 + 이동한 직선 방향의 좌, 우 대각선 1칸으로 이동
- [x] 진행 방향이 가로막혀도 적, 아군 상관없이 뛰어넘을 수 있음

- [x] 비숍 (3)
- [x] 모든 대각선 방향으로 원하는 만큼 이동

- [x] 퀸 (9)
- [x] 모든 방향으로 원하는 만큼 이동

- [x] 킹
- [x] 모든 방향 1칸 이동
- [x] 상대의 공격 범위로는 이동 불가능

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testCompile "org.assertj:assertj-core:3.14.0"
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.4.2'
}
17 changes: 17 additions & 0 deletions src/main/java/chess/ConsoleChessApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chess;

import chess.controller.ConsoleChessController;
import chess.view.ConsoleInputView;
import chess.view.ConsoleOutputView;
import chess.view.InputView;
import chess.view.OutputView;

public class ConsoleChessApplication {

public static void main(String[] args) {
OutputView outputView = new ConsoleOutputView();
InputView inputView = new ConsoleInputView();
ConsoleChessController consoleChessController = new ConsoleChessController(inputView, outputView);
consoleChessController.run();
}
}
24 changes: 0 additions & 24 deletions src/main/java/chess/WebUIChessApplication.java

This file was deleted.

75 changes: 75 additions & 0 deletions src/main/java/chess/controller/ConsoleChessController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package chess.controller;

import chess.domain.command.Command;
import chess.dto.Scores;
import chess.dto.TurnDto;
import chess.exception.ForcedTerminationException;
import chess.exception.ScoresRequestedException;
import chess.service.ChessService;
import chess.view.InputView;
import chess.view.OutputView;

import java.util.Map;

public class ConsoleChessController {

private final InputView inputView;
private final OutputView outputView;
private final ChessService chessService;

public ConsoleChessController(final InputView inputView, final OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
this.chessService = new ChessService();
}

public void run() {
outputView.printGuide();

while (chessService.isGameRunning()) {
try {
runOneTurn();
printBoard();
} catch (ForcedTerminationException e) {
outputView.printMessage(e.getMessage());
break;
}
}

printFinalResult();
}

private void runOneTurn() {
try {
TurnDto currentTurn = chessService.getCurrentTurnDto();
outputView.printTurn(currentTurn);

Command command = new Command(inputView.getCommand());
chessService.run(command);
} catch (UnsupportedOperationException | IllegalArgumentException e) {
outputView.printMessage(e.getMessage());
} catch (ScoresRequestedException e) {
Scores scores = chessService.getScores();
outputView.printScores(scores);
}
}

private void printFinalResult() {
printBoard();
printWinner();
}

private void printBoard() {
Map<String, String> boardDto = chessService.getBoardDto();
outputView.printBoard(boardDto);
}

private void printWinner() {
try {
String winner = chessService.getWinnerDto();
outputView.printWinner(winner);
} catch (IllegalStateException e) {
outputView.printMessage(e.getMessage());
}
}
}
49 changes: 49 additions & 0 deletions src/main/java/chess/domain/board/File.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package chess.domain.board;

import java.util.Arrays;

public enum File {

a(1),
b(2),
c(3),
d(4),
e(5),
f(6),
g(7),
h(8);

private final int index;

File(final int index) {
this.index = index;
}

public static File of(final int fileIndex) {
return Arrays.stream(File.values())
.filter(file -> hasSameIndex(fileIndex, file))
.findAny()
.orElseThrow(IllegalArgumentException::new);
}

private static boolean hasSameIndex(final int fileIndex, final File file) {
return file.getIndex() == fileIndex;
}

public int getIndex() {
return index;
}

public int calculateGap(final File file) {
return this.index - file.index;
}

public File add(final int amount) {
return File.of(this.index + amount);
}

public boolean canMove(final int amount) {
int fileIndex = index + amount;
return fileIndex >= a.index && fileIndex <= h.index;
}
}
Loading