Example #1
0
        private Node Parse()
        {
            Node  n = ParseExpression();
            Token t = PeekToken();

            if (t == Token.Cut)
            {
                Expect(Token.Cut);
                Node n1 = new CutNode(positions.Count);
                positions.Add(n1);
                n = new SequenceNode(n, n1);
                n = new SequenceNode(n, ParseExpression());
            }
            return(n);
        }
Example #2
0
    static void Main(string[] args)
    {
        string[] inputs;
        inputs = Console.ReadLine().Split(' ');
        int N = int.Parse(inputs[0]); // the total number of nodes in the level, including the gateways
        int L = int.Parse(inputs[1]); // the number of links
        int E = int.Parse(inputs[2]); // the number of exit gateways

        Dictionary <int, Node> Nodes = new Dictionary <int, Node>();

        for (int i = 0; i < L; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int N1 = int.Parse(inputs[0]); // N1 and N2 defines a link between these nodes
            int N2 = int.Parse(inputs[1]);
            BuildNodesMap(N1, N2, ref Nodes);

            // Console.Error.WriteLine("{0} {1}", N1, N2);
        }
        // int[] Gateways = new int[E];
        for (int i = 0; i < E; i++)
        {
            int EI = int.Parse(Console.ReadLine()); // the index of a gateway node
            Nodes[EI].SetGateway();
        }



        // game loop
        while (true)
        {
            foreach (var n in Nodes)
            {
                n.Value.SetRank();
            }

            int  AgentID   = int.Parse(Console.ReadLine()); // The index of the node on which the Skynet agent is positioned this turn
            Node AgentNode = Nodes[AgentID];
            AgentNode.SetAgent(true);

            if (AgentNode.Rank == 1)
            {
                AgentNode.CutGatewayLink();
            }
            else
            {
                /* find every rank 2 node
                 * build paths from nodes with 1+ rank
                 * end at rank 0 nodes
                 * store these paths
                 * cut path ending at agent, else shortest path
                 */
                List <List <Node> > Paths = new List <List <Node> >();
                int TopRank       = Nodes.Where(x => !x.Value.Gateway).Select(x => x.Value.Rank).Max();
                var HighRiskNodes = Nodes.Select(x => x.Value).Where(n => n.Rank == TopRank);


                foreach (Node HighRiskNode in HighRiskNodes)
                {
                    BuildPaths(HighRiskNode, new List <Node>(), ref Paths);
                }

                Node CutNode;
                var  OrderedPaths = Paths.OrderBy(p => p.Count());

                var MostUrgentPath = OrderedPaths.First();

                var UrgentPaths = OrderedPaths.Where(p => p.Contains(AgentNode));

                if (UrgentPaths.Count() > 0)
                {
                    MostUrgentPath = UrgentPaths.First();
                }
                CutNode = MostUrgentPath[0];


                Console.Error.WriteLine("Cut: " + CutNode.Id);
                CutNode.CutGatewayLink();
                AgentNode.SetAgent(false);
            }
        }
    }
Example #3
0
		private Node Parse()
		{
			Node n = ParseExpression();
			Token t = PeekToken();
			if (t == Token.Cut)
			{
				Expect(Token.Cut);
				Node n1 = new CutNode(positions.Count);
				positions.Add(n1);
				n = new SequenceNode(n, n1);
				n = new SequenceNode(n, ParseExpression());
			}
			return n;
		}