Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d27a33
fix: 향상된 문법으로 equals 수정
junseoplee Jul 19, 2024
d6ca9b5
docs: 기능 요구 사항 업데이트
junseoplee Jul 20, 2024
5e9f872
feat: 승리한 팀을 찾고 출력하는 기능 구현
junseoplee Jul 20, 2024
fba2d73
feat: King 이 잡혔을 때 승리 팀과 점수를 출력하는 기능 구현
junseoplee Jul 22, 2024
90f634b
fix: Pawn 피스가 적이 없을 경우에도 대각선으로 움직일 수 있던 오류 수정
junseoplee Jul 22, 2024
89edcb7
docs: 기능 요구 사항 정리
junseoplee Jul 22, 2024
0218cec
refactor: 프로젝트 구조 수정
junseoplee Jul 23, 2024
c786f3d
feat: 게임별로 구분할 수 있는 ChessGame 클래스 구현, 저장할 수 있도록 상태를 나타내는 State 열거형 구현
junseoplee Jul 23, 2024
5fd16d9
feat: DB 연결에 필요한 설정 추가
junseoplee Jul 23, 2024
54b66b5
feat: DB 연결을 위한 ChessGameDao 기능 추가
junseoplee Jul 23, 2024
9f7f78c
feat: DB 연결을 위한 PieceDao 기능 추가
junseoplee Jul 23, 2024
037471d
feat: DB 연결을 위한 PieceDao 기능 추가
junseoplee Jul 23, 2024
61d451a
fix: DB 연결을 위한 설정 수정
junseoplee Jul 25, 2024
3f07391
refactor: Board 반환을 위한 리팩토링
junseoplee Jul 25, 2024
a4d293e
refactor: 진행 상태를 보다 명확하게 알 수 있도록 변경
junseoplee Jul 25, 2024
e20a260
feat: DB 연결 기능과 컨트롤러 조립
junseoplee Jul 25, 2024
80b7e47
docs: 기능 요구 사항 및 에러메세지 업데이트
junseoplee Jul 25, 2024
a3ac67f
fix: 기존 게임이 정상적으로 불러와지지 않던 오류 수정
junseoplee Jul 25, 2024
ddfb961
refactor: 명령어를 다루는 책임을 컨트롤러에서 분리
junseoplee Jul 29, 2024
7c6c78e
feat: UnsupportedOperationException 으로 사용되지 않는 메서드 관리
junseoplee Jul 29, 2024
0ad0e65
test: 폰의 공격 움직임을 검증하는 테스트 추가
junseoplee Jul 29, 2024
3ce712d
fix: 변수 이름을 명확하게 수정
junseoplee Jul 29, 2024
d5483e4
fix: 상태를 더 명확하게 나타낼 수 있는 이름으로 수정
junseoplee Jul 29, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/chess/model/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void validatePath(Position from, Position to) {
Set<Position> positionsWithOutTarget = new HashSet<>(board.keySet());
positionsWithOutTarget.remove(to);

Path path = source.findPath(from, to);
Path path = source.findPath(from, to, board);
path.validateObstacle(positionsWithOutTarget);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/Piece.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import chess.model.position.Position;
import chess.model.ErrorMessage;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public abstract class Piece {
Expand All @@ -16,7 +17,7 @@ public Piece(final Color color) {
this.color = color;
}

public abstract Path findPath(Position from, Position to);
public abstract Path findPath(Position from, Position to, Map<Position, Piece> board);

public abstract PieceInfo pieceType();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/pieces/Bishop.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import chess.model.position.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Bishop extends Piece {

Expand All @@ -21,7 +22,7 @@ public Bishop(final Color color) {
}

@Override
public Path findPath(Position from, Position to) {
public Path findPath(Position from, Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);
validateMovement(movement, availableMovements);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/pieces/King.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import chess.model.position.Position;
import chess.model.ErrorMessage;
import java.util.List;
import java.util.Map;

public class King extends Piece {

Expand All @@ -22,7 +23,7 @@ public King(final Color color) {
}

@Override
public Path findPath(Position from, Position to) {
public Path findPath(Position from, Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);
validateMovement(movement, availableMovements);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/pieces/Knight.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import chess.model.ErrorMessage;

import java.util.List;
import java.util.Map;

public class Knight extends Piece {

Expand All @@ -25,7 +26,7 @@ public Knight(final Color color) {
}

@Override
public Path findPath(Position from, Position to) {
public Path findPath(Position from, Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);
validateMovement(movement, availableMovements);

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/chess/model/piece/pieces/Pawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,29 @@ public Pawn(final Color color) {
}

@Override
public Path findPath(final Position from, final Position to) {
public Path findPath(final Position from, final Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);

if (isAttackMovement(movement)) { // 공격 움직임인 경우
return findPathForAttackMovement(to, movement);
if (isAttackMovement(movement)) {
return findPathForAttackMovement(to, movement, board);
}

return findPathForEmptyPosition(from, to, movement); // 빈 칸으로 이동하는 경우
return findPathForEmptyPosition(from, to, movement);
}

private boolean isAttackMovement(final Movement movement) {
return AVAILABLE_ATTACK_MOVEMENTS.get(getColor()).contains(movement);
}

private Path findPathForAttackMovement(final Position to, final Movement movement) {
private Path findPathForAttackMovement(final Position to, final Movement movement, final Map<Position, Piece> board) {
validateMovement(movement, AVAILABLE_ATTACK_MOVEMENTS.get(getColor()));

validateAttackMovement(to, board);
return new Path(List.of(to));
}
private void validateAttackMovement(final Position to, final Map<Position, Piece> board) {
Piece targetPiece = board.get(to);
if (targetPiece == null || targetPiece.getColor() == this.getColor()) {
throw new IllegalArgumentException(ErrorMessage.INVALID_DIRECTION.getMessage());
}
}
Comment on lines -58 to +66
Copy link
Owner

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.

후후 좋습니다


private Path findPathForEmptyPosition(final Position from, final Position to, final Movement movement) {
validateMovement(movement, List.of(AVAILABLE_MOVEMENTS.get(getColor())));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/pieces/Queen.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Queen extends Piece {

Expand All @@ -25,7 +26,7 @@ public Queen(final Color color) {
}

@Override
public Path findPath(final Position from, final Position to) {
public Path findPath(final Position from, final Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);
validateMovement(movement, availableMovements);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/chess/model/piece/pieces/Rook.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Rook extends Piece {

Expand All @@ -24,7 +25,7 @@ public Rook(final Color color) {
}

@Override
public Path findPath(final Position from, final Position to) {
public Path findPath(final Position from, final Position to, final Map<Position, Piece> board) {
Movement movement = convertMovement(from, to);
validateMovement(movement, availableMovements);

Expand Down