コード例 #1
0
ファイル: MapObject.cs プロジェクト: komastar/TileTraveler
    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
ファイル: MapObject.cs プロジェクト: komastar/TileTraveler
    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;
                        }
                    }
                }
            }
        }
    }
コード例 #3
0
ファイル: MapObject.cs プロジェクト: komastar/TileTraveler
    public void GetScore(ScoreViewModel scoreViewModel)
    {
        connExits.Clear();
        foreach (var node in entireNodes)
        {
            if (node.Value.NodeType == ENodeType.Entrance)
            {
                connExits.Add(node.Value, new HashSet <Vector2Int>()
                {
                    node.Value.Position
                });
            }
        }

        foreach (var node in connExits)
        {
            for (int i = 0; i < 4; i++)
            {
                CollectNeighborRecursive(node.Key, node.Key.Neighbors[i], i);
            }
        }

        Dictionary <SortedSet <NodeObject>, int> exitScore = new Dictionary <SortedSet <NodeObject>, int>();
        HashSet <Vector2Int> passNode = new HashSet <Vector2Int>();

        foreach (var node in connExits)
        {
            if (passNode.Contains(node.Key.Position))
            {
                continue;
            }

            SortedSet <NodeObject> exitGroup = new SortedSet <NodeObject>();
            foreach (var comp in connExits)
            {
                if (node.Key.Position != comp.Key.Position)
                {
                    if (node.Value.Contains(comp.Key.Position) && comp.Value.Contains(node.Key.Position))
                    {
                        exitGroup.Add(node.Key);
                        exitGroup.Add(comp.Key);
                        passNode.Add(node.Key.Position);
                        passNode.Add(comp.Key.Position);
                    }
                }
            }
            if (exitGroup.Count > 1)
            {
                exitScore.Add(exitGroup, node.Value.Count);
            }
        }

        int networkScore = 0;

        foreach (var score in exitScore)
        {
            int scoreCalc = (score.Key.Count - 1) * 4;
            networkScore += scoreCalc;
            Log.Debug($"Score : {scoreCalc}");
        }

        Log.Debug($"TotalNetworkScore : {networkScore}");
        scoreViewModel.NetworkScore = networkScore;

        List <NodeObject> rails = new List <NodeObject>();
        List <NodeObject> roads = new List <NodeObject>();

        foreach (var node in entireNodes)
        {
            if (node.Value.NodeType == ENodeType.Entrance)
            {
                continue;
            }

            if (node.Value.IsRailRoute)
            {
                rails.Add(node.Value);
            }

            if (node.Value.IsRoadRoute)
            {
                roads.Add(node.Value);
            }
        }

        HashSet <NodeObject> visited = new HashSet <NodeObject>();
        int railScore = 0;

        foreach (var rail in rails)
        {
            visited.Clear();
            int currentRailScore = CalcLongestWayScoreRecursive(rail, EJointType.Rail, ref visited);
            railScore = railScore < currentRailScore ? currentRailScore : railScore;
        }

        int roadScore = 0;

        foreach (var road in roads)
        {
            visited.Clear();
            int currentRoadScore = CalcLongestWayScoreRecursive(road, EJointType.Road, ref visited);
            roadScore = roadScore < currentRoadScore ? currentRoadScore : roadScore;
        }

        Log.Debug($"TotalRailScore : {railScore}");
        Log.Debug($"TotalRoadScore : {roadScore}");
        scoreViewModel.RailScore = railScore;
        scoreViewModel.RoadScore = roadScore;

        int penaltyScore = 0;

        foreach (var node in entireNodes.Values)
        {
            if (!IsEdgeNode(node))
            {
                for (int i = 0; i < 4; i++)
                {
                    EJointType joint = node.GetJoint(i);
                    if (joint != EJointType.None)
                    {
                        Vector2Int neighborPos = node.Position + Direction[i];
                        if (entireNodes.ContainsKey(neighborPos))
                        {
                            NodeObject neighbor = entireNodes[neighborPos];
                            if (!IsEdgeNode(neighbor))
                            {
                                EJointType nJoint = neighbor.GetJoint2(i);
                                if (joint != nJoint)
                                {
                                    penaltyScore++;
                                }
                            }
                        }
                    }
                }
            }
        }

        Log.Debug($"TotalFaultScore : {penaltyScore}");
        scoreViewModel.PenaltyScore = penaltyScore;
        scoreViewModel.Calculate();
    }