Пример #1
0
        internal void AddGoalNodes(GraphSearchData gsData, Level level, Entity exceptThisGoal, HashSet <Goal> solvedGoals)
        {
            foreach (var node in Nodes)
            {
                if (node is BoxConflictNode boxNode)
                {
                    level.AddWall(boxNode.Value.Ent.Pos);
                }
            }

            var goalCondition = new Func <(Point pos, int distance), GraphSearcher.GoalFound <(Point pos, int distance)> >(x =>
            {
                return(new GraphSearcher.GoalFound <(Point, int)>(x, PositionHasNode(x.pos)));
            });

            foreach (var goal in level.Goals)
            {
                if (solvedGoals.Contains(goal))
                {
                    continue;
                }
                if (goal.Ent == exceptThisGoal)
                {
                    continue;
                }

                BoxConflictNode node = new BoxConflictNode(new EntityNodeInfo(goal.Ent, goal.EntType));

                List <(Point pos, int distance)> edges = GraphSearcher.GetReachedGoalsBFS(gsData, level, goal.Ent.Pos, goalCondition);
                foreach (var edge in edges.Distinct())
                {
                    if (GetNodeFromPosition(edge.pos) is BoxConflictNode boxEnd)
                    {
                        node.AddEdge(new Edge <DistanceEdgeInfo>(boxEnd, new DistanceEdgeInfo(edge.distance)));
                        boxEnd.AddEdge(new Edge <DistanceEdgeInfo>(node, new DistanceEdgeInfo(edge.distance)));
                    }
                    else if (GetNodeFromPosition(edge.pos) is FreeSpaceNode freeEnd)
                    {
                        node.AddEdge(new Edge <DistanceEdgeInfo>(freeEnd, new DistanceEdgeInfo()));
                        freeEnd.AddEdge(new Edge <DistanceEdgeInfo>(node, new DistanceEdgeInfo()));
                    }
                }

                Nodes.Add(node);
            }

            level.ResetWalls();
        }
Пример #2
0
 internal void AddNode(BoxConflictNode node)
 {
     base.AddNode(node);
     PositionToNode.Add(node.Value.Ent.Pos, node);
 }