public List <Vector2Int> FindFullAtackMove(BoardLogic startingBoardLogic, Checker checker, int k) { List <Vector2Int> atackMoves = new List <Vector2Int>(); char startingTurn = startingBoardLogic.Turn; while (startingTurn == startingBoardLogic.Turn) { for (int x = -k; x <= k; x += 1) { for (int y = -k; y <= k; y += 1) { if (Math.Abs(x) != Math.Abs(y)) { continue; } if (startingBoardLogic.MoveChecker(startingBoardLogic.Checkers, checker, checker.PositionX + x, checker.PositionY + y) == true) { atackMoves.Add(new Vector2Int(checker.PositionX, checker.PositionY)); x = -k; y = -k; } } } } return(atackMoves); }
public void OnDrop(PointerEventData eventData) { if (eventData.pointerDrag != null) { if (eventData.pointerDrag != null) { //board Logic BoardLogic boardLogic = PiecesCreation.BoardLogic; char turn = boardLogic.Turn; int oldX = eventData.pointerDrag.GetComponent <Coordinates>().X; int oldY = eventData.pointerDrag.GetComponent <Coordinates>().Y; int newX = GetComponent <Coordinates>().X; int newY = GetComponent <Coordinates>().Y; Debug.Log(oldX + " " + oldY + " " + newX + " " + newY); if (boardLogic.MoveChecker(boardLogic.Checkers, boardLogic.FindChecker(boardLogic.Checkers, oldX, oldY), newX, newY) == true) { eventData.pointerDrag.GetComponent <Coordinates>().X = newX; eventData.pointerDrag.GetComponent <Coordinates>().Y = newY; if (boardLogic.delX != -1 && boardLogic.delY != -1) { GameObject piece = FindCheckerToDestroy(boardLogic); if (piece != null) { Destroy(piece); } } if (boardLogic.FindChecker(boardLogic.Checkers, newX, newY).isQueen == true) { eventData.pointerDrag.GetComponent <RectTransform>().sizeDelta = new Vector2(45, 45); } MovePieceToField(eventData.pointerDrag, gameObject); /* Debug.Log(boardLogic.Turn); * Debug.Log(boardLogic.IsMoveAtack); * Debug.Log(boardLogic.FindChecker(boardLogic.Checkers, newX, newY).isQueen); */ if (boardLogic.Turn != turn && GameObject.Find("AI").GetComponent <AILogic>().IsAIOn == true) { StartCoroutine("UpdateTree"); //opoznienie // StartCoroutine("UpdateTree"); } // GameObject.Find("TreeBoard").GetComponent<TreeCreation>().UpdateTree(); } } } }
public void FindAllPossibleMovesForChecker(BoardLogic startingBoardLogic, Checker checker, int movesAhead) { Vector2Int startingCoords = new Vector2Int(checker.PositionX, checker.PositionY); int k; if (checker.isQueen == true) { k = 7; } else if (startingBoardLogic.SearchForNormalAtackForChecker(startingBoardLogic.Checkers, checker) == true) { k = 2; } else { k = 1; } BoardLogic boardLogic = startingBoardLogic.CopyBoard(); checker = boardLogic.FindChecker(boardLogic.Checkers, checker.PositionX, checker.PositionY); for (int x = -k; x <= k; x += 1) { for (int y = -k; y <= k; y += 1) { if (x == 0 || y == 0) { continue; } if (Math.Abs(x) - Math.Abs(y) != 0) { continue; } int newX = checker.PositionX + x; int newY = checker.PositionY + y; if (newX < 0 || newX > 7 || newY < 0 || newY > 7) { continue; } if (boardLogic.MoveChecker(boardLogic.Checkers, checker, newX, newY) == true) { if (newX == 5 && newY == 2) { } MoveTree movement = CreateMoveTreeNode(boardLogic, checker, movesAhead, startingCoords, k); movement.EvaluateMovement(); Moves.Add(movement); //next moves if (movement.MovesAhead > 0) { movement.FindAllPossibleMoves(boardLogic, movement.MovesAhead); } //cleanup boardLogic = startingBoardLogic.CopyBoard(); checker = boardLogic.FindChecker(boardLogic.Checkers, startingCoords.x, startingCoords.y); } } } }