示例#1
0
 /*Because the exit node being a bridge is unacceptable.*/
 public Node(Bridge b)
 {
     id = b.id;
     while (b.neighbors.Count > 0)
     {
         connect(b.neighbors[0]);
         b.disconnect(b.neighbors[0]);
     }
     packs = b.packs;
     items = b.items;
 }
示例#2
0
 /* To disconnect a bridge from the rest of the zone the bridge is in. */
 public void disconnect(Bridge b)
 {
     Logger.log("Disconnecting the bridge " + b.id + " from its zone.");
     for (int i = 0; i < b.GetFromNodes.Count; i++)
     {
         b.disconnect(b.GetFromNodes[i]);
     }
     //int z = int.Parse(b.id.Split()[1]);
     //b.toggleAlert(zone[z],false);
     //zone[z].Remove(b);//else node are allerted again if there is a fight on
 }
示例#3
0
        /*Tuple contains the remaining connections from the bridge,
        *  the amount of nodes, and the total amount of connections.*/
        private Tuple <int, int, int> makeSection(Node start, int startc, ref int level)
        {
            Bridge b      = new Bridge(level.ToString());
            Bridge bstart = start as Bridge;

            if (startc == 1) //can only be directly connected to a bridge
            {
                level++;
                b.connectToNodeOfSameZone(start);
                if (bstart != null)
                {
                    bstart.connectToNodeOfNextZone(b);
                    bstart.disconnect(b);
                }
                if (level > difficultyLevel + 1)
                {
                    exitNode = new Node(b);
                }
                else
                {
                    bridges[level - 2] = b;
                }
                return(Tuple.Create(rng.Next(1, 4), 1, 1));
            }
            HashSet <int> open       = new HashSet <int>();
            List <Node>   nodes      = new List <Node>();
            List <int>    conns      = new List <int>();
            int           totalConns = 0;

            open.Add(0);
            nodes.Add(start);
            conns.Add(startc);
            int index;

            while (open.Count > 1 || open.Contains(0))
            {
                Node n = new Node();
                index = nodes.Count;
                open.Add(index);
                nodes.Add(n);
                conns.Add(rng.Next(1, 5));
                for (int i = 0; i < index; i++)
                {
                    if (open.Contains(i) && conns.Sum() > open.Count)
                    {
                        totalConns++;
                        nodes[i].connect(n);
                        conns[i]--;
                        if (conns[i] == 0)
                        {
                            open.Remove(i);
                        }
                        conns[index]--;
                        if (conns[index] == 0)
                        {
                            open.Remove(index);
                            break;
                        }
                    }
                }
            }
            if (bstart != null)
            {
                bstart.toNodes = bstart.neighbors.Except(bstart.fromNodes).ToList();
            }
            index = open.Single();
            foreach (Node nd in shortestpath(start, nodes[index])
                     .Where(m => m == nodes[index] || p.isBridge(start, nodes[index], m)))
            {
                level++;
                if (level > difficultyLevel + 1)
                {
                    exitNode    = nd;
                    exitNode.id = "exit";
                    break;
                }
                else
                {
                    var nb = nd.neighbors;
                    while (nb.Count > 0)
                    {
                        Node m = nb[0];
                        m.disconnect(nd);
                        if (p.isReachable(start, m))
                        {
                            b.connectToNodeOfSameZone(m);
                        }
                        else
                        {
                            b.connectToNodeOfNextZone(m);
                        }
                    }
                    bridges[level - 2] = b;
                    b = new Bridge(level.ToString());
                }
            }
            return(Tuple.Create(conns[index], nodes.Count - 1, totalConns));
        }