From e234eb2e500e1afe839941ebfae105cf2d81dd89 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Tue, 1 Feb 2022 00:09:34 +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; }