package de.vivi.chess.pieces; import de.vivi.chess.board.Board; import de.vivi.chess.board.Field; public class Knight extends Piece { public Knight(Color color, Type type) { super(color, type); } public Knight(Color color, Type type, Field field) { super(color, type, field); } @Override public char getSymbol() { if (getColor() == Color.WHITE) { if (getType() == Type.KNIGHT) { symbol = '\u265E'; } } else if (getColor() == Color.BLACK) { if (getType() == Type.KNIGHT) { symbol = '\u2658'; } } return symbol; } @Override public boolean isValidMove(Board board, Field from, Field to) { if (to.equals(from)) { return false; } int rowDiff = Math.abs(from.getRow() - to.getRow()); int colDiff = Math.abs(from.getColumn() - to.getColumn()); boolean isValidLMove = (rowDiff == 2 && colDiff == 1) || (rowDiff == 1 && colDiff == 2); if (!isValidLMove) { return false; } Piece targetPiece = board.getPiece(to); if (targetPiece == null) { return true; } else { return targetPiece.getColor() != this.getColor(); } } }