From a05e4b23a7e26e2abf5c06e1b5624d1aea58e631 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Sun, 30 Jan 2022 22:16:15 +0100 Subject: [PATCH] TEMP commit for later pull and deletion --- src/main/java/Game/ChessObj/ChessBoard.java | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/Game/ChessObj/ChessBoard.java b/src/main/java/Game/ChessObj/ChessBoard.java index 8477a4b..0fc39c4 100644 --- a/src/main/java/Game/ChessObj/ChessBoard.java +++ b/src/main/java/Game/ChessObj/ChessBoard.java @@ -82,6 +82,32 @@ public class ChessBoard { return false; } + public boolean validateMove(int sourceX, int sourceY, int destX, int destY) { + if (!isCellInBoard(sourceX, sourceY) || !isCellInBoard(destX, destY)) + return false; + ChessFigure figure = board[sourceY][sourceX]; + if(board[destY][destX] == null || (board[destY][destX].getTeam() != figure.getTeam())) + return false; + int deltaX = destX - sourceX; + int deltaY = sourceY - destY; + //Pawn special case + if(figure.getType() == ChessFigure.Type.PAWN){ + //FUCKED Pawn can destroy Enemy backwards + if((deltaX == -1 || deltaX == 1) && (deltaY == 1 || deltaY == -1) && (board[destY][destX] != null && board[destY][destX].getTeam() != figure.getTeam())) + return true; + if(figure.isRelativeMoveValid(deltaX, deltaY)) + return true; + } + if(figure.isRelativeMoveValid(deltaX, deltaY)){ + if(figure.getType() == ChessFigure.Type.KNIGHT) + return true; + if(validateCleanPath(sourceX, sourceY, destX, destY)) + return true; + } + + return false; + } + protected boolean validateCleanPath(int sourceX, int sourceY, final int destX, final int destY) { int deltaX = destX - sourceX; int deltaY = destY - sourceY;