-
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단계 - 체스] 기론(김규철) 미션 제출합니다. #357
Changes from all commits
335590b
05c4241
90c0077
734d65d
66afd19
f2bf52e
18924f2
35cc84b
4d5594e
e69f383
f0cc4ec
04e8c0a
78409f9
4ee3400
9cdda01
98daf05
4c31338
38c36ec
516bdd1
8e37744
7567805
3e15f8b
2a30411
62b6fea
8fd34ae
bee6b51
b8f2615
b5500cb
0936db7
cbe22f2
df48432
64bcd98
eccf42b
580ce4c
31c0681
3534067
cdfc911
e87699e
bb0e2d7
ba580e6
4b62c8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,95 @@ | ||
CREATE TABLE member | ||
DROP TABLE IF EXISTS board; | ||
DROP TABLE IF EXISTS piece; | ||
|
||
CREATE TABLE board | ||
( | ||
id varchar(10) not null, | ||
name varchar(20) not null, | ||
id INT(10) not null AUTO_INCREMENT , | ||
turn VARCHAR (5) not null, | ||
primary key (id) | ||
); | ||
|
||
CREATE TABLE role | ||
INSERT INTO board (turn) VALUES ("white"); | ||
|
||
CREATE TABLE piece | ||
( | ||
member_id varchar(10) not null, | ||
role varchar(10) not null, | ||
primary key (member_id), | ||
foreign key (member_id) references member (id) | ||
id INT(10) not null AUTO_INCREMENT, | ||
board_id INT(10), | ||
position CHAR(2), | ||
type VARCHAR (20) not null, | ||
team VARCHAR (10) not null, | ||
foreign key (board_id) references board (id) ON DELETE CASCADE , | ||
primary key (id) | ||
); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a1", 1, "rook", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b1", 1, "knight", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c1", 1, "bishop", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d1", 1, "queen", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e1", 1, "king", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f1", 1, "bishop", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g1", 1, "knight", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h1", 1, "rook", "white"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g2", 1, "pawn", "white"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h2", 1, "pawn", "white"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g3", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h3", 1, "empty", "none"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g4", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h4", 1, "empty", "none"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g5", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h5", 1, "empty", "none"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g6", 1, "empty", "none"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h6", 1, "empty", "none"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g7", 1, "pawn", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h7", 1, "pawn", "black"); | ||
|
||
INSERT INTO piece (position, board_id, type, team) VALUES ("a8", 1, "rook", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("b8", 1, "knight", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("c8", 1, "bishop", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("d8", 1, "queen", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("e8", 1, "king", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("f8", 1, "bishop", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("g8", 1, "knight", "black"); | ||
INSERT INTO piece (position, board_id, type, team) VALUES ("h8", 1, "rook", "black"); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
package chess; | ||
|
||
import spark.ModelAndView; | ||
import spark.template.handlebars.HandlebarsTemplateEngine; | ||
import chess.web.controller.ChessWebController; | ||
import chess.web.service.ChessService; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static spark.Spark.get; | ||
import static spark.Spark.port; | ||
import static spark.Spark.staticFileLocation; | ||
|
||
public class WebApplication { | ||
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. 웹에서 한 게임을 완료한 후 정상적으로 게임을 재시작할 수 없네요 😂 관련 재현 영상은 용량이 큰 관계로 DM 으로 보내드릴게요! 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. board를 초기화 하고 piece들도 초기화 해야하는데 기존의 piece들의 position을 수정하지 않고 새로운 초기화된 piece 64개를 만들어서 오류가 생겼었네요! initBoard()로직을 기존의 piece들의 position을 초기화하는 방식으로 수정했습니다! 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. 문제점을 파악하여 잘 수정해주셨네요! 좋습니다~! |
||
public static void main(String[] args) { | ||
get("/", (req, res) -> { | ||
Map<String, Object> model = new HashMap<>(); | ||
return render(model, "index.html"); | ||
}); | ||
} | ||
|
||
private static String render(Map<String, Object> model, String templatePath) { | ||
return new HandlebarsTemplateEngine().render(new ModelAndView(model, templatePath)); | ||
port(8080); | ||
staticFileLocation("static"); | ||
ChessWebController chessController = new ChessWebController(new ChessService()); | ||
chessController.run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
package chess; | ||
package chess.board; | ||
|
||
import chess.piece.Empty; | ||
import chess.piece.Piece; | ||
import chess.piece.Pieces; | ||
import chess.piece.position.Position; | ||
import chess.board.piece.Empty; | ||
import chess.board.piece.Piece; | ||
import chess.board.piece.Pieces; | ||
import chess.board.piece.position.Position; | ||
|
||
import java.util.List; | ||
|
||
public final class Board { | ||
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. 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.
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. 확인했어요~! |
||
|
||
private final Pieces pieces; | ||
private final Turn turn; | ||
|
||
private Board(Pieces pieces) { | ||
private Board(Pieces pieces, Turn turn) { | ||
this.pieces = pieces; | ||
this.turn = turn; | ||
} | ||
|
||
public static Board create(Pieces pieces) { | ||
return new Board(pieces); | ||
public static Board create(Pieces pieces, Turn turn) { | ||
return new Board(pieces, turn); | ||
} | ||
|
||
public Pieces getPieces() { | ||
return pieces; | ||
} | ||
|
||
public Turn getTurn() { | ||
return turn; | ||
} | ||
|
||
public void move(List<String> commandPosition, Turn thisTurn) { | ||
Position sourcePosition = getSource(commandPosition); | ||
Position targetPosition = getTarget(commandPosition); | ||
|
@@ -35,7 +41,7 @@ public void move(List<String> commandPosition, Turn thisTurn) { | |
} | ||
|
||
private void validateTurn(Turn thisTurn, Piece sourcePiece) { | ||
if (!sourcePiece.isCurrentTurn(thisTurn)) { | ||
if (sourcePiece.isNotCurrentTurn(thisTurn)) { | ||
throw new IllegalArgumentException("[ERROR] 현재 차례가 아닙니다."); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package chess.board; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum Team { | ||
BLACK(-1), | ||
WHITE(1), | ||
NONE(0), | ||
; | ||
|
||
private final int forwardDirection; | ||
|
||
Team(int forwardDirection) { | ||
this.forwardDirection = forwardDirection; | ||
} | ||
|
||
public static Team from(String name) { | ||
return Arrays.stream(values()) | ||
.filter(team -> team.value().equals(name)) | ||
.findFirst() | ||
.orElse(Team.NONE); | ||
} | ||
|
||
public String value() { | ||
return this.name().toLowerCase(); | ||
} | ||
|
||
public boolean isOpposingTeam(Team team) { | ||
return this.forwardDirection + team.forwardDirection == 0; | ||
} | ||
|
||
public int getForwardDirection() { | ||
return this.forwardDirection; | ||
} | ||
} |
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.
API 명세를 보기 좋도록 table을 활용하여 표현해볼까요?
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.
table을 사용하니 보기에 더 깔끔해졌네요 !
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.
고생하셨어요! 회사에 들어와보니 문서를 잘 작성하는 것도 능력이더라구요! 지금부터 조금씩 연습해보죠!
추가로 API 명세는 서버쪽에서 담당해야하는 책임이기에 읽기 좋게 만들어주면 협업할 때에 도움이 됩니다!
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.
좋은 말씀 감사합니다...진짜 최고에요 토니!
경험과 함께 말씀해주시니깐 완전 동기부여가 되네요😃
감사합니당