diff --git a/src/main/java/chess/controller/ChessController.java b/src/main/java/chess/controller/ChessController.java index 984701bc7a4..f5bb64d8294 100644 --- a/src/main/java/chess/controller/ChessController.java +++ b/src/main/java/chess/controller/ChessController.java @@ -1,7 +1,7 @@ package chess.controller; +import chess.controller.dto.TeamDto; import chess.domain.ChessRunner; -import chess.domain.piece.Team; import chess.view.ConsoleInputView; import chess.view.ConsoleOutputView; import chess.view.InputView; @@ -13,37 +13,39 @@ public class ChessController { private static OutputView outputView = new ConsoleOutputView(); public static void start() { - try { - runChessGame(); - } catch (IllegalArgumentException e) { - System.out.println(e.getMessage()); - start(); - } - } - - public static void runChessGame() { Command command = Command.of(inputView.askChessRun()); - if (command.isStart()) { ChessRunner chessRunner = new ChessRunner(); - GameController startController = command.getGameController(); - startController.execute(chessRunner, StringUtils.EMPTY); + GameController gameController = command.getGameController(); + gameController.execute(chessRunner, StringUtils.EMPTY); - do { - String commands = inputView.askGameCommand(); - command = Command.of(commands); - GameController gameController = command.getGameController(); - gameController.execute(chessRunner, commands); - } while (!command.isEnd() && findWinner(chessRunner)); + runChessGame(command, chessRunner); + } + } + + private static void runChessGame(Command command, ChessRunner chessRunner) { + do { + command = validateExecute(command, chessRunner); + } while (!command.isEnd() && !chessRunner.isEndChess()); + printWinner(chessRunner); + } + + private static Command validateExecute(Command command, ChessRunner chessRunner) { + try { + String commands = inputView.askGameCommand(); + command = Command.of(commands); + GameController gameController = command.getGameController(); + gameController.execute(chessRunner, commands); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); } + return command; } - private static boolean findWinner(final ChessRunner chessRunner) { - Team winner = chessRunner.findWinner(); - if (winner != null) { - outputView.printWinner(winner); - return false; + private static void printWinner(ChessRunner chessRunner) { + if (chessRunner.isEndChess()) { + TeamDto teamDto = new TeamDto(chessRunner.getWinner()); + outputView.printWinner(teamDto.getTeamName()); } - return true; } } diff --git a/src/main/java/chess/controller/EndController.java b/src/main/java/chess/controller/EndController.java index 5447a5811c3..0beb80032d8 100644 --- a/src/main/java/chess/controller/EndController.java +++ b/src/main/java/chess/controller/EndController.java @@ -9,6 +9,5 @@ public EndController() { @Override public void execute(ChessRunner chessRunner, String input) { - return; } } diff --git a/src/main/java/chess/controller/GameController.java b/src/main/java/chess/controller/GameController.java index 1bab9902963..ce494b93043 100644 --- a/src/main/java/chess/controller/GameController.java +++ b/src/main/java/chess/controller/GameController.java @@ -3,11 +3,12 @@ import chess.controller.dto.BoardDto; import chess.controller.dto.PositionDto; import chess.domain.ChessRunner; -import chess.domain.board.Board; import chess.domain.position.Position; import chess.view.ConsoleOutputView; import chess.view.OutputView; +import java.util.Map; + public abstract class GameController { protected final OutputView outputView; @@ -15,8 +16,8 @@ public GameController() { this.outputView = new ConsoleOutputView(); } - protected void printBoard(final Board board) { - BoardDto boardDto = new BoardDto(board.parse()); + protected void printBoard(final Map board) { + BoardDto boardDto = new BoardDto(board); PositionDto positionDto = new PositionDto(Position.getPositions()); this.outputView.printBoard(positionDto.getPositions(), boardDto.get()); } diff --git a/src/main/java/chess/controller/MoveController.java b/src/main/java/chess/controller/MoveController.java index 6613c3b2e70..4bc52b69329 100644 --- a/src/main/java/chess/controller/MoveController.java +++ b/src/main/java/chess/controller/MoveController.java @@ -4,6 +4,7 @@ public class MoveController extends GameController { private static final String DELIMITER = " "; + private static final int COMMANDS_SIZE = 2; private static final int SOURCE_INDEX = 1; private static final int TARGET_INDEX = 2; @@ -14,9 +15,13 @@ public MoveController() { @Override public void execute(ChessRunner chessRunner, String input) { String[] commands = input.split(DELIMITER); + if (commands.length < COMMANDS_SIZE) { + throw new IllegalArgumentException("잘못된 이동 명령어를 입력하였습니다."); + } + String source = commands[SOURCE_INDEX]; String target = commands[TARGET_INDEX]; chessRunner.update(source, target); - printBoard(chessRunner.getBoard()); + printBoard(chessRunner.getBoardEntities()); } } diff --git a/src/main/java/chess/controller/StartController.java b/src/main/java/chess/controller/StartController.java index 7ce8debfbac..d952290efec 100644 --- a/src/main/java/chess/controller/StartController.java +++ b/src/main/java/chess/controller/StartController.java @@ -9,6 +9,6 @@ public StartController() { @Override public void execute(ChessRunner chessRunner, String input) { - printBoard(chessRunner.getBoard()); + printBoard(chessRunner.getBoardEntities()); } } diff --git a/src/main/java/chess/controller/StatusController.java b/src/main/java/chess/controller/StatusController.java index 76c3613c5cb..1b950eccbc9 100644 --- a/src/main/java/chess/controller/StatusController.java +++ b/src/main/java/chess/controller/StatusController.java @@ -1,5 +1,7 @@ package chess.controller; +import chess.controller.dto.BoardScoreDto; +import chess.controller.dto.TeamDto; import chess.domain.ChessRunner; public class StatusController extends GameController { @@ -9,8 +11,9 @@ public StatusController() { @Override public void execute(ChessRunner chessRunner, String input) { - double score = chessRunner.calculateScore(); - outputView.printStatus(score, chessRunner.getCurrentTeam()); - printBoard(chessRunner.getBoard()); + BoardScoreDto boardScoreDto = new BoardScoreDto(chessRunner.calculateScore()); + TeamDto teamDto = new TeamDto(chessRunner.getCurrentTeam()); + outputView.printStatus(boardScoreDto.getBoardScore(), teamDto.getTeamName()); + printBoard(chessRunner.getBoardEntities()); } } diff --git a/src/main/java/chess/controller/dto/BoardScoreDto.java b/src/main/java/chess/controller/dto/BoardScoreDto.java new file mode 100644 index 00000000000..d7e457a2076 --- /dev/null +++ b/src/main/java/chess/controller/dto/BoardScoreDto.java @@ -0,0 +1,13 @@ +package chess.controller.dto; + +public class BoardScoreDto { + private final double boardScore; + + public BoardScoreDto(double boardScore) { + this.boardScore = boardScore; + } + + public double getBoardScore() { + return boardScore; + } +} diff --git a/src/main/java/chess/controller/dto/TeamDto.java b/src/main/java/chess/controller/dto/TeamDto.java new file mode 100644 index 00000000000..073908e98f8 --- /dev/null +++ b/src/main/java/chess/controller/dto/TeamDto.java @@ -0,0 +1,13 @@ +package chess.controller.dto; + +public class TeamDto { + private final String teamName; + + public TeamDto(final String teamName) { + this.teamName = teamName; + } + + public String getTeamName() { + return teamName; + } +} diff --git a/src/main/java/chess/domain/ChessRunner.java b/src/main/java/chess/domain/ChessRunner.java index 3a8845d409d..4652a0e677b 100644 --- a/src/main/java/chess/domain/ChessRunner.java +++ b/src/main/java/chess/domain/ChessRunner.java @@ -1,9 +1,15 @@ package chess.domain; import chess.domain.board.Board; +import chess.domain.board.BoardScore; import chess.domain.piece.Piece; import chess.domain.piece.Team; import chess.domain.position.Position; +import chess.domain.strategy.direction.Direction; + +import java.util.List; +import java.util.Map; +import java.util.Optional; public class ChessRunner { private Board board; @@ -17,17 +23,57 @@ public ChessRunner() { public void update(String source, String target) { Position sourcePosition = Position.of(source); Position targetPosition = Position.of(target); - Piece selectedPiece = this.board.getPiece(sourcePosition); + Piece sourcePiece = this.board.getPiece(sourcePosition); + + checkCorrectTurn(sourcePiece); + checkUpdateBoard(sourcePosition, targetPosition, sourcePiece); - if (!(currentTeam.isSameTeamWith(selectedPiece.getTeam()))) { + updateBoard(sourcePosition, targetPosition); + changeTeam(); + } + + private void checkCorrectTurn(Piece sourcePiece) { + if (sourcePiece.isEnemy(this.currentTeam)) { throw new IllegalArgumentException("현재 차례가 아닙니다."); } + } + + private void checkUpdateBoard(Position sourcePosition, Position targetPosition, Piece sourcePiece) { + if (isSamePosition(sourcePosition, targetPosition)) { + throw new IllegalArgumentException("같은 위치로 이동할 수 없습니다."); + } - if (!(selectedPiece.movable(sourcePosition, targetPosition, board))) { - throw new IllegalArgumentException("이동할 수 없는 곳입니다."); + if (!(sourcePiece.movable(sourcePosition, targetPosition))) { + throw new IllegalArgumentException("선택한 기물이 이동할 수 없는 곳입니다."); } - updateBoard(sourcePosition, targetPosition); - changeTeam(); + + if (!isEmptyPath(sourcePosition, targetPosition)) { + throw new IllegalArgumentException("경로 사이에 장애물이 있습니다."); + } + + if (!isMovableTarget(sourcePiece, targetPosition)) { + throw new IllegalArgumentException("목적지가 잘못되었습니다."); + } + } + + private boolean isSamePosition(final Position sourcePosition, final Position targetPosition) { + return sourcePosition.equals(targetPosition); + } + + private boolean isEmptyPath(final Position sourcePosition, final Position targetPosition) { + Direction direction = Direction.findDirection(sourcePosition, targetPosition); + List path = direction.findPath(sourcePosition, targetPosition); + + if (path.isEmpty()) { + return true; + } + return path.stream() + .allMatch(this.board::isEmpty); + } + + private boolean isMovableTarget(final Piece sourcePiece, final Position targetPosition) { + Piece targetPiece = this.board.getPiece(targetPosition); + return sourcePiece.isEnemy(targetPiece); } private void updateBoard(Position sourcePosition, Position targetPosition) { @@ -35,22 +81,28 @@ private void updateBoard(Position sourcePosition, Position targetPosition) { } private void changeTeam() { - this.currentTeam = Team.changeTeam(this.currentTeam); + this.currentTeam = this.currentTeam.changeTeam(); + } + + public double calculateScore() { + BoardScore boardScore = this.board.calculateScore(this.currentTeam); + return boardScore.getBoardScore(); } - public Team findWinner() { - return this.board.checkWinner(); + public boolean isEndChess() { + return this.board.getWinner().isPresent(); } - public double calculateScore() { - return board.calculateScore(currentTeam); + public Map getBoardEntities() { + return this.board.parse(); } - public Team getCurrentTeam() { - return currentTeam; + public String getCurrentTeam() { + return this.currentTeam.name(); } - public Board getBoard() { - return this.board; + public String getWinner() { + Optional winner = this.board.getWinner(); + return winner.map(Enum::name).orElseThrow(AssertionError::new); } } diff --git a/src/main/java/chess/domain/board/Board.java b/src/main/java/chess/domain/board/Board.java index d42f958b544..13ef182755a 100644 --- a/src/main/java/chess/domain/board/Board.java +++ b/src/main/java/chess/domain/board/Board.java @@ -5,16 +5,10 @@ import chess.domain.position.File; import chess.domain.position.Position; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; public class Board { - private static final int PAWN_ON_SAME_FILE = 1; - private static final double PAWN_SCORE_STRATEGY = 0.5; - private final Map board; public Board() { @@ -25,30 +19,45 @@ public Board(final Map board) { this.board = board; } - public Map parse() { - Map parseResult = board.entrySet() - .stream() - .collect(Collectors.toMap(entry -> entry.getKey().toString(), - entry -> entry.getValue().toSymbol(), - (e1, e2) -> e1, LinkedHashMap::new)); - - return Collections.unmodifiableMap(parseResult); - } - public void updateBoard(final Position sourcePosition, final Position targetPosition) { Piece selectedPiece = this.board.get(sourcePosition); this.board.put(targetPosition, selectedPiece); this.board.remove(sourcePosition); } - public Team checkWinner() { + public BoardScore calculateScore(final Team team) { + BoardScore totalScore = calculateTotalScore(team); + return calculatePawnScore(team, totalScore); + } + + private BoardScore calculateTotalScore(final Team team) { + double totalScore = board.values().stream() + .filter(piece -> team.isSameTeamWith(piece.getTeam())) + .mapToDouble(Piece::getScore) + .sum(); + return new BoardScore(totalScore); + } + + private BoardScore calculatePawnScore(final Team team, BoardScore totalScore) { + for (File file : File.values()) { + List> sameFilePawns = this.board.entrySet().stream() + .filter(entry -> File.of(entry.getKey().getFile()).equals(file)) + .filter(entry -> entry.getValue().isPawn() && !entry.getValue().isEnemy(team)) + .collect(Collectors.toList()); + + totalScore = totalScore.pawnStrategy(sameFilePawns); + } + return totalScore; + } + + public Optional getWinner() { if (checkWhiteKing() && !checkBlackKing()) { - return Team.WHITE; + return Optional.of(Team.WHITE); } if (!checkWhiteKing() && checkBlackKing()) { - return Team.BLACK; + return Optional.of(Team.BLACK); } - return null; + return Optional.empty(); } private boolean checkWhiteKing() { @@ -66,32 +75,20 @@ public boolean isEmpty(final Position position) { } public Piece getPiece(final Position position) { - return this.board.get(position); - } - - public double calculateScore(final Team team) { - double totalScore = calculateTotalScore(team); - return calculatePawnScore(team, totalScore); - } + if (!this.board.containsKey(position)) { + throw new IllegalArgumentException("비어있는 위치를 선택하였습니다."); + } - private double calculateTotalScore(final Team team) { - return board.values().stream() - .filter(piece -> team.isSameTeamWith(piece.getTeam())) - .mapToDouble(Piece::getScore) - .sum(); + return this.board.get(position); } - private double calculatePawnScore(final Team team, double score) { - for (File file : File.values()) { - List> sameFile = this.board.entrySet().stream() - .filter(entry -> File.of(entry.getKey().getFile()).equals(file)) - .filter(entry -> entry.getValue().isPawn() && !entry.getValue().isEnemy(team)) - .collect(Collectors.toList()); + public Map parse() { + Map parseResult = board.entrySet() + .stream() + .collect(Collectors.toMap(entry -> entry.getKey().toString(), + entry -> entry.getValue().toSymbol(), + (e1, e2) -> e1, LinkedHashMap::new)); - if (sameFile.size() > PAWN_ON_SAME_FILE) { - score -= sameFile.size() * PAWN_SCORE_STRATEGY; - } - } - return score; + return Collections.unmodifiableMap(parseResult); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/board/BoardScore.java b/src/main/java/chess/domain/board/BoardScore.java new file mode 100644 index 00000000000..fc46c94ffba --- /dev/null +++ b/src/main/java/chess/domain/board/BoardScore.java @@ -0,0 +1,30 @@ +package chess.domain.board; + +import chess.domain.piece.Piece; +import chess.domain.position.Position; + +import java.util.List; +import java.util.Map; + +public class BoardScore { + private static final int PAWN_ON_SAME_FILE = 1; + private static final double PAWN_SCORE_STRATEGY = 0.5; + + private final double boardScore; + + public BoardScore(final double boardScore) { + this.boardScore = boardScore; + } + + public BoardScore pawnStrategy(List> sameFilePawns) { + int pawnsCount = sameFilePawns.size(); + if (pawnsCount > PAWN_ON_SAME_FILE) { + return new BoardScore(this.boardScore - (pawnsCount * PAWN_SCORE_STRATEGY)); + } + return this; + } + + public double getBoardScore() { + return this.boardScore; + } +} diff --git a/src/main/java/chess/domain/piece/Bishop.java b/src/main/java/chess/domain/piece/Bishop.java new file mode 100644 index 00000000000..7151af78465 --- /dev/null +++ b/src/main/java/chess/domain/piece/Bishop.java @@ -0,0 +1,17 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class Bishop extends Piece { + public Bishop(PieceType pieceType, Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(Position source, Position target) { + int fileGap = Math.abs(source.calculateFileGap(target)); + int rankGap = Math.abs(source.calculateRankGap(target)); + + return fileGap == rankGap; + } +} diff --git a/src/main/java/chess/domain/piece/King.java b/src/main/java/chess/domain/piece/King.java new file mode 100644 index 00000000000..d671b45b632 --- /dev/null +++ b/src/main/java/chess/domain/piece/King.java @@ -0,0 +1,21 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class King extends Piece { + private static final int MAX_FILE_GAP = 1; + private static final int MAX_RANK_GAP = 1; + + public King(PieceType pieceType, Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(Position source, Position target) { + int fileGap = Math.abs(source.calculateFileGap(target)); + int rankGap = Math.abs(source.calculateRankGap(target)); + + return fileGap <= MAX_FILE_GAP + && rankGap <= MAX_RANK_GAP; + } +} diff --git a/src/main/java/chess/domain/piece/Knight.java b/src/main/java/chess/domain/piece/Knight.java new file mode 100644 index 00000000000..c7908365708 --- /dev/null +++ b/src/main/java/chess/domain/piece/Knight.java @@ -0,0 +1,23 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class Knight extends Piece { + private static final int HORIZONTAL_FILE_GAP = 2; + private static final int HORIZONTAL_RANK_GAP = 1; + private static final int VERTICAL_FILE_GAP = 1; + private static final int VERTICAL_RANK_GAP = 2; + + public Knight(PieceType pieceType, Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(Position source, Position target) { + int fileGap = Math.abs(source.calculateFileGap(target)); + int rankGap = Math.abs(source.calculateRankGap(target)); + + return (fileGap == HORIZONTAL_FILE_GAP && rankGap == HORIZONTAL_RANK_GAP) + || (fileGap == VERTICAL_FILE_GAP && rankGap == VERTICAL_RANK_GAP); + } +} diff --git a/src/main/java/chess/domain/piece/MoveStrategy.java b/src/main/java/chess/domain/piece/MoveStrategy.java new file mode 100644 index 00000000000..75726bc7ee6 --- /dev/null +++ b/src/main/java/chess/domain/piece/MoveStrategy.java @@ -0,0 +1,7 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public interface MoveStrategy { + boolean movable(Position source, Position target); +} diff --git a/src/main/java/chess/domain/piece/Pawn.java b/src/main/java/chess/domain/piece/Pawn.java new file mode 100644 index 00000000000..6d34deb7351 --- /dev/null +++ b/src/main/java/chess/domain/piece/Pawn.java @@ -0,0 +1,51 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class Pawn extends Piece { + private static final int START_WHITE_RANK = 2; + private static final int START_BLACK_RANK = 7; + private static final int SAME_FILE = 0; + private static final int DIAGONAL = 1; + private static final int UP_WHITE_ONE = -1; + private static final int UP_WHITE_TWO = -2; + private static final int DOWN_BLACK_ONE = 1; + private static final int DOWN_BLACK_TWO = 2; + + public Pawn(final PieceType pieceType, final Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(final Position source, final Position target) { + final int fileGap = source.calculateFileGap(target); + final int rankGap = source.calculateRankGap(target); + + if (this.team.isWhite()) { + return whitePawnMovable(source, fileGap, rankGap); + } + return blackPawnMovable(source, fileGap, rankGap); + } + + private boolean whitePawnMovable(final Position source, final int fileGap, final int rankGap) { + if (source.getRank() == START_WHITE_RANK) { + return fileGap == SAME_FILE + && (rankGap == UP_WHITE_ONE || rankGap == UP_WHITE_TWO); + } + + final int absFileGap = Math.abs(fileGap); + return (absFileGap == SAME_FILE || absFileGap == DIAGONAL) + && rankGap == UP_WHITE_ONE; + } + + private boolean blackPawnMovable(final Position source, final int fileGap, final int rankGap) { + if (source.getRank() == START_BLACK_RANK) { + return fileGap == SAME_FILE + && (rankGap == DOWN_BLACK_ONE || rankGap == DOWN_BLACK_TWO); + } + + final int absFileGap = Math.abs(fileGap); + return (absFileGap == SAME_FILE || absFileGap == DIAGONAL) + && rankGap == DOWN_BLACK_ONE; + } +} diff --git a/src/main/java/chess/domain/piece/Piece.java b/src/main/java/chess/domain/piece/Piece.java index 5169eb6c99c..a09e9aacb87 100644 --- a/src/main/java/chess/domain/piece/Piece.java +++ b/src/main/java/chess/domain/piece/Piece.java @@ -1,25 +1,14 @@ package chess.domain.piece; -import chess.domain.board.Board; -import chess.domain.position.Position; - -public class Piece { - private final PieceType pieceType; - private final Team team; +public abstract class Piece implements MoveStrategy { + protected final PieceType pieceType; + protected final Team team; public Piece(final PieceType pieceType, final Team team) { this.pieceType = pieceType; this.team = team; } - public String toSymbol() { - return this.team.symbolize(this.pieceType.getSymbol()); - } - - public boolean movable(final Position source, final Position target, final Board board) { - return this.pieceType.movable(source, target, board); - } - public boolean isEnemy(final Piece targetPiece) { return !this.team.isSameTeamWith(targetPiece.getTeam()); } @@ -40,6 +29,10 @@ public boolean isPawn() { return this.pieceType.isPawn(); } + public String toSymbol() { + return this.team.symbolize(this.pieceType.getSymbol()); + } + public Team getTeam() { return this.team; } diff --git a/src/main/java/chess/domain/piece/PieceType.java b/src/main/java/chess/domain/piece/PieceType.java index f50f5efc873..6640ffa3d86 100644 --- a/src/main/java/chess/domain/piece/PieceType.java +++ b/src/main/java/chess/domain/piece/PieceType.java @@ -1,29 +1,19 @@ package chess.domain.piece; -import chess.domain.board.Board; -import chess.domain.position.Position; -import chess.domain.strategy.move.*; - public enum PieceType { - KING("k", 0, new KingMoveStrategy()), - QUEEN("q", 9, new QueenMoveStrategy()), - ROOK("r", 5, new RookMoveStrategy()), - BISHOP("b", 3, new BishopMoveStrategy()), - KNIGHT("n", 2.5, new KnightMoveStrategy()), - PAWN("p", 1, new PawnMoveStrategy()); + KING("k", 0), + QUEEN("q", 9), + ROOK("r", 5), + BISHOP("b", 3), + KNIGHT("n", 2.5), + PAWN("p", 1); private final String symbol; private final double score; - private final MoveStrategy moveStrategy; - PieceType(String symbol, double score, MoveStrategy moveStrategy) { + PieceType(String symbol, double score) { this.symbol = symbol; this.score = score; - this.moveStrategy = moveStrategy; - } - - public boolean movable(final Position source, final Position target, final Board board) { - return this.moveStrategy.movable(source, target, board); } public boolean isKing() { diff --git a/src/main/java/chess/domain/piece/Queen.java b/src/main/java/chess/domain/piece/Queen.java new file mode 100644 index 00000000000..c7379c01f75 --- /dev/null +++ b/src/main/java/chess/domain/piece/Queen.java @@ -0,0 +1,15 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class Queen extends Piece { + public Queen(PieceType pieceType, Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(Position source, Position target) { + return new Rook(this.pieceType, this.team).movable(source, target) + && new Bishop(this.pieceType, this.team).movable(source, target); + } +} diff --git a/src/main/java/chess/domain/piece/Rook.java b/src/main/java/chess/domain/piece/Rook.java new file mode 100644 index 00000000000..791c12d4c66 --- /dev/null +++ b/src/main/java/chess/domain/piece/Rook.java @@ -0,0 +1,22 @@ +package chess.domain.piece; + +import chess.domain.position.Position; + +public class Rook extends Piece { + + private static final int MIN_FILE_GAP = 0; + private static final int MIN_RANK_GAP = 0; + + public Rook(PieceType pieceType, Team team) { + super(pieceType, team); + } + + @Override + public boolean movable(Position source, Position target) { + int fileGap = Math.abs(source.calculateFileGap(target)); + int rankGap = Math.abs(source.calculateRankGap(target)); + + return (fileGap > MIN_FILE_GAP && rankGap == MIN_RANK_GAP) + || (fileGap == MIN_FILE_GAP && rankGap > MIN_RANK_GAP); + } +} diff --git a/src/main/java/chess/domain/piece/Team.java b/src/main/java/chess/domain/piece/Team.java index 6ae03e8124d..593352c6ab2 100644 --- a/src/main/java/chess/domain/piece/Team.java +++ b/src/main/java/chess/domain/piece/Team.java @@ -12,8 +12,8 @@ public enum Team { this.expression = expression; } - public static Team changeTeam(final Team team) { - if (team == BLACK) { + public Team changeTeam() { + if (this == BLACK) { return WHITE; } return BLACK; diff --git a/src/main/java/chess/domain/position/Position.java b/src/main/java/chess/domain/position/Position.java index 4ba4ddb7fd5..f0794eb275e 100644 --- a/src/main/java/chess/domain/position/Position.java +++ b/src/main/java/chess/domain/position/Position.java @@ -52,13 +52,6 @@ public static Position of(final int fileSymbol, final int rankSymbol) { return findPosition(File.of(fileSymbol), Rank.of(rankSymbol)); } - public static List getPositions() { - List parseResult = positions.stream() - .map(Position::toString) - .collect(Collectors.toList()); - return Collections.unmodifiableList(parseResult); - } - public int calculateFileGap(final Position target) { return this.file.compareTo(target.file); } @@ -67,6 +60,13 @@ public int calculateRankGap(final Position target) { return this.rank.getDifference(target.rank); } + public static List getPositions() { + List parseResult = positions.stream() + .map(Position::toString) + .collect(Collectors.toList()); + return Collections.unmodifiableList(parseResult); + } + public int getFile() { return this.file.getNumber(); } diff --git a/src/main/java/chess/domain/strategy/move/direction/Direction.java b/src/main/java/chess/domain/strategy/direction/Direction.java similarity index 97% rename from src/main/java/chess/domain/strategy/move/direction/Direction.java rename to src/main/java/chess/domain/strategy/direction/Direction.java index 857ad66d9a7..50aa5d53255 100644 --- a/src/main/java/chess/domain/strategy/move/direction/Direction.java +++ b/src/main/java/chess/domain/strategy/direction/Direction.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; diff --git a/src/main/java/chess/domain/strategy/move/direction/DirectionStrategy.java b/src/main/java/chess/domain/strategy/direction/DirectionStrategy.java similarity index 78% rename from src/main/java/chess/domain/strategy/move/direction/DirectionStrategy.java rename to src/main/java/chess/domain/strategy/direction/DirectionStrategy.java index d9d3f558288..ec27cd66a4a 100644 --- a/src/main/java/chess/domain/strategy/move/direction/DirectionStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/DirectionStrategy.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; diff --git a/src/main/java/chess/domain/strategy/move/direction/DownStrategy.java b/src/main/java/chess/domain/strategy/direction/DownStrategy.java similarity index 88% rename from src/main/java/chess/domain/strategy/move/direction/DownStrategy.java rename to src/main/java/chess/domain/strategy/direction/DownStrategy.java index 9d0cae3a260..4c934153ce7 100644 --- a/src/main/java/chess/domain/strategy/move/direction/DownStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/DownStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/move/direction/LeftDownStrategy.java b/src/main/java/chess/domain/strategy/direction/LeftDownStrategy.java similarity index 89% rename from src/main/java/chess/domain/strategy/move/direction/LeftDownStrategy.java rename to src/main/java/chess/domain/strategy/direction/LeftDownStrategy.java index 0b2927ebcfb..9eb5797914a 100644 --- a/src/main/java/chess/domain/strategy/move/direction/LeftDownStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/LeftDownStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/move/direction/LeftStrategy.java b/src/main/java/chess/domain/strategy/direction/LeftStrategy.java similarity index 88% rename from src/main/java/chess/domain/strategy/move/direction/LeftStrategy.java rename to src/main/java/chess/domain/strategy/direction/LeftStrategy.java index e95cbff9e82..9c03bab43ba 100644 --- a/src/main/java/chess/domain/strategy/move/direction/LeftStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/LeftStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/move/direction/LeftUpStrategy.java b/src/main/java/chess/domain/strategy/direction/LeftUpStrategy.java similarity index 88% rename from src/main/java/chess/domain/strategy/move/direction/LeftUpStrategy.java rename to src/main/java/chess/domain/strategy/direction/LeftUpStrategy.java index 03400dc3e29..7be9d112170 100644 --- a/src/main/java/chess/domain/strategy/move/direction/LeftUpStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/LeftUpStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -14,7 +13,7 @@ public List findPath(final Position source, final Position target) { List path = IntStream.range(target.getFile() + 1, source.getFile()) .mapToObj(index -> Position.of(index, target.getRank() + (target.getFile() - index))) .collect(Collectors.toList()); - + return Collections.unmodifiableList(path); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/move/direction/RightDownStrategy.java b/src/main/java/chess/domain/strategy/direction/RightDownStrategy.java similarity index 85% rename from src/main/java/chess/domain/strategy/move/direction/RightDownStrategy.java rename to src/main/java/chess/domain/strategy/direction/RightDownStrategy.java index 9a304efcfaa..6f8988b2d0c 100644 --- a/src/main/java/chess/domain/strategy/move/direction/RightDownStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/RightDownStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -12,7 +11,7 @@ public final class RightDownStrategy implements DirectionStrategy { @Override public List findPath(final Position source, final Position target) { - List path = IntStream.rangeClosed(source.getFile() + 1, target.getFile() -1) + List path = IntStream.rangeClosed(source.getFile() + 1, target.getFile() - 1) .mapToObj(index -> Position.of(index, target.getRank() + (target.getFile() - index))) .collect(Collectors.toList()); diff --git a/src/main/java/chess/domain/strategy/move/direction/RightStrategy.java b/src/main/java/chess/domain/strategy/direction/RightStrategy.java similarity index 89% rename from src/main/java/chess/domain/strategy/move/direction/RightStrategy.java rename to src/main/java/chess/domain/strategy/direction/RightStrategy.java index 112de22e38f..f665648ee0a 100644 --- a/src/main/java/chess/domain/strategy/move/direction/RightStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/RightStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/move/direction/RightUpStrategy.java b/src/main/java/chess/domain/strategy/direction/RightUpStrategy.java similarity index 89% rename from src/main/java/chess/domain/strategy/move/direction/RightUpStrategy.java rename to src/main/java/chess/domain/strategy/direction/RightUpStrategy.java index ffadef2983d..f321d432ef1 100644 --- a/src/main/java/chess/domain/strategy/move/direction/RightUpStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/RightUpStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/move/direction/UpStrategy.java b/src/main/java/chess/domain/strategy/direction/UpStrategy.java similarity index 89% rename from src/main/java/chess/domain/strategy/move/direction/UpStrategy.java rename to src/main/java/chess/domain/strategy/direction/UpStrategy.java index 8c7e704a4a8..c309ae1f086 100644 --- a/src/main/java/chess/domain/strategy/move/direction/UpStrategy.java +++ b/src/main/java/chess/domain/strategy/direction/UpStrategy.java @@ -1,8 +1,7 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/chess/domain/strategy/initialize/BishopInitializer.java b/src/main/java/chess/domain/strategy/initialize/BishopInitializer.java index aa96685bbe1..de5017b6892 100644 --- a/src/main/java/chess/domain/strategy/initialize/BishopInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/BishopInitializer.java @@ -1,23 +1,42 @@ package chess.domain.strategy.initialize; +import chess.domain.piece.Bishop; import chess.domain.piece.Piece; import chess.domain.piece.PieceType; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class BishopInitializer implements InitializeStrategy { + private enum InitialBishop { + BLACK_LEFT(Position.of("c8"), new Bishop(PieceType.BISHOP, Team.BLACK)), + BLACK_RIGHT(Position.of("f8"), new Bishop(PieceType.BISHOP, Team.BLACK)), + WHITE_LEFT(Position.of("c1"), new Bishop(PieceType.BISHOP, Team.WHITE)), + WHITE_RIGHT(Position.of("f1"), new Bishop(PieceType.BISHOP, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialBishop(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initializeBishops() { + Map bishops = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(bishops); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("c8"), new Piece(PieceType.BISHOP, Team.BLACK)); - pieces.put(Position.of("c1"), new Piece(PieceType.BISHOP, Team.WHITE)); - pieces.put(Position.of("f8"), new Piece(PieceType.BISHOP, Team.BLACK)); - pieces.put(Position.of("f1"), new Piece(PieceType.BISHOP, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialBishop.initializeBishops(); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/initialize/KingInitializer.java b/src/main/java/chess/domain/strategy/initialize/KingInitializer.java index 31346c488f2..caec8420870 100644 --- a/src/main/java/chess/domain/strategy/initialize/KingInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/KingInitializer.java @@ -1,21 +1,40 @@ package chess.domain.strategy.initialize; +import chess.domain.piece.King; import chess.domain.piece.Piece; import chess.domain.piece.PieceType; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class KingInitializer implements InitializeStrategy { + private enum InitialKing { + BLACK_KING(Position.of("e8"), new King(PieceType.KING, Team.BLACK)), + WHITE_KING(Position.of("e1"), new King(PieceType.KING, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialKing(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initializeKings() { + Map kings = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(kings); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("e8"), new Piece(PieceType.KING, Team.BLACK)); - pieces.put(Position.of("e1"), new Piece(PieceType.KING, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialKing.initializeKings(); } } diff --git a/src/main/java/chess/domain/strategy/initialize/KnightInitializer.java b/src/main/java/chess/domain/strategy/initialize/KnightInitializer.java index 610e7e8864c..fa95bb0823d 100644 --- a/src/main/java/chess/domain/strategy/initialize/KnightInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/KnightInitializer.java @@ -1,23 +1,42 @@ package chess.domain.strategy.initialize; +import chess.domain.piece.Knight; import chess.domain.piece.Piece; import chess.domain.piece.PieceType; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class KnightInitializer implements InitializeStrategy { + private enum InitialKnight { + BLACK_LEFT(Position.of("b8"), new Knight(PieceType.KNIGHT, Team.BLACK)), + BLACK_RIGHT(Position.of("g8"), new Knight(PieceType.KNIGHT, Team.BLACK)), + WHITE_LEFT(Position.of("b1"), new Knight(PieceType.KNIGHT, Team.WHITE)), + WHITE_RIGHT(Position.of("g1"), new Knight(PieceType.KNIGHT, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialKnight(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initializeKnights() { + Map knights = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(knights); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("b8"), new Piece(PieceType.KNIGHT, Team.BLACK)); - pieces.put(Position.of("b1"), new Piece(PieceType.KNIGHT, Team.WHITE)); - pieces.put(Position.of("g8"), new Piece(PieceType.KNIGHT, Team.BLACK)); - pieces.put(Position.of("g1"), new Piece(PieceType.KNIGHT, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialKnight.initializeKnights(); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/initialize/PawnInitializer.java b/src/main/java/chess/domain/strategy/initialize/PawnInitializer.java index fae533df5d9..523acea9c0a 100644 --- a/src/main/java/chess/domain/strategy/initialize/PawnInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/PawnInitializer.java @@ -1,36 +1,55 @@ package chess.domain.strategy.initialize; +import chess.domain.piece.Pawn; import chess.domain.piece.Piece; import chess.domain.piece.PieceType; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class PawnInitializer implements InitializeStrategy { + private enum InitialPawn { + BLACK_A7(Position.of("a7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_B7(Position.of("b7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_C7(Position.of("c7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_D7(Position.of("d7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_E7(Position.of("e7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_F7(Position.of("f7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_G7(Position.of("g7"), new Pawn(PieceType.PAWN, Team.BLACK)), + BLACK_H7(Position.of("h7"), new Pawn(PieceType.PAWN, Team.BLACK)), + + WHITE_A2(Position.of("a2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_B2(Position.of("b2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_C2(Position.of("c2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_D2(Position.of("d2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_E2(Position.of("e2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_F2(Position.of("f2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_G2(Position.of("g2"), new Pawn(PieceType.PAWN, Team.WHITE)), + WHITE_H2(Position.of("h2"), new Pawn(PieceType.PAWN, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialPawn(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initialPawns() { + Map pawns = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(pawns); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("a7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("b7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("c7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("d7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("e7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("f7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("g7"), new Piece(PieceType.PAWN, Team.BLACK)); - pieces.put(Position.of("h7"), new Piece(PieceType.PAWN, Team.BLACK)); - - pieces.put(Position.of("a2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("b2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("c2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("d2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("e2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("f2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("g2"), new Piece(PieceType.PAWN, Team.WHITE)); - pieces.put(Position.of("h2"), new Piece(PieceType.PAWN, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialPawn.initialPawns(); } } diff --git a/src/main/java/chess/domain/strategy/initialize/QueenInitializer.java b/src/main/java/chess/domain/strategy/initialize/QueenInitializer.java index d13feded160..e23871b6bd9 100644 --- a/src/main/java/chess/domain/strategy/initialize/QueenInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/QueenInitializer.java @@ -2,20 +2,39 @@ import chess.domain.piece.Piece; import chess.domain.piece.PieceType; +import chess.domain.piece.Queen; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class QueenInitializer implements InitializeStrategy { + private enum InitialQueen { + BLACK_QUEEN(Position.of("d8"), new Queen(PieceType.QUEEN, Team.BLACK)), + WHITE_QUEEN(Position.of("d1"), new Queen(PieceType.QUEEN, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialQueen(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initializeQueens() { + Map queens = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(queens); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("d8"), new Piece(PieceType.QUEEN, Team.BLACK)); - pieces.put(Position.of("d1"), new Piece(PieceType.QUEEN, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialQueen.initializeQueens(); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/initialize/RookInitializer.java b/src/main/java/chess/domain/strategy/initialize/RookInitializer.java index c1409b0f6c0..8b351c3088d 100644 --- a/src/main/java/chess/domain/strategy/initialize/RookInitializer.java +++ b/src/main/java/chess/domain/strategy/initialize/RookInitializer.java @@ -2,22 +2,41 @@ import chess.domain.piece.Piece; import chess.domain.piece.PieceType; +import chess.domain.piece.Rook; import chess.domain.piece.Team; import chess.domain.position.Position; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; public final class RookInitializer implements InitializeStrategy { + private enum InitialRook { + BLACK_LEFT(Position.of("a8"), new Rook(PieceType.ROOK, Team.BLACK)), + BLACK_RIGHT(Position.of("h8"), new Rook(PieceType.ROOK, Team.BLACK)), + WHITE_LEFT(Position.of("a1"), new Rook(PieceType.ROOK, Team.WHITE)), + WHITE_RIGHT(Position.of("h1"), new Rook(PieceType.ROOK, Team.WHITE)); + + private final Position position; + private final Piece piece; + + InitialRook(Position position, Piece piece) { + this.position = position; + this.piece = piece; + } + + public static Map initializeRooks() { + Map rooks = Arrays.stream(values()) + .collect(Collectors.toMap(entry -> entry.position, entry -> entry.piece, + (e1, e2) -> e1, HashMap::new)); + return Collections.unmodifiableMap(rooks); + } + } + @Override public Map initialize() { - Map pieces = new HashMap<>(); - pieces.put(Position.of("a8"), new Piece(PieceType.ROOK, Team.BLACK)); - pieces.put(Position.of("a1"), new Piece(PieceType.ROOK, Team.WHITE)); - pieces.put(Position.of("h8"), new Piece(PieceType.ROOK, Team.BLACK)); - pieces.put(Position.of("h1"), new Piece(PieceType.ROOK, Team.WHITE)); - - return Collections.unmodifiableMap(pieces); + return InitialRook.initializeRooks(); } } \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/move/BishopMoveStrategy.java b/src/main/java/chess/domain/strategy/move/BishopMoveStrategy.java deleted file mode 100644 index 2d6b99cda57..00000000000 --- a/src/main/java/chess/domain/strategy/move/BishopMoveStrategy.java +++ /dev/null @@ -1,20 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.position.Position; - -public final class BishopMoveStrategy extends MoveStrategy { - @Override - public boolean movable(final Position source, final Position target, final Board board) { - if (isSamePosition(source, target)) { - return false; - } - - int fileGap = Math.abs(source.calculateFileGap(target)); - int rankGap = Math.abs(source.calculateRankGap(target)); - - return (fileGap == rankGap) - && checkObstacle(source, target, board) - && checkTarget(source, target, board); - } -} diff --git a/src/main/java/chess/domain/strategy/move/KingMoveStrategy.java b/src/main/java/chess/domain/strategy/move/KingMoveStrategy.java deleted file mode 100644 index 1b7c157e9e1..00000000000 --- a/src/main/java/chess/domain/strategy/move/KingMoveStrategy.java +++ /dev/null @@ -1,19 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.position.Position; - -public final class KingMoveStrategy extends MoveStrategy { - @Override - public boolean movable(final Position source, final Position target, final Board board) { - if (isSamePosition(source, target)) { - return false; - } - - int fileGap = Math.abs(source.calculateFileGap(target)); - int rankGap = Math.abs(source.calculateRankGap(target)); - - return (fileGap <= 1 && rankGap <= 1) - && checkTarget(source, target, board); - } -} diff --git a/src/main/java/chess/domain/strategy/move/KnightMoveStrategy.java b/src/main/java/chess/domain/strategy/move/KnightMoveStrategy.java deleted file mode 100644 index 7a2e2676256..00000000000 --- a/src/main/java/chess/domain/strategy/move/KnightMoveStrategy.java +++ /dev/null @@ -1,19 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.position.Position; - -public final class KnightMoveStrategy extends MoveStrategy { - @Override - public boolean movable(final Position source, final Position target, final Board board) { - if (isSamePosition(source, target)) { - return false; - } - - int fileGap = Math.abs(source.calculateFileGap(target)); - int rankGap = Math.abs(source.calculateRankGap(target)); - - return (fileGap == 2 && rankGap == 1) || (fileGap == 1 && rankGap == 2) - && checkTarget(source, target, board); - } -} \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/move/MoveStrategy.java b/src/main/java/chess/domain/strategy/move/MoveStrategy.java deleted file mode 100644 index 5b6395ce053..00000000000 --- a/src/main/java/chess/domain/strategy/move/MoveStrategy.java +++ /dev/null @@ -1,33 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.position.Position; -import chess.domain.strategy.move.direction.Direction; - -import java.util.List; - -public abstract class MoveStrategy { - protected boolean isSamePosition(final Position source, final Position target) { - return source.equals(target); - } - - protected boolean checkObstacle(final Position source, final Position target, final Board board) { - Direction direction = Direction.findDirection(source, target); - List path = direction.findPath(source, target); - - return path.stream() - .allMatch(board::isEmpty); - } - - protected boolean checkTarget(final Position source, final Position target, final Board board) { - Piece sourcePiece = board.getPiece(source); - if (board.isEmpty(target)) { - return true; - } - Piece targetPiece = board.getPiece(target); - return sourcePiece.isEnemy(targetPiece); - } - - public abstract boolean movable(final Position source, final Position target, final Board board); -} diff --git a/src/main/java/chess/domain/strategy/move/PawnMoveStrategy.java b/src/main/java/chess/domain/strategy/move/PawnMoveStrategy.java deleted file mode 100644 index 51152f41ea2..00000000000 --- a/src/main/java/chess/domain/strategy/move/PawnMoveStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.Team; -import chess.domain.position.Position; - -public final class PawnMoveStrategy extends MoveStrategy { - private static final int WHITE_POSITION = 2; - private static final int BLACK_POSITION = 7; - - @Override - public boolean movable(final Position source, final Position target, final Board board) { - if (isSamePosition(source, target)) { - return false; - } - - int fileGap = source.calculateFileGap(target); - int rankGap = source.calculateRankGap(target); - - Piece sourcePiece = board.getPiece(source); - Piece targetPiece = board.getPiece(target); - Team pawnTeam = sourcePiece.getTeam(); - - if (pawnTeam.isWhite()) { - if (fileGap == 0 && rankGap == -1) { - return board.isEmpty(target); - } - if (fileGap == 0 && rankGap == -2) { - return source.getRank() == WHITE_POSITION; - } - if (Math.abs(fileGap) == 1 && rankGap == -1) { - return !board.isEmpty(target) && sourcePiece.isEnemy(targetPiece); - } - } - if (!pawnTeam.isWhite()) { - if (fileGap == 0 && rankGap == 1) { - return board.isEmpty(target); - } - if (fileGap == 0 && rankGap == 2) { - return source.getRank() == BLACK_POSITION; - } - if (Math.abs(fileGap) == 1 && rankGap == 1) { - return !board.isEmpty(target) && sourcePiece.isEnemy(targetPiece); - } - } - return false; - } -} \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/move/QueenMoveStrategy.java b/src/main/java/chess/domain/strategy/move/QueenMoveStrategy.java deleted file mode 100644 index 06b05f8db8b..00000000000 --- a/src/main/java/chess/domain/strategy/move/QueenMoveStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.position.Position; - -public final class QueenMoveStrategy extends MoveStrategy { - @Override - public boolean movable(final Position source, final Position target, final Board board) { - return new RookMoveStrategy().movable(source, target, board) - || new BishopMoveStrategy().movable(source, target, board); - } -} \ No newline at end of file diff --git a/src/main/java/chess/domain/strategy/move/RookMoveStrategy.java b/src/main/java/chess/domain/strategy/move/RookMoveStrategy.java deleted file mode 100644 index 91f0bc112c3..00000000000 --- a/src/main/java/chess/domain/strategy/move/RookMoveStrategy.java +++ /dev/null @@ -1,20 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.position.Position; - -public final class RookMoveStrategy extends MoveStrategy { - @Override - public boolean movable(final Position source, final Position target, final Board board) { - if (isSamePosition(source, target)) { - return false; - } - - int fileGap = Math.abs(source.calculateFileGap(target)); - int rankGap = Math.abs(source.calculateRankGap(target)); - - return ((fileGap > 0 && rankGap == 0) || (fileGap == 0 && rankGap > 0)) - && checkObstacle(source, target, board) - && checkTarget(source, target, board); - } -} diff --git a/src/main/java/chess/view/ConsoleOutputView.java b/src/main/java/chess/view/ConsoleOutputView.java index b0cc85985cd..b85b029b013 100644 --- a/src/main/java/chess/view/ConsoleOutputView.java +++ b/src/main/java/chess/view/ConsoleOutputView.java @@ -1,7 +1,5 @@ package chess.view; -import chess.domain.piece.Team; - import java.util.List; import java.util.Map; @@ -33,12 +31,12 @@ private String printPiece(String piece) { } @Override - public void printStatus(double calculateScore, Team team) { - System.out.println(String.format("%s 팀의 점수는 %.1f 점입니다.", team.name(), calculateScore)); + public void printStatus(double calculateScore, String teamName) { + System.out.println(String.format("%s 팀의 점수는 %.1f 점입니다.", teamName, calculateScore)); } @Override - public void printWinner(Team team) { - System.out.println(String.format("%s 팀이 이겼습니다.", team.name())); + public void printWinner(String teamName) { + System.out.println(String.format("%s 팀이 이겼습니다.", teamName)); } } diff --git a/src/main/java/chess/view/InputView.java b/src/main/java/chess/view/InputView.java index adb656d5da3..d3a8f06a520 100644 --- a/src/main/java/chess/view/InputView.java +++ b/src/main/java/chess/view/InputView.java @@ -2,5 +2,6 @@ public interface InputView { String askChessRun(); + String askGameCommand(); } diff --git a/src/main/java/chess/view/OutputView.java b/src/main/java/chess/view/OutputView.java index 1399b824401..155d5eaca09 100644 --- a/src/main/java/chess/view/OutputView.java +++ b/src/main/java/chess/view/OutputView.java @@ -1,12 +1,12 @@ package chess.view; -import chess.domain.piece.Team; - import java.util.List; import java.util.Map; public interface OutputView { void printBoard(List positions, Map board); - void printStatus(double calculateScore, Team team); - void printWinner(Team team); + + void printStatus(double calculateScore, String teamName); + + void printWinner(String teamName); } diff --git a/src/test/java/chess/domain/ChessRunnerTest.java b/src/test/java/chess/domain/ChessRunnerTest.java index 093fd56c2b9..e311062b9ee 100644 --- a/src/test/java/chess/domain/ChessRunnerTest.java +++ b/src/test/java/chess/domain/ChessRunnerTest.java @@ -22,11 +22,35 @@ void validateCurrentTeam() { .hasMessage("현재 차례가 아닙니다."); } - @DisplayName("이동할 수 없는 곳일 때 에러 메시지 출력") + @DisplayName("같은 위치로 이동할 때 에러 메시지 출력") + @Test + void validateSamePosition() { + assertThatThrownBy(() -> chessRunner.update("a2", "a2")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("같은 위치로 이동할 수 없습니다."); + } + + @DisplayName("선택한 기물에 맞지 않는 목적지를 선택했을 때 에레 메시지 출력") @Test void validateMovable() { - assertThatThrownBy(() -> chessRunner.update("a1", "a2")) //화이트 팀 룩 이동 + assertThatThrownBy(() -> chessRunner.update("a1", "b2")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("선택한 기물이 이동할 수 없는 곳입니다."); + } + + @DisplayName("경로 사이에 장애물이 있을 때 에러 메시지 출력") + @Test + void validateObstacle() { + assertThatThrownBy(() -> chessRunner.update("a1", "a3")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("경로 사이에 장애물이 있습니다."); + } + + @DisplayName("잘못된 목적지를 선택했을 때 에러 메시지 출력") + @Test + void validateTarget() { + assertThatThrownBy(() -> chessRunner.update("a1", "a2")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("이동할 수 없는 곳입니다."); + .hasMessage("목적지가 잘못되었습니다."); } } \ No newline at end of file diff --git a/src/test/java/chess/domain/board/BoardTest.java b/src/test/java/chess/domain/board/BoardTest.java index 9a0e11c066b..c1cb9c4df07 100644 --- a/src/test/java/chess/domain/board/BoardTest.java +++ b/src/test/java/chess/domain/board/BoardTest.java @@ -1,8 +1,6 @@ package chess.domain.board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; +import chess.domain.piece.*; import chess.domain.position.Position; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -10,6 +8,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.NoSuchElementException; public class BoardTest { @DisplayName("빈 칸으로 말 이동") @@ -20,16 +19,17 @@ void updateAtEmptyBoard() { Position target = Position.of("a3"); board.updateBoard(source, target); - Assertions.assertThat(board.getPiece(source)).isNull(); - Assertions.assertThat(board.getPiece(target)).isNotNull(); + Assertions.assertThatThrownBy(() -> { + board.getPiece(source); + }).isInstanceOf(IllegalArgumentException.class); Assertions.assertThat(board.getPiece(target)).isInstanceOf(Piece.class); } @DisplayName("상대 편으로 말 이동") @Test void updateAtEnemy() { - Piece rook = new Piece(PieceType.ROOK, Team.WHITE); - Piece pawn = new Piece(PieceType.PAWN, Team.BLACK); + Piece rook = new Rook(PieceType.ROOK, Team.WHITE); + Piece pawn = new Pawn(PieceType.PAWN, Team.BLACK); Map entry = new HashMap<>(); Position source = Position.of("a2"); Position target = Position.of("a3"); @@ -38,7 +38,9 @@ void updateAtEnemy() { Board board = new Board(entry); board.updateBoard(source, target); - Assertions.assertThat(board.getPiece(source)).isNull(); + Assertions.assertThatThrownBy(() -> { + board.getPiece(source); + }).isInstanceOf(IllegalArgumentException.class); Assertions.assertThat(board.getPiece(target)).isNotNull(); Assertions.assertThat(board.getPiece(target)).isInstanceOf(Piece.class); } @@ -47,21 +49,23 @@ void updateAtEnemy() { @Test void checkWinnerTest() { Map whiteKing = new HashMap<>(); - whiteKing.put(Position.of("a3"), new Piece(PieceType.KING, Team.WHITE)); + whiteKing.put(Position.of("a3"), new King(PieceType.KING, Team.WHITE)); Board whiteWinBoard = new Board(whiteKing); Map blackKing = new HashMap<>(); - blackKing.put(Position.of("b4"), new Piece(PieceType.KING, Team.BLACK)); + blackKing.put(Position.of("b4"), new King(PieceType.KING, Team.BLACK)); Board blackWinBoard = new Board(blackKing); Map bothKing = new HashMap<>(); - bothKing.put(Position.of("a5"), new Piece(PieceType.KING, Team.BLACK)); - bothKing.put(Position.of("b7"), new Piece(PieceType.KING, Team.WHITE)); + bothKing.put(Position.of("a5"), new King(PieceType.KING, Team.BLACK)); + bothKing.put(Position.of("b7"), new King(PieceType.KING, Team.WHITE)); Board drawBoard = new Board(bothKing); - Assertions.assertThat(whiteWinBoard.checkWinner()).isEqualTo(Team.WHITE); - Assertions.assertThat(blackWinBoard.checkWinner()).isEqualTo(Team.BLACK); - Assertions.assertThat(drawBoard.checkWinner()).isNull(); + Assertions.assertThat(whiteWinBoard.getWinner().get()).isEqualTo(Team.WHITE); + Assertions.assertThat(blackWinBoard.getWinner().get()).isEqualTo(Team.BLACK); + Assertions.assertThatThrownBy(() -> { + drawBoard.getWinner().get(); + }).isInstanceOf(NoSuchElementException.class); } @DisplayName("지정한 칸이 비어있는지 판단") @@ -81,7 +85,9 @@ void getPieceTest() { Board board = new Board(); Assertions.assertThat(board.getPiece(Position.of("a2"))).isInstanceOf(Piece.class); - Assertions.assertThat(board.getPiece(Position.of("a3"))).isNull(); + Assertions.assertThatThrownBy(() -> { + board.getPiece(Position.of("a3")); + }).isInstanceOf(IllegalArgumentException.class); } @DisplayName("같은 세로줄에 폰이 없을 때 점수 계산") @@ -89,19 +95,19 @@ void getPieceTest() { void calculateScoreWithoutSameFilePawnTest() { Board board = new Board(); - Assertions.assertThat(board.calculateScore(Team.WHITE)).isEqualTo(38d); - Assertions.assertThat(board.calculateScore(Team.BLACK)).isEqualTo(38d); + Assertions.assertThat(board.calculateScore(Team.WHITE).getBoardScore()).isEqualTo(38d); + Assertions.assertThat(board.calculateScore(Team.BLACK).getBoardScore()).isEqualTo(38d); } @DisplayName("같은 세로줄에 폰이 있을 때 점수 계산") @Test void calculateScoreWithSameFilePawn() { Map sameFilePawn = new HashMap<>(); - sameFilePawn.put(Position.of("a3"), new Piece(PieceType.PAWN, Team.WHITE)); - sameFilePawn.put(Position.of("a4"), new Piece(PieceType.PAWN, Team.WHITE)); - sameFilePawn.put(Position.of("a5"), new Piece(PieceType.PAWN, Team.WHITE)); + sameFilePawn.put(Position.of("a3"), new Pawn(PieceType.PAWN, Team.WHITE)); + sameFilePawn.put(Position.of("a4"), new Pawn(PieceType.PAWN, Team.WHITE)); + sameFilePawn.put(Position.of("a5"), new Pawn(PieceType.PAWN, Team.WHITE)); Board board = new Board(sameFilePawn); - Assertions.assertThat(board.calculateScore(Team.WHITE)).isEqualTo(1.5d); + Assertions.assertThat(board.calculateScore(Team.WHITE).getBoardScore()).isEqualTo(1.5d); } } diff --git a/src/test/java/chess/domain/piece/PieceTest.java b/src/test/java/chess/domain/piece/PieceTest.java index 088f7bc1eab..926051f7da8 100644 --- a/src/test/java/chess/domain/piece/PieceTest.java +++ b/src/test/java/chess/domain/piece/PieceTest.java @@ -9,8 +9,8 @@ class PieceTest { @DisplayName("팀 별 대소문자로 출력") @Test void toSymbol() { - Piece whitePiece = new Piece(PieceType.BISHOP, Team.WHITE); - Piece blackPiece = new Piece(PieceType.BISHOP, Team.BLACK); + Piece whitePiece = new Bishop(PieceType.BISHOP, Team.WHITE); + Piece blackPiece = new Bishop(PieceType.BISHOP, Team.BLACK); assertThat(whitePiece.toSymbol()).isEqualTo("b"); assertThat(blackPiece.toSymbol()).isEqualTo("B"); } @@ -18,16 +18,16 @@ void toSymbol() { @DisplayName("피스의 팀 구분") @Test void isEnemy() { - Piece whitePiece = new Piece(PieceType.KNIGHT, Team.WHITE); - Piece blackPiece = new Piece(PieceType.KNIGHT, Team.BLACK); + Piece whitePiece = new Knight(PieceType.KNIGHT, Team.WHITE); + Piece blackPiece = new Knight(PieceType.KNIGHT, Team.BLACK); assertThat(whitePiece.isEnemy(blackPiece)).isTrue(); } @DisplayName("피스가 흰 팀의 킹인지 테스트") @Test void isWhiteKing() { - Piece whiteKing = new Piece(PieceType.KING, Team.WHITE); - Piece blackBishop = new Piece(PieceType.BISHOP, Team.BLACK); + Piece whiteKing = new King(PieceType.KING, Team.WHITE); + Piece blackBishop = new Bishop(PieceType.BISHOP, Team.BLACK); assertThat(whiteKing.isWhiteKing()).isTrue(); assertThat(blackBishop.isWhiteKing()).isFalse(); } @@ -35,8 +35,8 @@ void isWhiteKing() { @DisplayName("피스가 검은 팀의 킹인지 테스트") @Test void isBlackKing() { - Piece blackKing = new Piece(PieceType.KING, Team.BLACK); - Piece whiteBishop = new Piece(PieceType.BISHOP, Team.WHITE); + Piece blackKing = new King(PieceType.KING, Team.BLACK); + Piece whiteBishop = new Bishop(PieceType.BISHOP, Team.WHITE); assertThat(blackKing.isBlackKing()).isTrue(); assertThat(whiteBishop.isBlackKing()).isFalse(); } @@ -44,8 +44,8 @@ void isBlackKing() { @DisplayName("피스가 폰인지 테스트") @Test void isPawn() { - Piece whitePawn = new Piece(PieceType.PAWN, Team.WHITE); - Piece blackQueen = new Piece(PieceType.QUEEN, Team.BLACK); + Piece whitePawn = new Pawn(PieceType.PAWN, Team.WHITE); + Piece blackQueen = new Queen(PieceType.QUEEN, Team.BLACK); assertThat(whitePawn.isPawn()).isTrue(); assertThat(blackQueen.isPawn()).isFalse(); } diff --git a/src/test/java/chess/domain/piece/TeamTest.java b/src/test/java/chess/domain/piece/TeamTest.java index 6578588c4a4..e792ec8643a 100644 --- a/src/test/java/chess/domain/piece/TeamTest.java +++ b/src/test/java/chess/domain/piece/TeamTest.java @@ -1,17 +1,20 @@ package chess.domain.piece; -import chess.domain.ChessRunner; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - class TeamTest { @DisplayName("팀 순서 변경 테스트") @Test void changeTeam() { - ChessRunner chessRunner = new ChessRunner(); - Team nextTeam = Team.changeTeam(chessRunner.getCurrentTeam()); - assertThat(nextTeam.isSameTeamWith(Team.BLACK)).isTrue(); + Team blackTeam = Team.BLACK; + Team whiteTeam = Team.WHITE; + + Team blackExpected = blackTeam.changeTeam(); + Team whiteExpected = whiteTeam.changeTeam(); + + Assertions.assertThat(blackExpected).isEqualTo(Team.WHITE); + Assertions.assertThat(whiteExpected).isEqualTo(Team.BLACK); } } \ No newline at end of file diff --git a/src/test/java/chess/domain/strategy/move/direction/DirectionTest.java b/src/test/java/chess/domain/strategy/direction/DirectionTest.java similarity index 98% rename from src/test/java/chess/domain/strategy/move/direction/DirectionTest.java rename to src/test/java/chess/domain/strategy/direction/DirectionTest.java index 6e099801ded..9c160a57849 100644 --- a/src/test/java/chess/domain/strategy/move/direction/DirectionTest.java +++ b/src/test/java/chess/domain/strategy/direction/DirectionTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/chess/domain/strategy/move/direction/DownStrategyTest.java b/src/test/java/chess/domain/strategy/direction/DownStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/DownStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/DownStrategyTest.java index 60eea0efeb5..95c10219872 100644 --- a/src/test/java/chess/domain/strategy/move/direction/DownStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/DownStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/LeftDownStrategyTest.java b/src/test/java/chess/domain/strategy/direction/LeftDownStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/LeftDownStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/LeftDownStrategyTest.java index 7b0ccb44a14..662a64c0ed8 100644 --- a/src/test/java/chess/domain/strategy/move/direction/LeftDownStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/LeftDownStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/LeftStrategyTest.java b/src/test/java/chess/domain/strategy/direction/LeftStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/LeftStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/LeftStrategyTest.java index 8b27066e7f4..a8c126e60c2 100644 --- a/src/test/java/chess/domain/strategy/move/direction/LeftStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/LeftStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/LeftUpStrategyTest.java b/src/test/java/chess/domain/strategy/direction/LeftUpStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/LeftUpStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/LeftUpStrategyTest.java index 8d3582c09c1..22689bd2bfc 100644 --- a/src/test/java/chess/domain/strategy/move/direction/LeftUpStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/LeftUpStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/RightDownStrategyTest.java b/src/test/java/chess/domain/strategy/direction/RightDownStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/RightDownStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/RightDownStrategyTest.java index 196e8560276..38d160091d5 100644 --- a/src/test/java/chess/domain/strategy/move/direction/RightDownStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/RightDownStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/RightStrategyTest.java b/src/test/java/chess/domain/strategy/direction/RightStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/RightStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/RightStrategyTest.java index 0487ca15540..b77f11878ec 100644 --- a/src/test/java/chess/domain/strategy/move/direction/RightStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/RightStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/RightUpStrategyTest.java b/src/test/java/chess/domain/strategy/direction/RightUpStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/RightUpStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/RightUpStrategyTest.java index c4903e7303a..616ed9fbb94 100644 --- a/src/test/java/chess/domain/strategy/move/direction/RightUpStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/RightUpStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/direction/UpStrategyTest.java b/src/test/java/chess/domain/strategy/direction/UpStrategyTest.java similarity index 94% rename from src/test/java/chess/domain/strategy/move/direction/UpStrategyTest.java rename to src/test/java/chess/domain/strategy/direction/UpStrategyTest.java index 8acb305c8c1..4999a795810 100644 --- a/src/test/java/chess/domain/strategy/move/direction/UpStrategyTest.java +++ b/src/test/java/chess/domain/strategy/direction/UpStrategyTest.java @@ -1,4 +1,4 @@ -package chess.domain.strategy.move.direction; +package chess.domain.strategy.direction; import chess.domain.position.Position; import org.assertj.core.api.Assertions; diff --git a/src/test/java/chess/domain/strategy/move/BishopMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/BishopMoveStrategyTest.java deleted file mode 100644 index 6bdeb3df2ca..00000000000 --- a/src/test/java/chess/domain/strategy/move/BishopMoveStrategyTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class BishopMoveStrategyTest { - private MoveStrategy bishopStrategy; - private Board board; - - @BeforeEach - private void setUp() { - bishopStrategy = new BishopMoveStrategy(); - Map emptyBoard = new HashMap<>(); - board = new Board(emptyBoard); - } - - @DisplayName("비숍의 우 상단 대각 이동") - @Test - void rightUpTest() { - Position source = Position.of("a1"); - Position target = Position.of("e5"); - - Assertions.assertThat(bishopStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("비숍의 우 하단 대각 이동") - @Test - void rightDownTest() { - Position source = Position.of("a7"); - Position target = Position.of("e3"); - - Assertions.assertThat(bishopStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("비숍의 좌 상단 대각 이동") - @Test - void leftUpTest() { - Position source = Position.of("g1"); - Position target = Position.of("c5"); - - Assertions.assertThat(bishopStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("비숍의 좌 하단 대각 이동") - @Test - void leftDownTest() { - Position source = Position.of("g7"); - Position target = Position.of("c3"); - - Assertions.assertThat(bishopStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("타겟 위치에 적이 있을 때 이동") - @Test - void moveWhenEnemyTest() { - Piece bishop = new Piece(PieceType.BISHOP, Team.BLACK); - Piece enemy = new Piece(PieceType.PAWN, Team.WHITE); - Position source = Position.of("a1"); - Position target = Position.of("e5"); - Map enemyEntry = new HashMap<>(); - enemyEntry.put(source, bishop); - enemyEntry.put(target, enemy); - Board enemyBoard = new Board(enemyEntry); - - Assertions.assertThat(bishopStrategy.movable(source, target, enemyBoard)).isTrue(); - } -} diff --git a/src/test/java/chess/domain/strategy/move/KingMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/KingMoveStrategyTest.java deleted file mode 100644 index 0f54b0d7e69..00000000000 --- a/src/test/java/chess/domain/strategy/move/KingMoveStrategyTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class KingMoveStrategyTest { - private MoveStrategy kingStrategy; - - @BeforeEach - private void setUp() { - kingStrategy = new KingMoveStrategy(); - } - - @DisplayName("킹의 이동 가능 위치에 대해 이동 테스트") - @Test - void moveTest() { - Map emptyBoard = new HashMap<>(); - Board board = new Board(emptyBoard); - Position source = Position.of("d4"); - - Position up = Position.of("d5"); - Position down = Position.of("d3"); - Position left = Position.of("c4"); - Position right = Position.of("e4"); - Position rightUp = Position.of("e5"); - Position rightDown = Position.of("e3"); - Position leftUp = Position.of("c5"); - Position leftDown = Position.of("c3"); - - Assertions.assertThat(kingStrategy.movable(source, up, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, down, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, left, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, right, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, rightUp, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, rightDown, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, leftUp, board)).isTrue(); - Assertions.assertThat(kingStrategy.movable(source, leftDown, board)).isTrue(); - } - - @DisplayName("타겟 위치에 적이 있을 때 이동") - @Test - void moveWhenEnemyTest() { - Piece king = new Piece(PieceType.KING, Team.BLACK); - Piece enemy = new Piece(PieceType.PAWN, Team.WHITE); - Position source = Position.of("d4"); - Position target = Position.of("e5"); - Map enemyEntry = new HashMap<>(); - enemyEntry.put(source, king); - enemyEntry.put(target, enemy); - Board enemyBoard = new Board(enemyEntry); - - Assertions.assertThat(kingStrategy.movable(source, target, enemyBoard)).isTrue(); - } -} diff --git a/src/test/java/chess/domain/strategy/move/KnightMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/KnightMoveStrategyTest.java deleted file mode 100644 index 84bcf4d3aa8..00000000000 --- a/src/test/java/chess/domain/strategy/move/KnightMoveStrategyTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class KnightMoveStrategyTest { - private MoveStrategy knightStrategy; - - @BeforeEach - private void setUp() { - knightStrategy = new KnightMoveStrategy(); - } - - @DisplayName("나이트의 이동 가능 위치에 이동") - @Test - void moveTest() { - Position source = Position.of("d4"); - Map emptyBoard = new HashMap<>(); - Board board = new Board(emptyBoard); - - Position upLeft = Position.of("c6"); - Position upRight = Position.of("e6"); - Position downLeft = Position.of("c2"); - Position downRight = Position.of("e2"); - Position leftUp = Position.of("b5"); - Position leftDown = Position.of("b3"); - Position rightUp = Position.of("f5"); - Position rightDown = Position.of("f3"); - - Assertions.assertThat(knightStrategy.movable(source, upLeft, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, upRight, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, downLeft, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, downRight, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, leftUp, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, leftDown, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, rightUp, board)).isTrue(); - Assertions.assertThat(knightStrategy.movable(source, rightDown, board)).isTrue(); - } - - @DisplayName("타겟 위치에 적이 있을 때 이동") - @Test - void moveWhenEnemyTest() { - Piece knight = new Piece(PieceType.KING, Team.BLACK); - Piece enemy = new Piece(PieceType.PAWN, Team.WHITE); - Position source = Position.of("d4"); - Position target = Position.of("e6"); - Map enemyEntry = new HashMap<>(); - enemyEntry.put(source, knight); - enemyEntry.put(target, enemy); - Board enemyBoard = new Board(enemyEntry); - - Assertions.assertThat(knightStrategy.movable(source, target, enemyBoard)).isTrue(); - } -} diff --git a/src/test/java/chess/domain/strategy/move/PawnMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/PawnMoveStrategyTest.java deleted file mode 100644 index 41e2d60050c..00000000000 --- a/src/test/java/chess/domain/strategy/move/PawnMoveStrategyTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class PawnMoveStrategyTest { - private MoveStrategy pawnStrategy; - - @BeforeEach - private void setUp() { - pawnStrategy = new PawnMoveStrategy(); -// Piece whitePawn = new Piece(PieceType.PAWN, Team.WHITE); -// Piece blackPawn = new Piece(PieceType.PAWN, Team.BLACK); -// Position whiteSource = Position.of("d4"); -// Position blackSource = Position.of("d3"); -// Map entry = new HashMap<>(); -// entry.put(whiteSource, whitePawn); -// entry.put(blackSource, blackPawn); -// board = new Board(entry); - } - - @DisplayName("폰이 시작 위치일 때 1칸 또는 2칸 이동") - @Test - void moveAtInitialPosition() { - Piece whitePawn = new Piece(PieceType.PAWN, Team.WHITE); - Piece blackPawn = new Piece(PieceType.PAWN, Team.BLACK); - Position whiteInitial = Position.of("a2"); - Position blackInitial = Position.of("a7"); - Map emptyBoard = new HashMap<>(); - emptyBoard.put(whiteInitial, whitePawn); - emptyBoard.put(blackInitial, blackPawn); - Board board = new Board(emptyBoard); - - Position whiteOne = Position.of("a3"); - Position whiteTwo = Position.of("a4"); - Position blackOne = Position.of("a6"); - Position blackTwo = Position.of("a5"); - - Assertions.assertThat(pawnStrategy.movable(whiteInitial, whiteOne, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(whiteInitial, whiteTwo, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(blackInitial, blackOne, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(blackInitial, blackTwo, board)).isTrue(); - } - - @DisplayName("폰이 시작 위치가 아닐 때 1칸 전진") - @Test - void moveAtNoneInitialPosition() { - Piece whitePawn = new Piece(PieceType.PAWN, Team.WHITE); - Piece blackPawn = new Piece(PieceType.PAWN, Team.BLACK); - Position whiteSource = Position.of("a3"); - Position blackSource = Position.of("a6"); - Map emptyBoard = new HashMap<>(); - emptyBoard.put(whiteSource, whitePawn); - emptyBoard.put(blackSource, blackPawn); - Board board = new Board(emptyBoard); - - Position upTarget = Position.of("a4"); - Position downTarget = Position.of("a5"); - - Assertions.assertThat(pawnStrategy.movable(whiteSource, upTarget, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(blackSource, downTarget, board)).isTrue(); - } - - @DisplayName("폰이 시작 위치가 아닐 때 대각선의 적을 공격 가능") - @Test - void moveDiagonalTest() { - Piece whitePawn = new Piece(PieceType.PAWN, Team.WHITE); - Piece whiteLeftEnemy = new Piece(PieceType.PAWN, Team.BLACK); - Piece whiteRightEnemy = new Piece(PieceType.PAWN, Team.BLACK); - - Piece blackPawn = new Piece(PieceType.PAWN, Team.BLACK); - Piece blackLeftEnemy = new Piece(PieceType.PAWN, Team.WHITE); - Piece blackRightEnemy = new Piece(PieceType.PAWN, Team.WHITE); - - Position whiteSource = Position.of("d3"); - Position whiteDiagonalLeft = Position.of("c4"); - Position whiteDiagonalRight = Position.of("e4"); - - Position blackSource = Position.of("d6"); - Position blackDiagonalLeft = Position.of("c5"); - Position blackDiagonalRight = Position.of("e5"); - - Map entry = new HashMap<>(); - entry.put(whiteSource, whitePawn); - entry.put(whiteDiagonalLeft, whiteLeftEnemy); - entry.put(whiteDiagonalRight, whiteRightEnemy); - entry.put(blackSource, blackPawn); - entry.put(blackDiagonalLeft, blackLeftEnemy); - entry.put(blackDiagonalRight, blackRightEnemy); - Board board = new Board(entry); - - Assertions.assertThat(pawnStrategy.movable(whiteSource, whiteDiagonalLeft, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(whiteSource, whiteDiagonalRight, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(blackSource, blackDiagonalLeft, board)).isTrue(); - Assertions.assertThat(pawnStrategy.movable(blackSource, blackDiagonalRight, board)).isTrue(); - } -} diff --git a/src/test/java/chess/domain/strategy/move/QueenMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/QueenMoveStrategyTest.java deleted file mode 100644 index e1cc32da9fd..00000000000 --- a/src/test/java/chess/domain/strategy/move/QueenMoveStrategyTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class QueenMoveStrategyTest { - private MoveStrategy queenStrategy; - private Board board; - - @BeforeEach - private void setUp() { - queenStrategy = new QueenMoveStrategy(); - Map emptyBoard = new HashMap<>(); - board = new Board(emptyBoard); - } - - @DisplayName("퀸의 우 상단 대각 이동") - @Test - void rightUpTest() { - Position source = Position.of("a1"); - Position target = Position.of("e5"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 우 하단 대각 이동") - @Test - void rightDownTest() { - Position source = Position.of("a7"); - Position target = Position.of("e3"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 좌 상단 대각 이동") - @Test - void leftUpTest() { - Position source = Position.of("g1"); - Position target = Position.of("c5"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 좌 하단 대각 이동") - @Test - void leftDownTest() { - Position source = Position.of("g7"); - Position target = Position.of("c3"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 상단 직진 이동") - @Test - void upTest() { - Position source = Position.of("a1"); - Position target = Position.of("a6"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 하단 직진 이동") - @Test - void downTest() { - Position source = Position.of("a6"); - Position target = Position.of("a1"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 우측 직진 이동") - @Test - void rightTest() { - Position source = Position.of("a1"); - Position target = Position.of("g1"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("퀸의 좌측 직진 이동") - @Test - void leftTest() { - Position source = Position.of("g1"); - Position target = Position.of("a1"); - - Assertions.assertThat(queenStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("타겟 위치에 적이 있을 때 이동") - @Test - void moveWhenEnemyTest() { - Piece queen = new Piece(PieceType.QUEEN, Team.BLACK); - Piece enemy = new Piece(PieceType.PAWN, Team.WHITE); - Position source = Position.of("a1"); - Position target = Position.of("a6"); - Map enemyEntry = new HashMap<>(); - enemyEntry.put(source, queen); - enemyEntry.put(target, enemy); - Board enemyBoard = new Board(enemyEntry); - - Assertions.assertThat(queenStrategy.movable(source, target, enemyBoard)).isTrue(); - } -} diff --git a/src/test/java/chess/domain/strategy/move/RookMoveStrategyTest.java b/src/test/java/chess/domain/strategy/move/RookMoveStrategyTest.java deleted file mode 100644 index bf977aa2c90..00000000000 --- a/src/test/java/chess/domain/strategy/move/RookMoveStrategyTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package chess.domain.strategy.move; - -import chess.domain.board.Board; -import chess.domain.piece.Piece; -import chess.domain.piece.PieceType; -import chess.domain.piece.Team; -import chess.domain.position.Position; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -public class RookMoveStrategyTest { - private MoveStrategy rookStrategy; - private Board board; - - @BeforeEach - private void setUp() { - rookStrategy = new RookMoveStrategy(); - Map emptyBoard = new HashMap<>(); - board = new Board(emptyBoard); - } - - @DisplayName("룩의 상단 직진 이동") - @Test - void upTest() { - Position source = Position.of("a1"); - Position target = Position.of("a6"); - - Assertions.assertThat(rookStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("룩의 하단 직진 이동") - @Test - void downTest() { - Position source = Position.of("a6"); - Position target = Position.of("a1"); - - Assertions.assertThat(rookStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("룩의 우측 직진 이동") - @Test - void rightTest() { - Position source = Position.of("a1"); - Position target = Position.of("g1"); - - Assertions.assertThat(rookStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("룩의 좌측 직진 이동") - @Test - void leftTest() { - Position source = Position.of("g1"); - Position target = Position.of("a1"); - - Assertions.assertThat(rookStrategy.movable(source, target, board)).isTrue(); - } - - @DisplayName("타겟 위치에 적이 있을 때 이동 테스트") - @Test - void moveWhenEnemyTest() { - Piece rook = new Piece(PieceType.ROOK, Team.BLACK); - Piece enemy = new Piece(PieceType.PAWN, Team.WHITE); - Position source = Position.of("a1"); - Position target = Position.of("a6"); - Map enemyEntry = new HashMap<>(); - enemyEntry.put(source, rook); - enemyEntry.put(target, enemy); - Board enemyBoard = new Board(enemyEntry); - - Assertions.assertThat(rookStrategy.movable(source, target, enemyBoard)).isTrue(); - } -}