package Game;
import Pieces.BoardSquare;
import Pieces.MoveType;
public class MoveHandler {
/*
Helper functions for movement.
*/
/**
* Helper function invoked by a Piece's move function and validMove.
*
* @param startSquare: Starting square of the move.
*
* @return Pieces.MoveType containing:
* Pieces.MoveType.type: enum: if the move was vertical, diagonal, horizontal, or other
* Pieces.MoveType.dist: int: distance of the move.
*/
public static MoveType DetermineType(BoardSquare startSquare, BoardSquare destSquare) {
if (startSquare.x == destSquare.x) {//Is the move being attempted vertical only?
int dist = moveSignedDist(startSquare.y, destSquare.y, startSquare.owner);
return new MoveType(MoveType.Direction.VERT, dist);
} else if (startSquare.y == destSquare.y) {//Is it horizontal?
int dist = moveSignedDist(startSquare.x, destSquare.x, startSquare.owner);
return new MoveType(MoveType.Direction.HORIZ, dist);
} else if (Math.abs(startSquare.y - destSquare.y) == Math.abs(startSquare.x - destSquare.x)) {//Is it diagonal?
int dist = moveSignedDist(startSquare.y, destSquare.y, startSquare.owner);
return new MoveType(MoveType.Direction.DIAG, dist);
} else {//Is the attempted move something else?
return new MoveType(MoveType.Direction.OTHER, 0);
}
}
/**
* Helper function invoked by DetermineType
*
* @param start start location
* @param end ending location
* @param player owner id
*
* @return positive distance between start and end if moving towards opponent, negative otherwise.
*/
private static int moveSignedDist(int start, int end, Player player){
if(player == Player.WHITE)
return end - start;
else if(player == Player.BLACK)
return start - end;
return 0;
}
}