public static int GetSizeOfTargetCluster(GameObject candidateNode, int targetTeam, List <GameObject> nodesList)
    {
        int        clusterSize     = 0;
        int        newDirection    = (candidateNode.GetComponent <Node>().direction + 1) % 4;
        GameObject destinationNode = TilesHelper.GetNeighbor(candidateNode, newDirection, nodesList);

        if (destinationNode != null)
        {
            int targetOwner = destinationNode.GetComponent <Node>().owner;
            if (targetOwner == targetTeam)
            {
                clusterSize = TilesHelper.GetClusterSize(destinationNode, nodesList);
            }
        }
        return(clusterSize);
    }
Exemple #2
0
    private GameObject CaptureInTwo(int targetTeam, List <GameObject> nodesList)
    {
        foreach (GameObject candidateNode in nodesList)
        {
            if (candidateNode.GetComponent <Node>().owner == team)
            {
                int        newDirection    = (candidateNode.GetComponent <Node>().direction + 2) % 4;
                GameObject destinationNode = TilesHelper.GetNeighbor(candidateNode, newDirection, nodesList);
                if (destinationNode != null)
                {
                    int targetOwner = destinationNode.GetComponent <Node>().owner;
                    if (targetOwner == targetTeam)
                    {
                        return(candidateNode);
                    }
                }
            }
        }

        return(null);
    }
Exemple #3
0
    int Propagate(GameObject source, int newOwner, int PreviousConverted)
    {
        int maxDepth = 1;

        //Rotate node
        source.GetComponent <Node>().ChangeOwner(newOwner);

        StartCoroutine(WaitForPlay(source, newOwner, PreviousConverted));

        // Update the target node
        int        targetDirection = source.GetComponent <Node>().direction;
        GameObject targetNeighbor  = TilesHelper.GetNeighbor(source, targetDirection, btns);

        if (targetNeighbor != null)
        {
            if (targetNeighbor.GetComponent <Node>().owner != newOwner)
            {
                maxDepth = Mathf.Max(maxDepth + 1, Propagate(targetNeighbor, newOwner, PreviousConverted + 1));
            }
        }

        // Update neighbors pointing to currentNode
        for (int neighDirection = 0; neighDirection < 4; neighDirection++)
        {
            GameObject neighbor = TilesHelper.GetNeighbor(source, neighDirection, btns);
            if (neighbor != null)
            {
                if (neighbor.GetComponent <Node>().owner != newOwner)
                {
                    if (neighbor.GetComponent <Node>().direction == (neighDirection + 2) % 4)
                    {
                        maxDepth = Mathf.Max(maxDepth + 1, Propagate(neighbor, newOwner, PreviousConverted + 1));
                    }
                }
            }
        }

        return(Mathf.Max(maxDepth, PreviousConverted + 1));
    }