Implemented direction enum
This commit is contained in:
1 parent
040f5e1b87
commit
d025c31789
1 file changed
+53
@@ -0,0 +1,53 @@
|
||||
package com.gitea.lin.model;
|
||||
|
||||
public enum Direction {
|
||||
// Orthogonal (Rook, Queen, King)
|
||||
NORTH(0, -1),
|
||||
SOUTH(0, 1),
|
||||
EAST(1, 0),
|
||||
WEST(-1, 0),
|
||||
|
||||
// Diagonal (Bishop, Queen, King, Pawn captures)
|
||||
NORTH_EAST(1, -1),
|
||||
NORTH_WEST(-1, -1),
|
||||
SOUTH_EAST(1, 1),
|
||||
SOUTH_WEST(-1, 1),
|
||||
|
||||
// Knight Jumps (L-shapes)
|
||||
KNIGHT_NNE(1, -2),
|
||||
KNIGHT_ENE(2, -1),
|
||||
KNIGHT_ESE(2, 1),
|
||||
KNIGHT_SSE(1, 2),
|
||||
KNIGHT_SSW(-1, 2),
|
||||
KNIGHT_WSW(-2, 1),
|
||||
KNIGHT_WNW(-2, -1),
|
||||
KNIGHT_NNW(-1, -2),
|
||||
|
||||
// Pawn Initial Double Push
|
||||
PAWN_DOUBLE_NORTH(0, -2),
|
||||
PAWN_DOUBLE_SOUTH(0, 2);
|
||||
|
||||
private final int dx;
|
||||
private final int dy;
|
||||
|
||||
Direction(int dx, int dy) {
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
}
|
||||
|
||||
public int getDx() {
|
||||
return dx;
|
||||
}
|
||||
|
||||
public int getDy() {
|
||||
return dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the 2D vector into a 1D array offset for Piece[64].
|
||||
* (Assuming index 0 is top-left a8 and 63 is bottom-right h1)
|
||||
*/
|
||||
public int getFlatOffset() {
|
||||
return dy * 8 + dx;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user