From 4ef75e249bb433518a8394b1cc0d329b676d150f Mon Sep 17 00:00:00 2001 From: Dion Aliu Date: Thu, 3 Feb 2022 15:53:54 +0100 Subject: [PATCH] Fixed bug for Queen with negative values --- src/main/java/Game/ChessObj/ChessFigure.java | 2 +- src/test/java/Game/ChessObj/ChessFigureTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Game/ChessObj/ChessFigure.java b/src/main/java/Game/ChessObj/ChessFigure.java index 029b233..4dd993b 100644 --- a/src/main/java/Game/ChessObj/ChessFigure.java +++ b/src/main/java/Game/ChessObj/ChessFigure.java @@ -70,7 +70,7 @@ public class ChessFigure { return true; break; case QUEEN: - if ((dx == dy) || (dx == 0 ^ dy == 0)) + if ((Math.abs(dx) == Math.abs(dy)) || (dx == 0 ^ dy == 0)) return true; break; case CASTLE: diff --git a/src/test/java/Game/ChessObj/ChessFigureTest.java b/src/test/java/Game/ChessObj/ChessFigureTest.java index 2232596..4144b85 100644 --- a/src/test/java/Game/ChessObj/ChessFigureTest.java +++ b/src/test/java/Game/ChessObj/ChessFigureTest.java @@ -68,7 +68,7 @@ class ChessFigureTest { } break; 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)); continue; }