Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
61f7968
docs : ์ถ”๊ฐ€๋œ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ ๋ฌธ์„œ ์ž‘์„ฑ
softmoca Apr 1, 2026
ec9c5be
test(Palace) : ๊ถ์„ฑ ์˜์—ญ ๋ฐ ๋Œ€๊ฐ์„  ์ด๋™ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
softmoca Apr 1, 2026
ceb1b80
feat(Palace) : ๊ถ์„ฑ ์˜์—ญ ์ •์˜ ๋ฐ ๋Œ€๊ฐ์„ฑ ์ด๋™ ๊ธฐ๋Šฅ ๊ตฌํ˜„
softmoca Apr 1, 2026
1fa07f0
test : ๊ถ์„ฑ์ด๋™ ๊ทœ์น™ ํ…Œ์ŠคํŠธ
softmoca Apr 1, 2026
148e779
feat: ์žฅ,์‚ฌ ๊ถ์„ฑ ์ด๋™ ๊ทœ์น™ ์ถ”๊ฐ€ ์ ์šฉ
softmoca Apr 1, 2026
8a9bd7b
refactor: MoveRule์—์„œ Palace ์ง์ ‘ ์˜์กด ์ œ๊ฑฐ
softmoca Apr 2, 2026
24773e8
refactor: PalaceMoveRule ์ œ๊ฑฐ ๋ฐ ์žฅ/์‚ฌ์˜ ์ด๋™ ๊ทœ์น™์„ ๊ฐ ๊ธฐ๋ฌผ๋กœ ๋ถ„๋ฆฌ
softmoca Apr 2, 2026
ec987d6
feat: ์ฐจ ๊ถ์„ฑ ๋Œ€๊ฐ์„  ์ด๋™ ๊ทœ์น™ ์ถ”๊ฐ€
softmoca Apr 2, 2026
ebbfc8f
test : ๊ถ์„ฑ ์ด๋™ ๊ทœ์น™ ์‹คํŒจ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
softmoca Apr 2, 2026
2dff7db
feat: ํฌ ๊ถ์„ฑ ๋Œ€๊ฐ์„  ์ด๋™ ๊ทœ์น™ ์ถ”๊ฐ€
softmoca Apr 2, 2026
6082531
feat : ์กธ ๊ถ์„ฑ ๋Œ€๊ฐ์„ฑ ์ด๋™ ๊ทœ์น™ ์ถ”๊ฐ€
softmoca Apr 2, 2026
38ace55
feat: ์™• ์žกํž˜ ์‹œ ๊ฒŒ์ž„ ์ข…๋ฃŒ ๊ธฐ๋Šฅ๊ตฌํ˜„
softmoca Apr 2, 2026
d766f80
feat: ๊ธฐ๋ฌผ ์ ์ˆ˜ ๊ณ„์‚ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„
softmoca Apr 2, 2026
732fc7f
docs : 2-1๋‹จ๊ณ„ ๊ธฐ๋Šฅ๊ตฌํ˜„ ๋ชฉ๋ก ์—…๋ฐ์ดํŠธ ๋ฐ 2-2 ๊ธฐ๋Šฅ๊ตฌํ˜„ ๋ชฉ๋ก ์ถ”๊ฐ€
softmoca Apr 2, 2026
0bc0f2e
feat: DB ์—ฐ๊ฒฐ ์„ค์ •
softmoca Apr 3, 2026
1467302
feat: DB ํ…Œ์ด๋ธ” ์„ค๊ณ„
softmoca Apr 3, 2026
bb8dedc
feat : ๊ฒŒ์ž„๊ด€๋ จ ์ €์žฅ ๊ธฐ๋Šฅ ๊ตฌํ˜„
softmoca Apr 3, 2026
cc36c63
feat : ๊ธฐ๋ฌผ ์ €์žฅ ๊ด€๋ จ ๊ธฐ๋Šฅ ๊ตฌํ˜„
softmoca Apr 3, 2026
f3b7634
feat : ๊ฒŒ์ž„ ์ €์žฅ ๋ฐ ์ด์–ดํ•˜๊ธฐ ์ปจํŠธ๋กค๋Ÿฌ ๋ฐ ์ž…์ถœ๋ ฅ ๋ฐ˜์˜
softmoca Apr 3, 2026
2b62466
test : DB ๊ด€๋ จ ๊ธฐ๋Šฅ๋“ค ํ…Œ์ŠคํŠธ
softmoca Apr 3, 2026
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/

# SQLite
*.db
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,100 @@
- [X] ํƒ€ ์ง„์˜ ๊ธฐ๋ฌผ ์„ ํƒ ์‹œ ์˜ˆ์™ธ
- [X] ๋นˆ ์นธ ์„ ํƒ์‹œ ์˜ˆ์™ธ
- [X] ๋„์ฐฉ ์ง€์ ์— ์•„๊ตฐ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ

## 2.1๋‹จ๊ณ„ - ๊ธฐ๋ฌผ์˜ ํ™•์žฅ

### ๊ถ์„ฑ ์˜์—ญ ์ •์˜

- [x] ๊ถ์„ฑ(ๅฎฎๅŸŽ) ์˜์—ญ ์ •์˜
- ๊ถ์„ฑ ์ขŒํ‘œ ๋ฒ”์œ„ ์ •์˜
- [x] ๊ถ์„ฑ ๋‚ด ๋Œ€๊ฐ์„  ๊ฒฝ๋กœ ์ •์˜
- ๊ถ์„ฑ์—๋Š” ๋Œ€๊ฐ์„  ์„ ์ด ์กด์žฌํ•˜๋ฉฐ, ๋Œ€๊ฐ์„  ์ด๋™์€ ์ด ์„  ์œ„์˜ ์ขŒํ‘œ์—์„œ๋งŒ ๊ฐ€๋Šฅ
- ๋Œ€๊ฐ์„  ํ—ˆ์šฉ ์ขŒํ‘œ์Œ ์ •์˜
- [x] ํŠน์ • ์ขŒํ‘œ๊ฐ€ ๊ถ์„ฑ ๋‚ด๋ถ€์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๊ธฐ๋Šฅ
- [x] ๋‘ ์ขŒํ‘œ ๊ฐ„ ๊ถ์„ฑ ๋Œ€๊ฐ์„  ์ด๋™ ๊ฐ€๋Šฅ ์—ฌ๋ถ€ ํŒ๋ณ„

### ๊ถ์„ฑ ๊ด€๋ จ ๊ธฐ๋ฌผ ์ด๋™ ๊ทœ์น™ ๋ณ€๊ฒฝ ๋ฐ ์ถ”๊ฐ€

- [x] ์žฅ(King)
- ๊ถ์„ฑ ๋‚ด๋ถ€์—์„œ๋งŒ ์ด๋™ ๊ฐ€๋Šฅ
- ์ƒํ•˜์ขŒ์šฐ 1์นธ ์ด๋™ (๊ธฐ์กด ์œ ์ง€)
- ๊ถ์„ฑ ๋Œ€๊ฐ์„  ๊ฒฝ๋กœ์—์„œ ๋Œ€๊ฐ์„  1์นธ ์ด๋™ ๊ฐ€๋Šฅ
- [x] ์‚ฌ(Advisor)
- ๊ถ์„ฑ ๋‚ด๋ถ€์—์„œ๋งŒ ์ด๋™ ๊ฐ€๋Šฅ
- ์ƒํ•˜์ขŒ์šฐ 1์นธ ์ด๋™ (๊ธฐ์กด ์œ ์ง€)
- ๊ถ์„ฑ ๋Œ€๊ฐ์„  ๊ฒฝ๋กœ์—์„œ ๋Œ€๊ฐ์„  1์นธ ์ด๋™ ๊ฐ€๋Šฅ
- [x] ์ฐจ(Tank)
- ๊ธฐ์กด ์ง์„  ์ด๋™ ๊ทœ์น™ ์œ ์ง€
- ๊ถ์„ฑ ๋‚ด๋ถ€์—์„œ ๋Œ€๊ฐ์„  ๊ฒฝ๋กœ ์ด๋™ ๊ฐ€๋Šฅ
- [x] ํฌ(Cannon)
- ๊ธฐ์กด ์ง์„  + 1๊ฐœ ๊ธฐ๋ฌผ ๋„˜๊ธฐ ๊ทœ์น™ ์œ ์ง€
- ๊ถ์„ฑ ๋‚ด๋ถ€์—์„œ ๋Œ€๊ฐ์„  ๊ฒฝ๋กœ ์ด๋™ ๊ฐ€๋Šฅ
- [x] ์กธ(Soldier)
- ๊ธฐ์กด ์ „์ง„ + ์ขŒ์šฐ ์ด๋™ ์œ ์ง€
- ๊ถ์„ฑ ๋‚ด๋ถ€์—์„œ ๋Œ€๊ฐ์„  "์ „์ง„" ์ด๋™ ๊ฐ€๋Šฅ
- ํ›„์ง„ ๋Œ€๊ฐ์„  ๋ถˆ๊ฐ€

### ์™• ์žกํž˜ ์‹œ ๊ฒŒ์ž„ ์ข…๋ฃŒ

- [x] ์ด๋™ ๊ฒฐ๊ณผ ๋„์ฐฉ ์นธ์˜ ๊ธฐ๋ฌผ์ด ์™•(King)์ธ์ง€ ํŒ๋ณ„
- [x] ์™•์ด ์žกํ˜”์„ ๋•Œ ์Šน์ž ์ง„์˜ ๊ฒฐ์ •
- [x] JanggiGame์— ๊ฒŒ์ž„ ์ข…๋ฃŒ ์ƒํƒœ ๋ฐ˜์˜

### ์ ์ˆ˜ ๊ณ„์‚ฐ

- [x] Piece์— `score()` ์ถ”์ƒ ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
- [x] ๊ธฐ๋ฌผ๋ณ„ ์ ์ˆ˜ ์ •์˜
- [x] Board์—์„œ ํŠน์ • ์ง„์˜ ์ ์ˆ˜ ํ•ฉ์‚ฐ ๊ธฐ๋Šฅ
- [x] ์–‘ ์ง„์˜ ์ ์ˆ˜ ์กฐํšŒ ๊ธฐ๋Šฅ

## 2.2๋‹จ๊ณ„ - DB ์ ์šฉ

### 1. DB ์—ฐ๊ฒฐ ์„ค์ •

- [ ] SQLite JDBC ์˜์กด์„ฑ ์ถ”๊ฐ€
- [ ] DB ์—ฐ๊ฒฐ ๊ด€๋ฆฌ ํด๋ž˜์Šค ์ƒ์„ฑ

### 2. ํ…Œ์ด๋ธ” ์„ค๊ณ„ ๋ฐ ์ ์šฉ

- [ ] game ํ…Œ์ด๋ธ” โ€” ๊ฒŒ์ž„ ๋ฉ”ํƒ€ ์ •๋ณด
- [ ] piece ํ…Œ์ด๋ธ” โ€” ๊ธฐ๋ฌผ ๋ฐฐ์น˜ ์ •๋ณด

### 3. GameRepository ๊ตฌํ˜„

- [ ] save
- ์ƒˆ ๊ฒŒ์ž„ ์ƒ์„ฑ
- ์ƒ์„ฑ๋œ gameID ๋ฐ˜ํ™˜
- [ ] findById
- ํŠน์ • ๊ฒŒ์ž„ ์กฐํšŒ
- [ ] findPlayingGames
- ์ง„ํ–‰ ์ค‘์ธ ๊ฒŒ์ž„ ๋ชฉ๋ก ์กฐํšŒ
- [ ] updateTurn
- ํ„ด ๋ณ€๊ฒฝ ์‹œ ๊ฐฑ์‹ 
- [ ] updateFinished
- ๊ฒŒ์ž„ ์ข…๋ฃŒ ์‹œ ๊ฐฑ์‹ 

### 4. PieceRepository ๊ตฌํ˜„

- [ ] saveAll
- ๊ฒŒ์ž„์˜ ๋ชจ๋“  ๊ธฐ๋ฌผ์„ DB์— ์ผ๊ด„ ์ €์žฅ

- [ ] findByGameId
- ํŠน์ • ๊ฒŒ์ž„์˜ ๋ชจ๋“  ๊ธฐ๋ฌผ ์กฐํšŒ

- [ ] movePiece
- ๊ธฐ๋ฌผ ์ด๋™ ๋ฐ˜์˜
- ๋„์ฐฉ ์นธ ๊ธฐ๋ฌผ ์‚ญ์ œ
- ์ถœ๋ฐœ ์นธ ๊ธฐ๋ฌผ ์ขŒํ‘œ ๊ฐฑ์‹ 

### 5. Controller ํ๋ฆ„ ๋ณ€๊ฒฝ (์ƒˆ ๊ฒŒ์ž„ / ์ด์–ดํ•˜๊ธฐ)

- [ ] ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ์‹œ
- DB์—์„œ ์ง„ํ–‰ ์ค‘์ธ ๊ฒŒ์ž„ ๋ชฉ๋ก ์กฐํšŒ
- ์กด์žฌํ•˜๋ฉด โ†’ ์ด์–ดํ•˜๊ธฐ / ์ƒˆ ๊ฒŒ์ž„ ์„ ํƒ
- ์—†์œผ๋ฉด โ†’ ์ƒˆ ๊ฒŒ์ž„ ์‹œ์ž‘
- [ ] ๋งค ํ„ด ์ด๋™ ํ›„
- DB์— ๊ธฐ๋ฌผ ์ด๋™ ๋ฐ˜์˜
- DB์— ํ„ด ๋ณ€๊ฒฝ ๋ฐ˜์˜
- [ ] ๊ฒŒ์ž„ ์ข…๋ฃŒ ์‹œ
- DB์— ๊ฒŒ์ž„ ์ข…๋ฃŒ ์ƒํƒœ ๋ฐ˜์˜
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repositories {
}

dependencies {
implementation 'org.xerial:sqlite-jdbc:3.45.1.0'
implementation 'org.slf4j:slf4j-simple:2.0.12'

testImplementation platform('org.junit:junit-bom:5.11.4')
testImplementation platform('org.assertj:assertj-bom:3.27.3')
testImplementation('org.junit.jupiter:junit-jupiter')
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/janggi/Application.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package janggi;

import janggi.controller.JanggiController;
import janggi.infrastructure.DBInitializer;

public class Application {
public static void main(String[] args) {
DBInitializer.initialize();
JanggiController janggiController = new JanggiController();
janggiController.run();
}
Expand Down
84 changes: 76 additions & 8 deletions src/main/java/janggi/controller/JanggiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,111 @@
import janggi.domain.Board;
import janggi.domain.JanggiGame;
import janggi.domain.dto.MoveCommand;
import janggi.domain.piece.Piece;
import janggi.domain.piece.Team;
import janggi.domain.vo.Position;
import janggi.repository.GameRepository;
import janggi.repository.PieceRepository;
import janggi.view.InputView;
import janggi.view.OutputView;
import java.util.List;

public class JanggiController {

private final InputView inputView = new InputView();
private final OutputView outputView = new OutputView();
private final GameRepository gameRepository = new GameRepository();
private final PieceRepository pieceRepository = new PieceRepository();

private JanggiGame janggiGame;
private Board board;

public void run() {
Board board = new Board();
initialize();
playGame();
printResult();
}

private void initialize() {
List<JanggiGame> playingGames = gameRepository.findPlayingGames();

JanggiGame janggiGame = new JanggiGame();
if (playingGames.isEmpty()) {
startNewGame();
return;
}

int choice = inputView.readGameChoice(playingGames);
if (choice == playingGames.size() + 1) {
startNewGame();
return;
}

resumeGame(playingGames.get(choice - 1));
}

private void startNewGame() {
janggiGame = new JanggiGame();
Long gameId = gameRepository.save(janggiGame);
janggiGame.assignId(gameId);

board = new Board();
pieceRepository.saveAll(gameId, board);

outputView.printGameStart(gameId);
}

private void resumeGame(JanggiGame game) {
janggiGame = game;
board = pieceRepository.findByGameId(game.findGameId());

outputView.printResume(game.findGameId(), game.findCurrentTeam());
}

private void playGame() {
while (!janggiGame.isFinished()) {
Team currentTeam = janggiGame.findCurrentTeam();
attemptMove(board, currentTeam);
janggiGame.changeTurn();
outputView.printCurrentTurn(currentTeam);
outputView.printBoard(board);
attemptMove(currentTeam);

if (!janggiGame.isFinished()) {
janggiGame.changeTurn();
gameRepository.updateTurn(janggiGame);
}
}
}

private void attemptMove(Board board, Team currentTeam) {
private void attemptMove(Team currentTeam) {
boolean moved = false;
while (!moved) {
moved = tryMove(board, currentTeam);
moved = tryMove(currentTeam);
}
}

private boolean tryMove(Board board, Team currentTeam) {
private boolean tryMove(Team currentTeam) {
try {
MoveCommand moveCommand = inputView.readMovePositions();
Position from = moveCommand.getFrom();
Position to = moveCommand.getTo();
board.move(from, to, currentTeam);

Piece captured = board.move(from, to, currentTeam);
pieceRepository.movePiece(janggiGame.findGameId(), from, to);

janggiGame.processCaptured(captured);
if (janggiGame.isFinished()) {
gameRepository.updateFinished(janggiGame);
}

return true;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
return false;
}
}

private void printResult() {
outputView.printGameEnd(janggiGame.findWinner());
outputView.printScore(Team.CHO, board.calculateScore(Team.CHO));
outputView.printScore(Team.HAN, board.calculateScore(Team.HAN));
}
}
56 changes: 55 additions & 1 deletion src/main/java/janggi/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import janggi.domain.piece.Piece;
import janggi.domain.piece.Team;
import janggi.domain.vo.Position;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -43,7 +44,27 @@ public boolean isEmptyPosition(Position position) {
return findByPosition(position).isEmpty();
}

public void move(Position from, Position to, Team currentTeam) {
@Override
public boolean isInsidePalace(Position position) {
return Palace.isInsidePalace(position);
}

@Override
public boolean canMoveDiagonallyInPalace(Position from, Position to) {
return Palace.canMoveDiagonally(from, to);
}

@Override
public boolean isDiagonalInPalace(Position from, Position to) {
return Palace.isDiagonalInPalace(from, to);
}

@Override
public Position getDiagonalMidpointInPalace(Position from, Position to) {
return Palace.getDiagonalMidpoint(from, to);
}

public Piece move(Position from, Position to, Team currentTeam) {
Piece fromPiece = findByPosition(from);
Piece toPiece = findByPosition(to);

Expand All @@ -55,6 +76,8 @@ public void move(Position from, Position to, Team currentTeam) {

place(from, new EmptyPosition(Team.OTHER));
place(to, fromPiece);

return toPiece;
}

private void place(Position position, Piece piece) {
Expand All @@ -75,4 +98,35 @@ private void validateCommonMove(Team currentTeam, Piece fromPiece, Piece toPiece
throw new IllegalArgumentException("์ด๋ฏธ ๋„์ฐฉ์ง€์ ์— ํ”Œ๋ ˆ์ด์–ด๋‹˜์˜ ์ง„์˜ ๊ธฐ๋ฌผ์ด ์žˆ์Šต๋‹ˆ๋‹ค.");
}
}

public int calculateScore(Team team) {
int totalScore = 0;
for (List<Piece> row : board) {
for (Piece piece : row) {
if (piece.isSameTeam(team)) {
totalScore += piece.score();
}
}
}
return totalScore;
}


// ๋นˆ๊ณณ์€ db์— ๋”ฐ๋กœ ์ €์žฅ์•ˆํ•˜๋ ค๋Š”๋ฐ....
// board ์ž๋ฃŒ๊ตฌ์กฐ ์ž์ฒด๊ฐ€ map์ด์—ˆ์œผ๋ฉด.....
public Map<Position, Piece> findAllPieces() {
Map<Position, Piece> pieces = new HashMap<>();
for (int row = 0; row < board.size(); row++) {
for (int col = 0; col < board.get(row).size(); col++) {
Position position = new Position(row, col);
Piece piece = findByPosition(position);
if (!piece.isEmpty()) {
pieces.put(position, piece);
}
}
}
return pieces;
}


}
8 changes: 8 additions & 0 deletions src/main/java/janggi/domain/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public interface BoardView {

boolean isEmptyPosition(Position position);

boolean isInsidePalace(Position position);

boolean canMoveDiagonallyInPalace(Position from, Position to);

boolean isDiagonalInPalace(Position from, Position to);

Position getDiagonalMidpointInPalace(Position from, Position to);

}
Loading