Skip to content
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

오잉또잉 체스게임 #6

Open
wants to merge 61 commits into
base: hanueleee
Choose a base branch
from

Conversation

hanueleee
Copy link

No description provided.

woowahan-neo and others added 30 commits March 13, 2023 12:57
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
Co-authored-by: hanueleee <[email protected]>
echo724 and others added 14 commits March 17, 2023 14:52
Co-authored-by: hanueleee <[email protected]>
Copy link
Member

@greeng00se greeng00se left a comment

Choose a reason for hiding this comment

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

테스트 부분은 전부 given-when-then(준비-실행-검증)을 적용해보면 어떨까?
다른 사람이 보기에는 너무 어려운 것 같아
체스 미션한다고 고생했어!

README.md Outdated

### 랭크 : 가로줄을 나타내는 enum

### 파일 : 세로줄을 나타내느 enum
Copy link
Member

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.

아차차~

Comment on lines 9 to 30
String defaultPiece = "";
if (piece.getType() == PieceType.EMPTY) {
return ".";
}
if (piece.getType() == PieceType.PAWN) {
defaultPiece = "p";
}
if (piece.getType() == PieceType.BISHOP) {
defaultPiece = "b";
}
if (piece.getType() == PieceType.KNIGHT) {
defaultPiece = "n";
}
if (piece.getType() == PieceType.ROOK) {
defaultPiece = "r";
}
if (piece.getType() == PieceType.QUEEN) {
defaultPiece = "q";
}
if (piece.getType() == PieceType.KING) {
defaultPiece = "k";
}
Copy link
Member

Choose a reason for hiding this comment

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

다음과 같이 맵을 사용하면 많은 분기를 줄일 수 있을 것 같아 👍

private static filnal Map<PieceType, String> Mapper = Map.of(
    PieceType.PAWN, "p"
)

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.

오 그렇네 감사링

Choose a reason for hiding this comment

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

친절했다 ㄷㄷ

Comment on lines 27 to 28
public static final int BLACK_GENERALS_RANK = 7;
private final Map<Position, Piece> board;
Copy link
Member

Choose a reason for hiding this comment

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

정적 필드랑 필드는 구분해주면 좋을 것 같아

Choose a reason for hiding this comment

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

ditto

Choose a reason for hiding this comment

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

디토


private void placePieceAtPosition(final List<Piece> pieces, final Position position, int rank) {
if (position.isRank(rank)) {
this.board.put(position, pieces.get(position.getFile().getIndex()));
Copy link
Member

Choose a reason for hiding this comment

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

인스턴스 필드, 메서드에 접근할 때 일관성있게 this를 사용하고 있는데
이렇게 사용하는 이유는 페어와 컨벤션을 맞췄기 때문이겠지?
이 부분에 대해서 어떻게 생각해? 사용하지 않는 쪽과 사용하는 쪽 뭐가 더 좋을 것 같아?

Copy link
Author

@hanueleee hanueleee Mar 20, 2023

Choose a reason for hiding this comment

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

사실 별생각없는데 인텔리제이에서 저장 키맵?에 this가 자동으로 붙도록 설정해두고 진행했어.
this를 붙여서 정확도?명확성?은 올라갔는데, 전체적으로 다시보니까 코드가 괜히 길어지는 것 같기도 하네.

Comment on lines 94 to 96
if (List.of(Direction.NE, Direction.SE, Direction.NW, Direction.SW).contains(direction)) {
this.checkDiagonalPiece(destination);
this.checkSameColor(destination, color);
Copy link
Member

Choose a reason for hiding this comment

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

�direction.isDiagnoal 과 같이 해당 Direction이 대각선인지 확인하는 메서드를 만들어보면 어떨까?

Choose a reason for hiding this comment

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

인정 Direction을 객체답게!!

Copy link
Author

Choose a reason for hiding this comment

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

굿굿

Comment on lines 44 to 50
int sourceFIleIndex = this.getFile().getIndex();
int sourceRankIndex = this.getRank().getIndex();
int destinationFIleIndex = destination.getFile().getIndex();
int destinationRankIndex = destination.getRank().getIndex();

int fileGap = destinationFIleIndex - sourceFIleIndex;
int sourceGap = destinationRankIndex - sourceRankIndex;
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 File과 Rank에서 각각 같은 Enum을 받아 받을 수 있을 것 같아

Copy link
Author

Choose a reason for hiding this comment

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

음 enum으로 연산하라는 말?

Comment on lines 52 to 55
try {
return Direction.findByVector(fileGap, sourceGap);
} catch (Exception ignored) {
}
Copy link
Member

Choose a reason for hiding this comment

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

orElseGet(빈 방향)을 반환한다면 try-catch를 사용하지 않아도 될 것 같아

Copy link
Author

Choose a reason for hiding this comment

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

단위벡터를 사용해서 해결했습니다 ㅎㅎㅎ

Comment on lines 57 to 79
if (fileGap > 0) {
if (sourceGap > 0) {
return Direction.NE;
}
if (sourceGap < 0) {
return Direction.SE;
}
return Direction.E;
}
if (fileGap < 0) {
if (sourceGap > 0) {
return Direction.NW;
}
if (sourceGap < 0) {
return Direction.SW;
}
return Direction.W;
}

if (sourceGap > 0) {
return Direction.N;
}
return Direction.S;
Copy link
Member

Choose a reason for hiding this comment

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

Direction.findByVector가 아닌

static 필드로 나이트의 �방향 리스트(NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW); 과
그 외 방향을 필드로 두고

Direction.knightDirection(a, b)
Direction.of(a, b) 받아서 구할 수 있을 것 같아

그러면 반복 제거 할 수 있을 듯


public List<String> readCommand() {
String input = scanner.nextLine();
return Arrays.stream(input.split(" ")).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

" " 매직넘버

List<Piece> pieces = List.of(Rook.create(Color.WHITE), Knight.create(Color.WHITE), Pawn.create(Color.BLACK),
Rook.create(Color.BLACK));
for (int i = 0; i < 4; i++) {
assertThat(board).extracting("board").asInstanceOf(InstanceOfAssertFactories.MAP)
Copy link
Member

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.

무슨말이느뇨 이해하지 못했느뇨

Copy link

@shin-mallang shin-mallang left a comment

Choose a reason for hiding this comment

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

1차

private static final String INVALID_COMMAND_ERROR_MESSAGE = "잘못된 명령어입니다.";
private static final String INVALID_ARGUMENT_ERROR_MESSAGE = "는 인자를 입력할 수 없습니다.";
private static final String INVALID_ARGUMENT_COUNT_ERROR_MESSAGE = "는 인자를 2개만 가질 수 있습니다.";
private static final String NO_ARGUMENT_ERROR_MESSAGE = "인자를 반환할 수 없는 명령입니다.";

Choose a reason for hiding this comment

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

굳이 메세지를 상수가 할 필요가 있었어?
오히려 더 파악하기 힘든 것 같아

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 final InputView inputView;
private final OutputView outputView;

public ChessController(final InputView inputView, final OutputView outputView) {

Choose a reason for hiding this comment

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

굳이 주입해준 이유가 있을까?
static으로 사용해 보는건 어때?

Choose a reason for hiding this comment

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

말랑 근데 static으로 사용하는 거의 단점은 없나?
당장 InputView가 여러가지로 가능한게 아니니 필요 없으려나??

Copy link
Author

@hanueleee hanueleee Mar 20, 2023

Choose a reason for hiding this comment

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

  1. 주입하기
  2. 주입안하고 그냥 생성자에서 알아서 초기화
  3. static으로 사용

이 셋 중 아무거나 쓰는 편
말랑이 3을 선호하는 이유는?

Choose a reason for hiding this comment

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

@hanueleee
@eunkeeee
테스트할 것도 아니고 그냥 컨크롤러에서만 편하게 쓸건데 굳이 주입을 할 필요가 있어?
회면이 바뀔 것도 아니니까?


public class PieceMapper {

public static String map(Piece piece) {

Choose a reason for hiding this comment

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

Map<Type, String>을 쓰면 분기를 줄일 수 있을 것 같아

Comment on lines 9 to 30
String defaultPiece = "";
if (piece.getType() == PieceType.EMPTY) {
return ".";
}
if (piece.getType() == PieceType.PAWN) {
defaultPiece = "p";
}
if (piece.getType() == PieceType.BISHOP) {
defaultPiece = "b";
}
if (piece.getType() == PieceType.KNIGHT) {
defaultPiece = "n";
}
if (piece.getType() == PieceType.ROOK) {
defaultPiece = "r";
}
if (piece.getType() == PieceType.QUEEN) {
defaultPiece = "q";
}
if (piece.getType() == PieceType.KING) {
defaultPiece = "k";
}

Choose a reason for hiding this comment

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

아뭐야 똑같은말했네용

Comment on lines 27 to 28
public static final int BLACK_GENERALS_RANK = 7;
private final Map<Position, Piece> board;

Choose a reason for hiding this comment

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

ditto

return this.board.get(position).isSameColor(color);
}

public List<Piece> getPiecesAt(Rank rank) {

Choose a reason for hiding this comment

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

findAllByRank도 좋을 듯?

Choose a reason for hiding this comment

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

ㅇㅇ get어쩌고를 쓰면 다른 사람 입장에서는 내부에 다른 로직이 존재할 것이라고 잘 생각 못하는 경우가 있어서 리얼 get만 딱 하는 곳에서 쓰는게 좋을듯

Copy link
Author

Choose a reason for hiding this comment

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

get은 진짜 get만 하는 곳에서 써라 굿

}
}

private void checkDiagonalPiece(final Position destination) {

Choose a reason for hiding this comment

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

왜 diagonal 체크인데 isEmpty를 하는거야?

Copy link
Author

Choose a reason for hiding this comment

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

폰은 대각선이 비어있으면 (다른 말을 잡을 수 없으면) 대각선으로 이동할 수 없으니까


public ChessGame() {
this.status = GameStatus.START;
this.board = Board.create();

Choose a reason for hiding this comment

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

주입 받는것도 좋을 것 갘아

Copy link
Author

@hanueleee hanueleee Mar 21, 2023

Choose a reason for hiding this comment

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

ChessGame에 `Board를 주입하라는? 왜죠?

}

public void start() {
if (this.status != GameStatus.START) {

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.

시러

Choose a reason for hiding this comment

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

끼잉..

BLACK,
NONE;

public static Color reverse(Color color) {

Choose a reason for hiding this comment

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

static 떼고, color.reverse()도 좋을 듯?

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.

반영했습니다. 굿

Copy link

@gitchannn gitchannn left a comment

Choose a reason for hiding this comment

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

오잉아 나도 다녀간다

from. 깃짱코딩

@@ -1,7 +1,62 @@
# java-chess

Choose a reason for hiding this comment

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

와 commit 보고 벌써 4단계 DB연결 다한줄 ㄷㄷ

Copy link
Author

Choose a reason for hiding this comment

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

킥 킥 어림도 없지

- [x] 룩
- [x] 비숍
- [x] 퀸
- [x] 킹

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.

왜여 >< 다 알자나

- [x] 빈 보드를 생성
- [x] 좌표를 입력으로 주었을때, 좌표의 피스를 반환(getPiece)
- [x] 좌표에 피스가 존재하는지 확인
- [x] 같은 색깔 피스 인지 확인.

Choose a reason for hiding this comment

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

확인.

private static final String INVALID_COMMAND_ERROR_MESSAGE = "잘못된 명령어입니다.";
private static final String INVALID_ARGUMENT_ERROR_MESSAGE = "는 인자를 입력할 수 없습니다.";
private static final String INVALID_ARGUMENT_COUNT_ERROR_MESSAGE = "는 인자를 2개만 가질 수 있습니다.";
private static final String NO_ARGUMENT_ERROR_MESSAGE = "인자를 반환할 수 없는 명령입니다.";

Choose a reason for hiding this comment

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

ㅇㅈ

public enum GameStatus {
START,
END,
MOVE

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.

엥 그러게 얘말고도 다른 enum도 땀 안붙였는데 잘돌아가네 왤까,, 일단 수정했슴당

Copy link
Author

Choose a reason for hiding this comment

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

image

오호 enum내에 따로 로직 없으면 땀 안붙여도 되는듯

BLACK,
NONE;

public static Color reverse(Color color) {

Choose a reason for hiding this comment

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

ㅇㅈ

public abstract class Piece {

public static final String PIECE_CANNOT_MOVE_ERROR_MESSAGE = "이(가) 움직일 수 없는 위치입니다.";
public static final String OUT_OF_DISTANCE_ERROR_MESSAGE = "이(가) 움직일 수 없는 거리입니다.";

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 static List<Piece> createGenerals(final Color color) {
List<Piece> generals = new ArrayList<>();

Choose a reason for hiding this comment

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

List.of(Rook.create(color), ~~~~ 해도 좋을듯 근데 똑같은듯

SSW(-1, -2),
WSW(-2, -1),
WNW(-2, 1),
NNW(-1, 2);

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.

요거 나침판에 쓰이는 표기여서 그대로 가져와봤삼

Comment on lines 14 to 18
public static final String INVALID_FILE_ERROR_MESSAGE = "잘못된 좌표입니다.";
private final String label;

private final int index;

Choose a reason for hiding this comment

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

끔찍한 혼종ㅋㅋㅋㅋ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants