Browse Source

Fixed bug for Queen with negative values

feature-chess
Dion Aliu 3 years ago
parent
commit
4ef75e249b
  1. 2
      src/main/java/Game/ChessObj/ChessFigure.java
  2. 2
      src/test/java/Game/ChessObj/ChessFigureTest.java

2
src/main/java/Game/ChessObj/ChessFigure.java

@ -70,7 +70,7 @@ public class ChessFigure {
return true; return true;
break; break;
case QUEEN: case QUEEN:
if ((dx == dy) || (dx == 0 ^ dy == 0))
if ((Math.abs(dx) == Math.abs(dy)) || (dx == 0 ^ dy == 0))
return true; return true;
break; break;
case CASTLE: case CASTLE:

2
src/test/java/Game/ChessObj/ChessFigureTest.java

@ -68,7 +68,7 @@ class ChessFigureTest {
} }
break; break;
case QUEEN: case QUEEN:
if ((x == y) || (x == 0 ^ y == 0)) {
if (Math.abs(x) == Math.abs(y) || (x == 0 ^ y == 0)) {
assertTrue(figure.isRelativeMoveValid(x, y)); assertTrue(figure.isRelativeMoveValid(x, y));
continue; continue;
} }

Loading…
Cancel
Save