Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
ff4f19d
feat: remove web dependency
woowahan-neo Mar 13, 2023
1bab9ff
feat: add example for functional programming api example
woowahan-neo Mar 13, 2023
98598c0
chore: change package
woowahan-neo Mar 13, 2023
c187e53
[1, 2단계 - 체스] 누누(송은우) 미션 제출합니다. (#462)
be-student Mar 22, 2023
a35d036
refactor: domain 만을 보고, 실행할 수 있도록 변경
be-student Mar 23, 2023
6bb1785
chore: 안 쓰이는 코드 제거
be-student Mar 23, 2023
9558e71
feat: pieceType 에 기본 점수를 추가했습니다
be-student Mar 23, 2023
aaaca1b
feat: 각 클래스마다 기본 점수를 반환하는 기능 추가
be-student Mar 23, 2023
1db36ca
refactor: factory 에서 생성하는 책임을 넘김
be-student Mar 23, 2023
3b091c2
fix: pieceType 에서 양방향 의존 관계를 갖던 부분 수정
be-student Mar 23, 2023
60d2e98
test: 빠진 gameState 테스트 추가
be-student Mar 23, 2023
dda31f7
feat: piece 에서 점수를 가져오는 기능 추가
be-student Mar 23, 2023
75f2301
feat: 출력 기능 구현
be-student Mar 23, 2023
ee0f955
feat: 체스판 기물 점수 계산 기능 추가
be-student Mar 23, 2023
1b30a1f
feat: board 점수 계산 기능 추가
be-student Mar 23, 2023
0b11ba6
feat: controller 에서 현재 점수 계산 기능 추가
be-student Mar 23, 2023
b8f93cc
test: mapper 테스트 추가
be-student Mar 23, 2023
afac2ef
test: pieceResponse 테스트 추가
be-student Mar 23, 2023
a0571fd
test: file, rank 테스트 추가
be-student Mar 23, 2023
37b9a7c
feat: frontcontroller 적용
be-student Mar 24, 2023
058efda
Revert "feat: frontcontroller 적용"
be-student Mar 24, 2023
7b649c2
feat: turn 기능 추가
be-student Mar 24, 2023
bf94ef8
feat: 같은 팀 말 연속 2번 움직임 검증 추가
be-student Mar 24, 2023
d36ad59
feat: 킹인지 여부를 체크하는 값 추가
be-student Mar 24, 2023
d8ad0fe
feat: 킹이 죽은 여부 체크 추가
be-student Mar 24, 2023
4877465
test: 빠진 테스트 추가
be-student Mar 24, 2023
055328b
feat: 킹이 죽으면 종료하는 기능 추가
be-student Mar 24, 2023
9078e43
test: 빠진 테스트 추가
be-student Mar 24, 2023
81ee7fb
feat: connectionGenerator 작성
be-student Mar 24, 2023
dd8439c
refactor: 패키지 변경
be-student Mar 24, 2023
ed0cd10
docs: readme 작성
be-student Mar 24, 2023
2e55d44
feat: userDao jdbc 템플릿으로 개선
be-student Mar 25, 2023
6e0fb4c
refactor: ! 가 앞에 있던 부분 긍정형으로 변경
be-student Mar 25, 2023
6cd7fc3
feat: userDao 테스트용 script 작성
be-student Mar 25, 2023
ea85e01
chore: 사용되지 않는 System.out.println 제거
be-student Mar 25, 2023
2aae9c8
refactor: board 에서 출력하는 로직 리팩토링
be-student Mar 25, 2023
3becd43
feat: 테이블 설계 작성
be-student Mar 25, 2023
d5cfadb
refactor: 의존성 역전 제거
be-student Mar 25, 2023
1e523e8
refactor: PieceMapper 로 black, white 한꺼번에 변경
be-student Mar 25, 2023
9facb95
feat: input 에서 request 객체를 반환하도록 변경
be-student Mar 25, 2023
e870575
feat: chessGameDao 작성
be-student Mar 25, 2023
e7e539d
feat: userDao 제작
be-student Mar 25, 2023
6bb215c
feat: 움직임을 저장하는 moveDao 추가
be-student Mar 25, 2023
1272093
feat: 현재 턴을 구하는 기능 추가
be-student Mar 25, 2023
20fe495
feat: sql 테이블에 게임 status 추가
be-student Mar 25, 2023
0050bce
feat: 인증 검사를 하는 필터 추가
be-student Mar 25, 2023
30347e2
chore: turn 의 필드 이름 변경
be-student Mar 25, 2023
b83d4de
feat: state 마다 이름 추가
be-student Mar 25, 2023
2868af1
feat: user 추가시 같은 닉네임은 2번 생성 안되도록 변경
be-student Mar 25, 2023
4e45eba
feat: 출력 메시지 추가
be-student Mar 25, 2023
3dae8ab
feat: request 에 getter 추가
be-student Mar 25, 2023
407caaf
feat: input 에 boardId, userID 설정 기능 추가
be-student Mar 25, 2023
8478b11
feat: 움직임을 바탕으로 게임 생성 기능 추가
be-student Mar 25, 2023
99cccd2
chore: T 타입 대신 Object 타입으로 변경
be-student Mar 25, 2023
809e70d
feat: controller 기능 추가
be-student Mar 25, 2023
0471a42
feat: 진행중인 유저가 본인인지 검증하는 기능 추가
be-student Mar 25, 2023
e26d6d3
feat: 종료된 게임에도 출력 가능하도록 변경
be-student Mar 25, 2023
ca3dac6
refactor: notStarted 추가
be-student Mar 25, 2023
e5556a4
refactor: 메서드 분리
be-student Mar 25, 2023
74c71c8
chore: 안 쓰이는 warning 제거
be-student Mar 25, 2023
70e7ed3
fix: 깨진 테스트 수정
be-student Mar 25, 2023
b887b77
feat: 멀티 쓰레드 적용
be-student Mar 25, 2023
953841c
feat: gitignore 작성
be-student Mar 31, 2023
706cae7
feat: docker 환경에서 sql 작성
be-student Mar 31, 2023
da8577e
feat: 안 쓰이는 코드 제거
be-student Mar 31, 2023
6b4e122
chore: 안 쓰이는 suppression 제거
be-student Mar 31, 2023
51191da
feat: dao 도커 환경에 맞게 변경
be-student Mar 31, 2023
9ce034d
feat: 발생할 수 있는 예외 커스텀으로 정의
be-student Mar 31, 2023
5097c93
feat: view 작성
be-student Mar 31, 2023
5b098cb
feat: mysql 패키지 이동
be-student Mar 31, 2023
3c04991
feat: service 작성
be-student Mar 31, 2023
484a1a4
feat: StatusType 으로 String 모아서 관리
be-student Mar 31, 2023
337fb98
refactor: 2번 사용되는 get 부분 변수로 분리
be-student Mar 31, 2023
edfcfe4
feat: 안 쓰이는 query 제거
be-student Mar 31, 2023
efea5ba
feat: controller 작성
be-student Mar 31, 2023
51b9ff1
refactor: turn 의 색을 계산하도록 변경
be-student Mar 31, 2023
8b11bd9
chore: 메서드명 변경
be-student Mar 31, 2023
a75623e
chore: static 변수와, 인스턴스 변수 사이에 개행 추가
be-student Mar 31, 2023
a64d29a
refactor: conroller 인터페이스를 통해 map 에서 한번에 관리하도록 변경
be-student Mar 31, 2023
9f40d23
fix: 리드미 최신화하기
be-student Mar 31, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ out/

### VS Code ###
.vscode/

docker/db/mysql/data
docker/db/config
122 changes: 118 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,121 @@
# java-chess
# 기능목록

체스 미션 저장소
## DB 정보

## 우아한테크코스 코드리뷰
chess 라는 schema 를 통해서 게임을 관리합니다

- [온라인 코드 리뷰 과정](https://github.com/woowacourse/woowacourse-docs/blob/master/maincourse/README.md)
## 2단계

- view
- [x] 사용자의 id 를 받는다
- [x] 사용자의 게임을 입력받는다

- controller
- [x] status를 입력할 경우 현재 게임의 상태를 출력한다
- [x] 사용자의 id를 입력받아 해당 id 에 해당하는 thread 를 통해서 게임을 진행한다

### 도메인

- dao
- 게임을 불러올 수 있다
- move 를 저장할 수 있다

- command
- [x] move 명령어를 입력받으면, 시작 위치와 끝 위치를 바탕으로 움직이게 한다
- [x] start 명령어를 입력받으면, 게임을 시작한다
- [x] end 명령어를 입력받으면, 게임을 종료한다
- query
- [x] 현재 게임 기물 위치를 출력한다
- [x] 현재 게임의 점수를 출력한다
- ScoreCalculator
- [x] 각 팀의 점수를 계산한다
- [x] 같은 file 에 있는 pawn 의 점수를 0.5점으로 계산한다
- turn
- [x] 턴을 관리한다
- piece
- [x] piece 에서 king 인지 여부를 확인한다
- board
- [x] board 에서 king 이 죽었는지 여부를 확인한다
- chessGame
- [x] 게임이 king 이 죽었을 때, 종료된다
- [x] dao 로부터 move 로부터 받은 정보를 불러올 수 있어야 한다

#### 인프라

- Connection 을 관리한다
- [x] 기본적으로 5개의 connection 을 가지고, 매 요청마다 다른 connection을 반환한다
- Thread 를 관리한다
- 기본적으로 5개의 thread 를 가지고, id 마다 하나의 쓰레드를 반환한다
- 쓰레드를 반환하면, 해당 쓰레드는 다시 재사용될 수 있다
- 5개가 넘는 thread 가 사용될 경우, 새로운 쓰레드를 생성한다
- 메인 쓰레드에서 동시에 thread get 요청을 할 수 있으니, lock 을 걸어준다

## 1단계

### 컨트롤러

- GameCommand
- [x] 게임 시작 커맨드는 "start"다.
- [x] 게임 종료 커맨드는 "end"다.
- [x] 체스 기물 이동 요청 커맨드는 "move 시작위치 이동위치" 이다.
- [x] 위치의 첫 번째 인자는 a~h까지 가능하다.
- [x] 위치의 두 번째 인자는 1~8까지 가능하다.

### 도메인

#### state

- InitialPawnState
- [x] 해당 위치에 아무 말이 없다면 앞으로 한 칸 혹은 두 칸을 갈 수 있다.
- [x] 해당 위치에 상대편 말이 있다면 대각 방향으로 한 칸 이동할 수 있다.

- MovedPawnState
- [x] 해당 위치에 아무 말이 없다면 앞으로 한 칸 갈 수 있다.
- [x] 해당 위치에 상대편 말이 있다면 대각 방향으로 한 칸 이동할 수 있다.

- KnightState
- [x] 해당 위치에 같은 색의 기물이 없으면 앞으로 한 칸 이동한 후 같은 방향 대각으로 한 칸 이동할 수 있다.
- [x] 다른 piece 가 중간에 있더라도 뛰어넘을 수 있다

- BishopState
- [x] 해당 위치에 같은 색의 기물이 없으면 대각 방향으로 원하는 만큼 이동할 수 있다.

- RookState
- [x] 해당 위치에 같은 색의 기물이 없으면 직선 방향으로 원하는 만큼 이동할 수 있다.

- QueenState
- [x] 해당 위치에 같은 색의 기물이 없으면 직선 방향으로 원하는 만큼 이동할 수 있다.
- [x] 해당 위치에 같은 색의 기물이 없으면 대각 방향으로 원하는 만큼 이동할 수 있다.

- KingState
- [x] 직선 혹은 대각 방향으로 한 칸 이동할 수 있다.

#### piece

- [x] 이름을 가진다.
- [x] 피스 타입을 가진다.
- [x] 움직임 전략을 가진다.

#### Position

- [x] File 과 Rank 를 갖는다.
- [x] 다른 포지션과의 Rank 순서 차이를 구할 수 있다.
- [x] 다른 포지션과의 File 순서 차이를 구할 수 있다.
- [x] 다른 포지션과의 직선 경로 Position 을 얻을 수 있다.
- [예외] 직선이 아니면 예외가 발생한다.

#### Board

- [x] Piece 들의 위치를 초기화 한다.
- [x] 보드는 자신의 판 정보를 반환할 수 있다.
- [x] 시작 Position 과 목표 Position 를 입력하면 Piece를 움직일 수 있다.

### 뷰

#### InputView

- [x] start 와 end 를 입력 받는다.

#### OutputView

- [x] 체스판을 출력한다.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ repositories {
}

dependencies {
implementation 'com.sparkjava:spark-core:2.9.3'
implementation 'com.sparkjava:spark-template-handlebars:2.7.1'
implementation 'ch.qos.logback:logback-classic:1.2.10'
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'

runtimeOnly 'mysql:mysql-connector-java:8.0.28'
}

java {
Expand Down
21 changes: 21 additions & 0 deletions docker/db/mysql/init/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE user
(
id INT AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(100) NOT NULL
);

CREATE TABLE board
(
id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(100),
status VARCHAR(10) NOT NULL
);

CREATE TABLE move
(
id INT AUTO_INCREMENT PRIMARY KEY,
board_id INT,
origin VARCHAR(10) NOT NULL,
destination VARCHAR(10) NOT NULL,
turn INT NOT NULL
);
18 changes: 18 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.9"
services:
db:
image: mysql:8.0.28
platform: linux/x86_64
restart: always
ports:
- "13306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: chess
MYSQL_USER: user
MYSQL_PASSWORD: password
TZ: Asia/Seoul
volumes:
- ./db/mysql/data:/var/lib/mysql
- ./db/mysql/config:/etc/mysql/conf.d
- ./db/mysql/init:/docker-entrypoint-initdb.d
13 changes: 13 additions & 0 deletions src/main/java/chess/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package chess;

import chess.controller.ControllerFactory;
import chess.controller.main.MainController;

public class Application {

public static void main(String[] args) {
ControllerFactory controllerFactory = ControllerFactory.getInstance();
MainController mainController = controllerFactory.getMainController();
mainController.run();
}
}
22 changes: 0 additions & 22 deletions src/main/java/chess/WebApplication.java

This file was deleted.

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

import chess.controller.main.Request;

public interface Controller {

void run(Request request);
}
72 changes: 72 additions & 0 deletions src/main/java/chess/controller/ControllerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package chess.controller;

import chess.controller.game.end.EndController;
import chess.controller.game.games.GamesController;
import chess.controller.game.move.MoveController;
import chess.controller.game.start.StartController;
import chess.controller.game.status.StatusController;
import chess.controller.main.ActionType;
import chess.controller.main.CommandMapper;
import chess.controller.main.MainController;
import chess.controller.room.create.CreateRoomController;
import chess.controller.room.join.JoinBoardController;
import chess.controller.user.LoginController;
import chess.service.ServiceFactory;
import chess.view.ViewFactory;
import java.util.Map;

public class ControllerFactory {

private static final ControllerFactory instance = new ControllerFactory();

private final StartController startController;
private final EndController endController;
private final MainController mainController;
private final MoveController moveController;
private final StatusController statusController;
private final GamesController gamesController;
private final CreateRoomController createRoomController;
private final JoinBoardController joinBoardController;
private final LoginController loginController;

private ControllerFactory() {
ServiceFactory serviceFactory = ServiceFactory.getInstance();
startController = new StartController(serviceFactory.getStartChessGameService());
endController = new EndController(serviceFactory.getEndChessGameService());
ViewFactory viewFactory = ViewFactory.getInstance();
moveController = new MoveController(serviceFactory.getMoveChessGameService(),
serviceFactory.getLoadChessGameService(), viewFactory.getBoardOutput());
statusController = new StatusController(viewFactory.getStatusOutput(),
serviceFactory.getStatusChessGameService());
gamesController = new GamesController(serviceFactory.getGamesService(), viewFactory.getGamesOutput());
createRoomController = new CreateRoomController(serviceFactory.getCreateRoomService(),
viewFactory.getCreateRoomOutput());
joinBoardController = new JoinBoardController(viewFactory.getJoinBoard(), viewFactory.getJoinBoardOutput(),
serviceFactory.getLoadChessGameService(), viewFactory.getBoardOutput());
loginController = new LoginController(viewFactory.getLogin(), viewFactory.getLoginOutput(),
serviceFactory.getLoginService());
mainController = new MainController(createCommandMapper(), viewFactory.getErrorOutput(),
viewFactory.getInputView(), viewFactory.getInitialOutput());
}

public static ControllerFactory getInstance() {
return instance;
}

private CommandMapper createCommandMapper() {
return new CommandMapper(Map.of(
ActionType.START, startController,
ActionType.END, endController,
ActionType.MOVE, moveController,
ActionType.STATUS, statusController,
ActionType.GAMES, gamesController,
ActionType.CREATE, createRoomController,
ActionType.JOIN, joinBoardController,
ActionType.LOGIN, loginController
));
}

public MainController getMainController() {
return mainController;
}
}
6 changes: 6 additions & 0 deletions src/main/java/chess/controller/ErrorOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package chess.controller;

public interface ErrorOutput {

void printError(String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chess.controller.exception;

public class BoardNotFoundException extends RuntimeException {

public BoardNotFoundException() {
super("방 잘못된 방번호를 입력하셨습니다 -join [방 번호] 형식으로 입력해주세요. -games 로 방 목록을 확인할 수 있습니다.");
}
}
8 changes: 8 additions & 0 deletions src/main/java/chess/controller/exception/LoginException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chess.controller.exception;

public class LoginException extends RuntimeException {

public LoginException() {
super("로그인이 필요합니다. login [id] 형식으로 입력해주세요.");
}
}
9 changes: 9 additions & 0 deletions src/main/java/chess/controller/game/BoardOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package chess.controller.game;

import chess.view.resposne.PieceResponse;
import java.util.List;

public interface BoardOutput {

void printBoard(List<List<PieceResponse>> boardResponse);
}
20 changes: 20 additions & 0 deletions src/main/java/chess/controller/game/end/EndController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package chess.controller.game.end;

import chess.controller.Controller;
import chess.controller.main.Request;
import chess.service.game.EndChessGameService;

public class EndController implements Controller {

private final EndChessGameService endChessGameService;

public EndController(EndChessGameService endChessGameService) {
this.endChessGameService = endChessGameService;
}

@Override
public void run(Request request) {
EndRequest endRequest = EndRequest.from(request);
endChessGameService.end(endRequest.getBoardId());
}
}
28 changes: 28 additions & 0 deletions src/main/java/chess/controller/game/end/EndRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package chess.controller.game.end;

import chess.controller.exception.BoardNotFoundException;
import chess.controller.exception.LoginException;
import chess.controller.main.Request;

public class EndRequest {

private final int boardId;

private EndRequest(int boardId) {
this.boardId = boardId;
}

public static EndRequest from(Request request) {
if (request.getUserId().isEmpty()) {
throw new LoginException();
}
if (request.getBoardId().isEmpty()) {
throw new BoardNotFoundException();
}
return new EndRequest(request.getBoardId().get());
}

int getBoardId() {
return boardId;
}
}
Loading