This repository has been archived on 2021-02-18. You can view files and clone it, but cannot push or open issues or pull requests.
chess/src/dev/kske/chess/Move.java

33 lines
880 B
Java
Raw Normal View History

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 {
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);
}
public Move(int xPos, int yPos, int xDest, int yDest) {
this(new Position(xPos, yPos), new Position(xDest, yDest));
}
public boolean isHorizontal() { return yDist == 0; }
public boolean isVertical() { return xDist == 0; }
public boolean isDiagonal() { return xDist == yDist; }
}