2019-07-02 13:49:36 +02:00
|
|
|
package dev.kske.chess;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Project: <strong>Chess</strong><br>
|
|
|
|
* File: <strong>Move.java</strong><br>
|
|
|
|
* Created: <strong>02.07.2019</strong><br>
|
|
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
|
|
*/
|
|
|
|
public class Move {
|
|
|
|
|
2019-07-02 20:07:47 +02:00
|
|
|
public final Position pos, dest;
|
|
|
|
public final int xDist, yDist, xSign, ySign;
|
|
|
|
|
|
|
|
public Move(Position pos, Position dest) {
|
|
|
|
this.pos = pos;
|
|
|
|
this.dest = dest;
|
|
|
|
xDist = Math.abs(dest.x - pos.x);
|
|
|
|
yDist = Math.abs(dest.y - pos.y);
|
|
|
|
xSign = (int) Math.signum(dest.x - pos.x);
|
|
|
|
ySign = (int) Math.signum(dest.y - pos.y);
|
|
|
|
}
|
2019-07-02 13:49:36 +02:00
|
|
|
|
|
|
|
public Move(int xPos, int yPos, int xDest, int yDest) {
|
2019-07-02 20:07:47 +02:00
|
|
|
this(new Position(xPos, yPos), new Position(xDest, yDest));
|
2019-07-02 13:49:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isHorizontal() { return yDist == 0; }
|
|
|
|
|
|
|
|
public boolean isVertical() { return xDist == 0; }
|
|
|
|
|
|
|
|
public boolean isDiagonal() { return xDist == yDist; }
|
|
|
|
}
|