From 7fc63546be7e8a391525144d3c5d45958c24ae0d Mon Sep 17 00:00:00 2001 From: PeterASteele Date: Sun, 19 May 2019 11:56:54 -0700 Subject: [PATCH 1/2] adjust king attack logic to check for 1 square away including diagonals instead of sqrt method --- .../com/mountainreacher/chess/model/ClassicBoard.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java b/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java index 7efdb54..793d18a 100644 --- a/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java +++ b/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java @@ -121,7 +121,7 @@ public GenericPiece[] kingIsInDanger() { } return null; } - + protected Piece kingIsInDanger(int kingTeam, int row, int column) { Gdx.app.log(TAG, "Checking king " + kingTeam + "(" + row + "," + column + ")"); for (Piece piece : pieces) { @@ -129,10 +129,11 @@ protected Piece kingIsInDanger(int kingTeam, int row, int column) { // Closeness with the other king if (piece.getFigure() == Piece.KING) { - if (Math.sqrt(Math.pow(piece.getRow() - row, 2) - + Math.pow(piece.getColumn() - column, 2)) < 2) { + int rowDistance = Math.abs(piece.getRow() - row); + int columnDistance = Math.abs(piece.getColumn() - column); + if(Math.max(rowDistance, columnDistance) < 2) { return piece; - } + } } // The other figure types @@ -197,4 +198,4 @@ public void reset() { ((GenericPiece) piece).reset(); } } -} \ No newline at end of file +} From ba00030e3636c386854d3a87dfb5ebe653528223 Mon Sep 17 00:00:00 2001 From: PeterASteele Date: Sun, 19 May 2019 12:00:36 -0700 Subject: [PATCH 2/2] match spacing of surrounding code --- .../com/mountainreacher/chess/model/ClassicBoard.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java b/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java index 793d18a..c7ee55b 100644 --- a/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java +++ b/libgdx/core/src/com/mountainreacher/chess/model/ClassicBoard.java @@ -121,7 +121,7 @@ public GenericPiece[] kingIsInDanger() { } return null; } - + protected Piece kingIsInDanger(int kingTeam, int row, int column) { Gdx.app.log(TAG, "Checking king " + kingTeam + "(" + row + "," + column + ")"); for (Piece piece : pieces) { @@ -129,11 +129,11 @@ protected Piece kingIsInDanger(int kingTeam, int row, int column) { // Closeness with the other king if (piece.getFigure() == Piece.KING) { - int rowDistance = Math.abs(piece.getRow() - row); - int columnDistance = Math.abs(piece.getColumn() - column); - if(Math.max(rowDistance, columnDistance) < 2) { + int rowDistance = Math.abs(piece.getRow() - row); + int columnDistance = Math.abs(piece.getColumn() - column); + if(Math.max(rowDistance, columnDistance) < 2) { return piece; - } + } } // The other figure types