Esempio n. 1
0
    public void UpdateTree()
    {
        DeleteNodes(CurrentMoveTree);
        CurrentMoveTree = new MoveTree
        {
            MovesAhead = TreeSize
        };
        CurrentMoveTree.FindAllPossibleMoves(PiecesCreation.BoardLogic, TreeSize);
        CurrentMoveTree.FindTheBestMove(CurrentMoveTree, PiecesCreation.BoardLogic.Turn);

        CreatePhysicalTree(CurrentMoveTree, 0);
        SetNodeParent(null, CurrentMoveTree);
    }
Esempio n. 2
0
    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);
                }
            }
        }
    }