-
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
[1, 2, 3단계 - 체스] 기론(김규철) 미션 제출합니다. #295
Changes from all commits
6c8ca60
5fbb082
325f6ee
110c301
742ff00
9f5689e
10e5026
23e2261
27341e6
4a094b2
84c3914
649f8db
78e60ce
0447917
32e0cf8
62d79c0
cc548fe
0f6128e
4baa7d6
95abedd
d44b7f2
e2b867a
e9a9253
61b3ce2
754ff24
708d657
aadcce9
7bb3409
c235483
7f92619
a267622
0a4fead
2cd9b8b
daa63dc
58212d7
1283e48
5c6e0a8
afbbb7a
354e7bd
8e2d464
5a60cb1
7f111ef
40b2a1f
0e074b5
4f377c2
c0c53e8
3190f12
b7b3972
ad6e2bb
42df1b1
8235b85
6c770d0
6896212
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TABLE member | ||
( | ||
id varchar(10) not null, | ||
name varchar(20) not null, | ||
primary key (id) | ||
); | ||
|
||
CREATE TABLE role | ||
( | ||
member_id varchar(10) not null, | ||
role varchar(10) not null, | ||
primary key (member_id), | ||
foreign key (member_id) references member (id) | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3.9" | ||
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. docker-compose는 어떤 의도에서 추가하셨는지 궁금해요~! 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. 아 docker-compose는 오늘 수업 중에 실습 했던 내용입니다! 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. 오호 그런 배경이 있었군요! 해당 기술을 잘 익혀두시면 추후에 프로젝트할 때나 현업에 와서도 잘 활용하실 수 있을거에요! |
||
services: | ||
db: | ||
image: mysql:8.0.28 | ||
platform: linux/x86_64 | ||
restart: always | ||
ports: | ||
- "3306: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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package chess; | ||
|
||
import chess.piece.Empty; | ||
import chess.piece.Piece; | ||
import chess.piece.Pieces; | ||
import chess.piece.position.Position; | ||
|
||
import java.util.List; | ||
|
||
public final class Board { | ||
|
||
private final Pieces pieces; | ||
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. 체스판을 구현하는 여러가지 방법이 있을텐데요. 기론은 자신의 위치에 해당하는 정보를 들고 있는 각 기물들의 모음을 체스판으로 봤어요. 다른 방식으로 구현한다면 8X8의 체스판 자체를 이중 리스트나 맵 형식으로 구조화할 수도 있겠죠! 기론이 기론의 방식으로 구현하며 느낀 장점이나 단점이 있을까요? 다른 방식으로 구현한다면 어떤 장단점이 있을지도 상상해보면 재미있겠네요! 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. 처음엔 Map<Position, Piece>를 갖는
또한 장점으로는 아마 기존의 Map방식으로 사용한다면 생각하면 생각할수록 어렵네요🤔🤔 각각 트레이드오프가 있는 것 같습니다. 또한 토니는 제 생각에 대해서 어떻게 생각하시나요?
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 Board(Pieces pieces) { | ||
this.pieces = pieces; | ||
} | ||
|
||
public static Board create(Pieces pieces) { | ||
return new Board(pieces); | ||
} | ||
|
||
public Pieces getPieces() { | ||
return pieces; | ||
} | ||
|
||
public void move(List<String> commandPosition, Turn thisTurn) { | ||
Position sourcePosition = getSource(commandPosition); | ||
Position targetPosition = getTarget(commandPosition); | ||
|
||
Piece sourcePiece = pieces.findByPosition(sourcePosition); | ||
Piece targetPiece = pieces.findByPosition(targetPosition); | ||
validateTurn(thisTurn, sourcePiece); | ||
validateMovable(targetPosition, sourcePiece, targetPiece); | ||
move(sourcePosition, targetPosition, sourcePiece, targetPiece); | ||
} | ||
|
||
private void validateTurn(Turn thisTurn, Piece sourcePiece) { | ||
if (!sourcePiece.isCurrentTurn(thisTurn)) { | ||
throw new IllegalArgumentException("[ERROR] 현재 차례가 아닙니다."); | ||
} | ||
} | ||
|
||
private void validateMovable(Position targetPosition, Piece sourcePiece, Piece targetPiece) { | ||
if (isNotMovable(targetPosition, sourcePiece, targetPiece)) { | ||
throw new IllegalArgumentException("[ERROR] 움직일수 없습니다."); | ||
} | ||
} | ||
|
||
private boolean isNotMovable(Position targetPosition, Piece sourcePiece, Piece targetPiece) { | ||
return (!sourcePiece.isMovableRange(targetPosition) || hasBlock(sourcePiece, targetPiece)) && | ||
!sourcePiece.isKill(targetPiece); | ||
} | ||
|
||
private void move(Position sourcePosition, Position targetPosition, Piece sourcePiece, Piece targetPiece) { | ||
sourcePiece.moveTo(targetPosition); | ||
pieces.remove(targetPiece); | ||
pieces.add(new Empty(sourcePosition)); | ||
} | ||
|
||
private boolean hasBlock(Piece sourcePiece, Piece targetPiece) { | ||
if (sourcePiece.isSameTeam(targetPiece)) { | ||
return true; | ||
} | ||
List<Position> positions = sourcePiece.getIntervalPosition(targetPiece); | ||
return positions.stream() | ||
.anyMatch(position -> !pieces.findByPosition(position).equals(new Empty(position))); | ||
} | ||
|
||
private Position getSource(List<String> commandPosition) { | ||
return Position.of( | ||
commandPosition.get(0).charAt(0), | ||
commandPosition.get(0).charAt(1)); | ||
} | ||
|
||
private Position getTarget(List<String> commandPosition) { | ||
return Position.of( | ||
commandPosition.get(1).charAt(0), | ||
commandPosition.get(1).charAt(1) | ||
); | ||
} | ||
|
||
public boolean isDeadKing() { | ||
return pieces.countOfKing() == 1; | ||
} | ||
|
||
public double getWhiteTeamScore() { | ||
return pieces.getTotalScore(Team.WHITE); | ||
} | ||
|
||
public double getBlackTeamScore() { | ||
return pieces.getTotalScore(Team.BLACK); | ||
} | ||
|
||
public Team getWinTeam() { | ||
if (getWhiteTeamScore() > getBlackTeamScore()) { | ||
return Team.WHITE; | ||
} | ||
if (getBlackTeamScore() > getWhiteTeamScore()) { | ||
return Team.BLACK; | ||
} | ||
return Team.NONE; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package chess; | ||
|
||
import chess.controller.ChessController; | ||
|
||
public class ConsoleApplication { | ||
public static void main(String[] args) { | ||
ChessController chessController = new ChessController(); | ||
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. 명짤(?)이네요.. 저장해둬야겠습니다😁수정했습니다! |
||
chessController.run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package chess; | ||
|
||
public enum Team { | ||
BLACK(-1), | ||
WHITE(1), | ||
NONE(0), | ||
; | ||
|
||
private final int forwardDirection; | ||
|
||
Team(int forwardDirection) { | ||
this.forwardDirection = forwardDirection; | ||
} | ||
|
||
public int getForwardDirection() { | ||
return this.forwardDirection; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package chess; | ||
|
||
import java.util.Objects; | ||
|
||
public final class Turn { | ||
private final Team team; | ||
|
||
public Turn(Team team) { | ||
this.team = team; | ||
} | ||
|
||
public static Turn init() { | ||
return new Turn(Team.WHITE); | ||
} | ||
|
||
public boolean isCurrentTeam(Team team) { | ||
return this.team.equals(team); | ||
} | ||
|
||
public Turn change() { | ||
if (team.equals(Team.BLACK)) { | ||
return new Turn(Team.WHITE); | ||
} | ||
return new Turn(Team.BLACK); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Turn turn = (Turn) o; | ||
return team == turn.team; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(team); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package chess.command; | ||
|
||
import java.util.List; | ||
|
||
public abstract class Command implements State { | ||
|
||
protected final String input; | ||
|
||
public Command(String input) { | ||
validateCommand(input); | ||
this.input = input; | ||
} | ||
|
||
private void validateCommand(String input) { | ||
if (!input.contains("move") && !"start".equals(input) && !"end".equals(input) && !"status".equals(input)) { | ||
throw new IllegalArgumentException("[ERROR] 명령어는 start, move, end, status 중 하나여야합니다."); | ||
} | ||
} | ||
|
||
@Override | ||
public Command turnFinalState(String input) { | ||
return new End(input); | ||
} | ||
|
||
@Override | ||
public boolean isEnd() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isMove() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isStatus() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> getCommandPosition() { | ||
throw new IllegalStateException("[ERROR] 명령어에서 위치를 얻을수 없습니다."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package chess.command; | ||
|
||
public final class End extends Command { | ||
|
||
public End(String input) { | ||
super(input); | ||
} | ||
|
||
@Override | ||
public Command turnState(String input) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Command turnFinalState(String input) { | ||
if ("status".equals(input)) { | ||
return new Status(input); | ||
} | ||
return new End(input); | ||
} | ||
|
||
@Override | ||
public boolean isEnd() { | ||
return true; | ||
} | ||
} |
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.
DB가 붙는군요! 설레네요(?)
여기서 한가지 퀴즈~!
runtimeOnly와 implementation 그리고 testImplementation는 각각 어떤 의미로 build.gradle에서 사용될까요? 댓글로 남겨주세요!
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.
오 퀴즈는 언제나 설레네요 ㅎㅎㅎ
퀴즈 공부하면서 grdle의 의존성 옵션에 대해서 알아볼 수 있었습니다!
runtimeOnly
implementation
testImplementation
와 같이 정리했습니다!
정리글
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.
정리 잘 해주셨네요! 좋습니당 블로그 글도 확인했어요 기론은 글도 잘 작성하시는군요 👍