Пример #1
0
    private void CollectNeighborRecursive(NodeObject root, NodeObject neighbor, int direction)
    {
        if (!ReferenceEquals(null, neighbor))
        {
            if (!connExits[root].Contains(neighbor.Position))
            {
                connExits[root].Add(neighbor.Position);
                for (int i = 0; i < 4; i++)
                {
                    if (!neighbor.RouteData.IsTransfer &&
                        neighbor.GetJoint2(direction) != neighbor.GetJoint(i))
                    {
                        continue;
                    }

                    var newNeighbor = neighbor.Neighbors[i];
                    if (!ReferenceEquals(null, newNeighbor))
                    {
                        if (neighbor.GetJoint(i) == newNeighbor.GetJoint2(i))
                        {
                            CollectNeighborRecursive(root, newNeighbor, i);
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    public bool IsConstructable(NodeObject node)
    {
        int matchCount   = 0;
        int connectCount = 0;

        for (int i = 0; i < Direction.Length; i++)
        {
            Vector2Int neighborPos = node.Position + Direction[i];
            var        neighbor    = entireNodes[neighborPos];
            if (neighbor.NodeType == ENodeType.Wall)
            {
                connectCount++;
                continue;
            }

            EJointType joint         = node.GetJoint(i);
            EJointType neighborJoint = neighbor.GetJoint2(i);
            if (joint == EJointType.None ||
                neighborJoint == EJointType.None)
            {
                connectCount++;
            }
            else if (joint == neighborJoint)
            {
                connectCount++;
                matchCount++;
            }
        }

        Log.Debug($"Connect : {connectCount} / {matchCount}");

        return((connectCount == 4) && (matchCount > 0));
    }
Пример #3
0
    private void FixNode(NodeObject node)
    {
        Vector2Int pos = node.Position;

        for (int i = 0; i < Direction.Length; i++)
        {
            EJointType joint = node.GetJoint(i);
            if (joint != EJointType.None)
            {
                if (node.Neighbors[i] == null)
                {
                    Vector2Int neighborPos = pos + Direction[i];
                    if (entireNodes.ContainsKey(neighborPos))
                    {
                        NodeObject neighbor = entireNodes[neighborPos];
                        EJointType nJoint   = neighbor.GetJoint2(i);
                        if (joint == nJoint)
                        {
                            node.Neighbors[i] = neighbor;
                            neighbor.Neighbors[(i + 2) % 4] = node;
                        }
                    }
                }
            }
        }
    }
Пример #4
0
    private int CalcLongestWayScoreRecursive(NodeObject node, EJointType joint, ref HashSet <NodeObject> visited)
    {
        int highestScore = 0;

        visited.Add(node);
        if (node.NodeType == ENodeType.Entrance)
        {
            return(0);
        }

        for (int i = 0; i < 4; i++)
        {
            var joint1 = node.GetJoint(i);
            if (joint == joint1)
            {
                var neighbor = node.Neighbors[i];
                if (!ReferenceEquals(null, neighbor))
                {
                    if (!visited.Contains(neighbor))
                    {
                        var joint2 = neighbor.GetJoint2(i);
                        if (joint1 == joint2)
                        {
                            int score = CalcLongestWayScoreRecursive(neighbor, joint, ref visited);
                            highestScore = score > highestScore ? score : highestScore;
                        }
                    }
                }
            }
        }

        return(1 + highestScore);
    }