-
Notifications
You must be signed in to change notification settings - Fork 412
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
[4, 5단계 - 체스] 라이언(권영훈) 미션 제출합니다. #235
Merged
serverwizard
merged 130 commits into
woowacourse:younghoonkwon
from
YounghoonKwon:step2
Apr 12, 2021
Merged
Changes from all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
27eea54
docs: 리드미 구현 목록 작성
7b41611
feat: 프로젝트 파일 구조 생성
9ff0366
feat(Position): 체스 말의 위치를 나타내는 Position 클래스에서 생성자 구현
612ce53
feat(Position): 체스 말의 위치가 Grid 범위를 벗어날 경우 예외 출력
da59418
docs: README 업데이트
fd15b1a
feat(Piece): 체스말에 대한 추상 클래스 구현
65371aa
feat(Position): 생성자 추가
e90c792
feat(Empty): empty예외 구현
2e65682
feat(King): 킹 스케레톤 코드 구현
ef48684
refactor: 추상 메서드 삭제 및 파라미터 추가
jaeseongDev f036d6b
feat(King): move 메서드에 대한 테스트 코드 작성
jaeseongDev 2e26da1
feat(King): 킹 움직임 구현
2112313
feat(LineTest): Line에 대한 테스트 코드 작성
jaeseongDev f6b677e
feat(Line): 같은 포지션을 가진 Piece가 있을 경우 예외 발생
3776fd9
refactor: 움직임 메서드 리펙토링
96aa010
feat(Grid): 체스판 초기화
a186116
feat(Direction): 방향 Enum 추가
f9ecd41
feat(Grid): 그리드 구현
4dbe3b8
refactor: 메서드 로직 및 구조 리팩터링
0f5b708
feat(Bishop): 비숍 관련 로직 구현
3f4f062
feat(Rook): 룩 관련 로직 구현
6cb36ce
docs: 기능 구현 목록 업데이트
23e7aef
feat(Queen): 퀸 관련 로직 구현
16c1962
feat(Knight): 나이트 관련 로직 구현
c8680f6
refactor(Line): GeneralLine 메서드 로직 수정
6365cfa
refactor: 불필요한 코드 제거
75a0b53
fix: 움직일 수 있는 포지션을 구하는 로직 버그 수정
cdaf2ca
feat(Pawn): 폰에 대한 로직 구현
jaeseongDev 101d677
refactor: Grid 클래스에서 move() 메서드 구현을 위한 재설계
jaeseongDev 1996682
refactor: Grid 클래스에서 static을 지우고 객체를 생성할 수 있도록 만들기
jaeseongDev bdf163c
refactor: 체스말 배치 네이밍 변경
b3513ec
refactor: 사용하지 않는 임포트 삭제 및 스타일 수정
69b30cc
refactor: 가는 방향 검증 네이밍 수정
9282eef
docs: 폰에 대한 기능 설명 추가
jaeseongDev 206f0b2
Merge branch 'step1' of https://github.com/YounghoonKwon/java-chess i…
jaeseongDev 9875051
feat(Grid): Pawn에 대한 로직 추가
jaeseongDev 5238d71
refactor: Pawn에 대한 처리 로직 리팩토링
jaeseongDev 8324ee8
refactor: 가는 방향 검증 네이밍 수정
d12ded4
feat(Grid): Pawn에 대한 로직 추가
jaeseongDev 768f509
refactor: Pawn에 대한 처리 로직 리팩토링
jaeseongDev f776685
Merge branch 'step1' of https://github.com/YounghoonKwon/java-chess i…
jaeseongDev 7097bb3
refactor: domain의 getter들 리팩토링
c6637dc
feat: 체스판 출력 기능
jaeseongDev d609d9a
feat: 입력값을 받아 움직이는 기능 추가
jaeseongDev 83e83df
fix: isEmpty 수정
f1c1002
test: Grid에서 move()가 작동하는 지 테스트 추가
jaeseongDev 7dcd632
feat: 폰 움직임 구현
e7e0fa5
refactor: controller 분리
1f8d4c2
docs: 구현한 기능 체크
jaeseongDev 3df65d3
Merge branch 'step1' of https://github.com/YounghoonKwon/java-chess i…
jaeseongDev d81f786
refactor(ChessController): 컨트롤러 관련 로직 리팩토링
jaeseongDev 0dac739
refactor(Grid): Grid의 move()에 대한 메서드 리팩토링
jaeseongDev 06c9376
refactor: 그리드 역할 분리
jaeseongDev f80bf5b
refactor: Grid 로직에 대한 메서드 분리
jaeseongDev 36ff8f4
feat: 각 체스 말에 대한 점수 조회 메서드 추가
jaeseongDev 1713ef7
feat: 점수 계산 기능
jaeseongDev c34bdd3
refactor(Grid): 계산 로직 수정
jaeseongDev af9fd29
docs: 기능 구현 목록 추가
jaeseongDev 57759a8
refactor: 접근 제어자 및 final 키워드 추가, 메서드 순서 변경
4bf176c
feat: 플레이어 순서 추가
1c79923
feat: 승자 판별 구현
2e380a3
refactor: 자신의 말을 옮길 수 있도록 유효성 검증 코드 리팩토링
jaeseongDev 67f5ce5
refactor: 네이밍 수정(엘레강트 오브젝트 스타일)
99f8268
refactor: 네이밍 수정(엘레강트 오브젝트 스타일)
fec2d17
Merge branch 'step1' of https://github.com/YounghoonKwon/java-chess i…
jaeseongDev 7c07e63
refactor(ChessService): 게임 상태를 관리하는 ChessService 클래스 생성해서 책임 분리
jaeseongDev de7e577
refactor: 입력 받은 명령어마다 클래스를 분리해서 리팩토링
jaeseongDev 15ada50
refactor: 상태 패턴 적용해서 게임 명령어에 따라 다르게 실행할 수 있도록 리팩토링
jaeseongDev 848b55f
refactor: ChessService의 gameOver 속성 제거
jaeseongDev 9b29f8f
refactor: 상태에 관련된 로직의 변수명 수정
jaeseongDev 0537d3f
refactor: 상태 패턴 리팩토링
jaeseongDev 403c3d2
refactor: 불필요한 코드 삭제
jaeseongDev 67e80a6
refactor: 상태패턴 리팩터링
e35961c
refactor: 매직 넘버 상수로 치환
jaeseongDev a3826f2
refactor: BlackTurn, WhiteTurn에 대한 로직 수정
jaeseongDev f078317
Merge branch 'step1' of https://github.com/YounghoonKwon/java-chess i…
jaeseongDev 4d10d37
refactor: Lines로 클래스 분리
jaeseongDev 4ba3daf
refactor: Lines로 클래스 분리
jaeseongDev 963e5b6
refactor: Grid에 불필요한 코드 삭제
jaeseongDev eece287
refactor: Lines에 대한 접근자 수정
jaeseongDev f44a710
refactor: grid 역할 분리
b0f1655
refactor: service 삭제
dacf443
refactor: 움직이는 로직은 Piece로 이동
jaeseongDev ac801c1
refactor: 상속과 Override를 막아야하는 클래스 및 메서드에 final 붙이기
754b9c0
feat: 테스트를 용이하게 하기 위해 Grid에 전략 패턴을 적용
jaeseongDev b1a602f
test(PwanTest): 폰을 생성하는 클래스에 대한 테스트 추가
jaeseongDev c43db81
reafactor: try-catch 추가
a49374d
test(PawnTest): 폰에 대한 로직 테스트 추가
jaeseongDev f2667a6
feat: 테스트 케이스 추가
2426a5f
refactor: resolve merge conflict
d84e0b8
refactor: 테스트 수정
0ef1dba
test(Empty): Empty에 대한 테스트 로직 추가
jaeseongDev c055ea6
test(PositionTest): Position에 대한 테스트 추가
jaeseongDev efd9e9e
test(ScoreTest): Score에 대한 테스트 코드 추가
jaeseongDev 78cbe9d
test: Line, Lines에 대한 테스트 추가
jaeseongDev a0f156d
test(GridTest): Grid에 대한 테스트 코드 추가
jaeseongDev ea7de41
fix: 버그 픽스
1e3b452
refactor: Column, Row Enum 추가 testStrategy 테스트 패키지로 이동
c31e0fd
refactor: Row, Column Enum으로 랩핑
d472193
refactor: given, when, then을 기준으로 줄바꿈
7829565
refactor: 상태패턴 domain으로 이동, controller에서 view 처리하게끔 리팩터링
ef4f91a
fix: 입력에 따른 에러 수정
1378d73
Merge branch 'younghoonkwon' of https://github.com/woowacourse/java-c…
7481be7
docs: 구현 목록 작성 4단계
b2650d8
feat: html/css 체스보드 작성
4b9b318
refactor: 컨트롤에서 상태 분리
719b235
feat: 말 움직임 구현
e4b061b
feat: 체스판 start 버튼에 따라 브라우저 껏다 켜도 이전 상황 복구
2bbb124
feat: 점수 계산 및 턴 구현
46b1733
feat: css 수정
7c0dbe2
feat: font 변경
a9ecf49
feat: 버튼 스타일 추가
61d654e
refactor: King, Queen 심볼 변경
735ab12
feat: db 구현
1166ecf
refactor: js 버튼 ui 리팩토링
bcd5045
refactor: js .then() 함수들 async await으로 리팩토링
88ef082
refactor: 스타일 변경
d01058e
refactor: css 패키지 분리
7fa3488
refactor: turn 싱크 안맞는 부분 수정
fb50826
refactor: 쓰이지 않는 코드 리팩토링
74c4fd9
refactor: PieceMapper 추가
430598d
refactor: Enum PieceMapper 리팩토링
f26dc31
refactor: response 처리 필요없는거 삭제
9837de7
docs: 구현 목록 업데이트
6523c82
refactor: 커맨트 삭제
5849615
refactor: Chess 엔티티 패키지 분리
ad8d890
feat: connection test 추가
5c32d38
refactor: html response message 수정
56d3516
feat: connection pooling 구현
6efff11
refactor: 주석 삭제
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,98 @@ | ||
package chess; | ||
|
||
import chess.dao.ChessDAO; | ||
import chess.domain.grid.ChessGame; | ||
import chess.domain.grid.Grid; | ||
import chess.domain.grid.gridStrategy.NormalGridStrategy; | ||
import chess.domain.piece.Color; | ||
import chess.domain.position.Position; | ||
import chess.dto.PositionDTO; | ||
import chess.entity.Chess; | ||
import com.google.gson.Gson; | ||
import spark.ModelAndView; | ||
import spark.template.handlebars.HandlebarsTemplateEngine; | ||
|
||
import java.sql.SQLDataException; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static spark.Spark.get; | ||
import static spark.Spark.*; | ||
|
||
public class WebUIChessApplication { | ||
private static final Gson GSON = new Gson(); | ||
private static final int SUCCESSFUL_RESPONSE = 200; | ||
private static final int CLIENT_ERROR_RESPONSE = 400; | ||
private static final String CHESS_ID = "1"; | ||
|
||
public static void main(String[] args) { | ||
staticFiles.location("/public"); | ||
ChessGame chessGame = new ChessGame(new Grid(new NormalGridStrategy())); | ||
ChessDAO chessDAO = new ChessDAO(); | ||
|
||
get("/", (req, res) -> { | ||
Map<String, Object> model = new HashMap<>(); | ||
return render(model, "index.html"); | ||
return render(new HashMap<>(), "index.html"); | ||
}); | ||
|
||
get("/pieces", (req, res) -> { | ||
return chessGame.pieceMap(); | ||
}, GSON::toJson); | ||
|
||
get("/turn", (req, res) -> { | ||
return chessGame.turn(); | ||
}, GSON::toJson); | ||
|
||
get("/score/white", (req, res) -> { | ||
return chessGame.score(Color.WHITE); | ||
}, GSON::toJson); | ||
|
||
get("/score/black", (req, res) -> { | ||
return chessGame.score(Color.BLACK); | ||
}, GSON::toJson); | ||
|
||
get("/gameover", (req, res) -> { | ||
return Arrays.asList(chessGame.isGameOver(), chessGame.getWinner()); | ||
}, GSON::toJson); | ||
|
||
post("/move", (req, res) -> { | ||
PositionDTO positionDTO = GSON.fromJson(req.body(), PositionDTO.class); | ||
String sourcePosition = positionDTO.getSourcePosition(); | ||
String targetPosition = positionDTO.getTargetPosition(); | ||
try { | ||
chessGame.move(chessGame.grid().piece(new Position(sourcePosition)), | ||
chessGame.grid().piece(new Position(targetPosition))); | ||
return SUCCESSFUL_RESPONSE; | ||
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. 클라이언트 입장에서 HTTP 상태 코드 200과 별개로, 응답 값으로 200이 내려오면 이게 숫자 200을 의미하는지 상태를 의미하는지 헷갈릴 수도 있지 않을까?란 피드백이었어요. ^^ |
||
} catch (IllegalArgumentException error) { | ||
return CLIENT_ERROR_RESPONSE; | ||
} | ||
}); | ||
|
||
post("/start", (req, res) -> { | ||
chessGame.start(); | ||
return SUCCESSFUL_RESPONSE; | ||
}); | ||
|
||
post("/reset", (req, res) -> { | ||
chessGame.reset(); | ||
return SUCCESSFUL_RESPONSE; | ||
}); | ||
|
||
post("/save", (req, res) -> { | ||
Chess chess = new Chess(CHESS_ID, chessGame.gridStringify(), chessGame.turn().name()); | ||
if (chessDAO.findByChessId(CHESS_ID) == null) { | ||
chessDAO.addChess(chess); | ||
} | ||
chessDAO.updateChess(chess, chess.getChess(), chess.getTurn()); | ||
return SUCCESSFUL_RESPONSE; | ||
}); | ||
|
||
post("/load", (req, res) -> { | ||
if (chessDAO.findByChessId(CHESS_ID) == null) { | ||
throw new SQLDataException("저장된 보드가 없습니다."); | ||
} | ||
Chess chess = chessDAO.findByChessId(CHESS_ID); | ||
chessGame.load(chess); | ||
return SUCCESSFUL_RESPONSE; | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이건 개인적인 궁금함인데요. Jackson이 아닌 Gson 라이브러리를 사용한 이유가 있을까요?
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.
Spring 에서는 Jackson을 기본으로 내장 하는 것으로 알고있는데 spark는 따로 언급 없이 spark documentation에 Gson으로 사용하길래, 따라했어요!
조금 찾아봤는데,
대용량 파일에서는 Jackson이 GSON보다 2배가량 빠르고,
작은 파일에서는 GSON이 Jackson보다 아주 약간? 빠르네요.
하지만, GSON은 maintenance가 더이상 안되는 것으로 보이며, moshi라는 것으로 대체되는 추세인것 같습니다.
google/gson#1821
https://www.overops.com/blog/the-ultimate-json-library-json-simple-vs-gson-vs-jackson-vs-json/
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.
추가 학습까지 하시고 이렇게 공유까지 해주시다니 정말 멋지네요 👍
이런 피드백을 드린 이유는 어떤 기준을 가지고 라이브러리를 선택했는지가 궁금했어요!
그리고 저는 설령 그 기준이 틀렸다하더라도 그런 고민하는 시간이 의미있다고 생각하거든요. ^^