2019-07-06 18:05:00 +02:00
|
|
|
package dev.kske.chess.board;
|
2019-07-01 19:50:42 +02:00
|
|
|
|
2019-07-05 14:14:48 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-07-01 19:50:42 +02:00
|
|
|
/**
|
|
|
|
* Project: <strong>Chess</strong><br>
|
|
|
|
* File: <strong>Queen.java</strong><br>
|
|
|
|
* Created: <strong>01.07.2019</strong><br>
|
2020-01-19 22:12:33 +01:00
|
|
|
*
|
2019-10-26 07:55:21 +02:00
|
|
|
* @since Chess v0.1-alpha
|
|
|
|
* @author Kai S. K. Engelbart
|
2019-07-01 19:50:42 +02:00
|
|
|
*/
|
|
|
|
public class Queen extends Piece {
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Creates queen {@link Piece}.
|
|
|
|
*
|
|
|
|
* @param color the color of this queen
|
|
|
|
* @param board the board on which this queen will be placed
|
|
|
|
*/
|
2019-07-02 13:49:36 +02:00
|
|
|
public Queen(Color color, Board board) {
|
|
|
|
super(color, board);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValidMove(Move move) {
|
2020-05-19 16:50:12 +02:00
|
|
|
return (move.isHorizontal() || move.isVertical() || move.isDiagonal())
|
|
|
|
&& isFreePath(move);
|
2019-07-01 19:50:42 +02:00
|
|
|
}
|
|
|
|
|
2019-07-05 14:14:48 +02:00
|
|
|
@Override
|
|
|
|
protected List<Move> getPseudolegalMoves(Position pos) {
|
|
|
|
List<Move> moves = new ArrayList<>();
|
|
|
|
|
|
|
|
// Horizontal moves to the right
|
|
|
|
for (int i = pos.x + 1; i < 8; i++) {
|
|
|
|
Move move = new Move(pos, new Position(i, pos.y));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Horizontal moves to the left
|
|
|
|
for (int i = pos.x - 1; i >= 0; i--) {
|
|
|
|
Move move = new Move(pos, new Position(i, pos.y));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Vertical moves to the top
|
|
|
|
for (int i = pos.y - 1; i >= 0; i--) {
|
|
|
|
Move move = new Move(pos, new Position(pos.x, i));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Vertical moves to the bottom
|
|
|
|
for (int i = pos.y + 1; i < 8; i++) {
|
|
|
|
Move move = new Move(pos, new Position(pos.x, i));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Diagonal moves to the lower right
|
|
|
|
for (int i = pos.x + 1, j = pos.y + 1; i < 8 && j < 8; i++, j++) {
|
|
|
|
Move move = new Move(pos, new Position(i, j));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Diagonal moves to the lower left
|
|
|
|
for (int i = pos.x - 1, j = pos.y + 1; i >= 0 && j < 8; i--, j++) {
|
|
|
|
Move move = new Move(pos, new Position(i, j));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Diagonal moves to the upper right
|
|
|
|
for (int i = pos.x + 1, j = pos.y - 1; i < 8 && j >= 0; i++, j--) {
|
|
|
|
Move move = new Move(pos, new Position(i, j));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
// Diagonal moves to the upper left
|
|
|
|
for (int i = pos.x - 1, j = pos.y - 1; i >= 0 && j >= 0; i--, j--) {
|
|
|
|
Move move = new Move(pos, new Position(i, j));
|
2020-05-19 16:50:12 +02:00
|
|
|
if (
|
|
|
|
board.getDest(move) == null
|
|
|
|
|| board.getDest(move).getColor() != getColor()
|
|
|
|
) {
|
2019-07-05 14:14:48 +02:00
|
|
|
moves.add(move);
|
2020-05-19 16:50:12 +02:00
|
|
|
if (board.getDest(move) != null)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2019-07-05 14:14:48 +02:00
|
|
|
}
|
|
|
|
return moves;
|
|
|
|
}
|
|
|
|
|
2019-07-01 19:50:42 +02:00
|
|
|
@Override
|
2019-11-04 05:51:11 +01:00
|
|
|
public int getValue() { return 90; }
|
2019-07-01 19:50:42 +02:00
|
|
|
}
|