pretty cool
This commit is contained in:
@@ -75,19 +75,19 @@ public class PermissiveRuleChecker implements PieceVisitor<Boolean> {
|
||||
int distance = this.move.traversedCells();
|
||||
|
||||
// Revoke moving backwards
|
||||
if (directionIndexOffset * pawn.multiplier() < 0)
|
||||
if (directionIndexOffset * pawn.multiplier() > 0)
|
||||
return false;
|
||||
|
||||
// Allowing straight moves
|
||||
if (Math.abs(directionIndexOffset) == Direction.Front.getIndexOffset()) {
|
||||
if (Math.abs(directionIndexOffset) == Math.abs(Direction.Front.getIndexOffset())) {
|
||||
if (pawn.hasMoved())
|
||||
return distance == 1;
|
||||
return distance == 1 || distance == 2;
|
||||
}
|
||||
|
||||
// Allowing small diagonal moves
|
||||
if (Math.abs(directionIndexOffset) == Direction.FrontLeft.getIndexOffset()
|
||||
|| Math.abs(directionIndexOffset) == Direction.FrontRight.getIndexOffset()) {
|
||||
if (directionIndexOffset == Direction.FrontLeft.getIndexOffset()
|
||||
|| directionIndexOffset == Direction.FrontRight.getIndexOffset()) {
|
||||
return distance == 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,12 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
public boolean isValidForPiece(Piece piece) {
|
||||
public boolean isValid() {
|
||||
if (this.move.getStart().equals(this.move.getFinish()))
|
||||
return false;
|
||||
Piece piece = this.board.pieceAt(move.getStart());
|
||||
if (piece == null)
|
||||
return false;
|
||||
return visit(piece);
|
||||
}
|
||||
|
||||
@@ -62,18 +67,16 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
||||
if (!new PermissiveRuleChecker(this.move).isValidFor(pawn))
|
||||
return false;
|
||||
|
||||
Direction moveDirection = Direction.findDirection(this.move);
|
||||
// ...
|
||||
// moveDirection = Directions(int(findDirection(move)) * pawn.multiplier())
|
||||
Direction moveDirection = Direction.fromInt(Direction.findDirection(move).getIndexOffset() * pawn.multiplier());
|
||||
|
||||
if (moveDirection == Direction.Front)
|
||||
return testPath(pawn.getColor());
|
||||
return testPath(pawn.getColor()) && this.board.pieceAt(this.move.getFinish()) == null;
|
||||
|
||||
assert moveDirection == Direction.FrontLeft || moveDirection == Direction.FrontRight;
|
||||
|
||||
Piece destPiece = this.board.pieceAt(this.move.getFinish());
|
||||
if (destPiece == null)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
return destPiece.getColor() != pawn.getColor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user