Beispiel #1
0
        static bool RunInstrucionToEnd(Instruct ins, List <List <char> > map)
        {
            int xPos = 0;
            int yPos = 0;

            while (true)
            {
                for (int i = 0; i < ins.Count; i++)
                {
                    if (ins[i] == 0)
                    {
                        yPos++;
                    }
                    else
                    {
                        xPos++;
                    }

                    if (map[yPos][xPos] == 'X')
                    {
                        //Console.WriteLine(insGroup);
                        return(false);
                    }
                    else if (map[yPos][xPos] == 'G')
                    {
                        return(true);
                    }
                }
            }
        }
Beispiel #2
0
 public Instruct AddEnd(Instruct instruct2)
 {
     foreach (short i in instruct2)
     {
         this.Add(i);
     }
     return(this);
 }
Beispiel #3
0
 static void PrintInstructions(Instruct ins)
 {
     foreach (int subInstruction in ins)
     {
         Console.Write(string.Format("{0} ", subInstruction));
     }
     Console.Write(Environment.NewLine);
     Console.Write(Environment.NewLine);
 }
Beispiel #4
0
        static void Solve(Instruct insRaw, string username, string password)
        {
            List <string> insString = new List <string>();

            foreach (short i in insRaw)
            {
                if (i == 0)
                {
                    insString.Add("D");
                }
                else if (i == 1)
                {
                    insString.Add("R");
                }
            }
            string joined = string.Join <string>("", insString);


            using (WebClient client = new WebClient())
            {
                client.DownloadData("http://www.hacker.org/runaway/index.php?name=" + username + "&password="******"&path=" + joined);
            }
        }
Beispiel #5
0
        static List <Instruct> GenerateInstructions(int length)
        {
            string          binaryString;
            List <Instruct> instructionSet = new List <Instruct>();

            for (int i = 0; i < (Math.Pow(2, length)); i++)
            {
                binaryString = Convert.ToString(i, 2);
                //Console.WriteLine(binaryString);
                //Instruction is in form {0,0,0,0}
                Instruct instruction = new Instruct();
                instruction.AddEnd(CreateList <short>(length));

                for (int j = binaryString.Length - 1; j >= 0; j--)
                {
                    instruction[j + (length - binaryString.Length)] = Int16.Parse(binaryString[j].ToString());
                }
                instructionSet.Add(instruction);
            }

            //Console.WriteLine("Number of instructions: " + instructionSet.Count + " Number of commands per instruction: " + instructionSet[0].Count);

            return(instructionSet);
        }
Beispiel #6
0
        static List <Instruct> GetFullInstructions(int maxInsLength, int maxIns, List <List <char> > map)
        {
            List <int>      lengths    = GetInstructionLengths(maxInsLength, maxIns);
            List <Instruct> outIns     = new List <Instruct>();
            List <Instruct> workingIns = new List <Instruct>();

            /*foreach (int len in lengths)
             * {
             *  Console.Write(len + ", ");
             * }*/
            int iter = 0;

            foreach (int length in lengths)
            {
                iter++;
                //Console.Write(Environment.NewLine);
                if (workingIns.Count != 0)
                {
                    //PrintInstructions(workingIns);
                    List <Instruct> newInsTemp2 = new List <Instruct>();
                    for (int startInsIndex = 0; startInsIndex < workingIns.Count; startInsIndex++)
                    {
                        Instruct currentInstruct = new Instruct();
                        currentInstruct = workingIns[startInsIndex];
                        List <Instruct> newInsTempBase = new List <Instruct>();
                        List <Instruct> newInsList     = new List <Instruct>();
                        newInsList = RunInstructions(GenerateInstructions(length), map, currentInstruct.EndPos()[1], currentInstruct.EndPos()[0]);
                        //Console.WriteLine(length);
                        //Console.WriteLine("From: ");
                        //PrintInstructions(currentInstruct);
                        //Console.WriteLine("y = " + currentInstruct.EndPos()[0] + ", x = " + currentInstruct.EndPos()[1]);
                        //PrintInstructions(newInsList);
                        //Console.Write(Environment.NewLine);

                        for (int i = 0; i < newInsList.Count; i++)
                        {
                            newInsTempBase.Add(currentInstruct);
                        }
                        //PrintInstructions(newInsTempBase);
                        newInsTemp2 = new List <Instruct>();
                        int k = 0;
                        foreach (Instruct baseIns in newInsTempBase)
                        {
                            Instruct combinedInstruct = new Instruct();
                            combinedInstruct.AddRange(baseIns);
                            combinedInstruct.AddRange(newInsList[k]);
                            newInsTemp2.Add(combinedInstruct);
                            k++;
                        }
                        k = 0;
                        //PrintInstructions(newInsTemp2);
                        outIns.AddRange(newInsTemp2);
                    }
                    ///PrintInstructions(outIns);

                    if (iter == lengths.Count)

                    {
                        return(outIns);
                    }

                    workingIns.RemoveRange(0, workingIns.Count);
                    workingIns.AddRange(outIns);
                    outIns.RemoveRange(0, outIns.Count);
                    //workingIns.RemoveRange(0, workingIns.Count);
                }
                else
                {
                    foreach (Instruct ins in RunInstructions(GenerateInstructions(length), map, 0, 0))
                    {
                        workingIns.Add(ins);
                    }
                    if (GetInstructionLengths(maxInsLength, maxIns).Count == 1)
                    {
                        return(workingIns);
                    }

                    //PrintInstructions(workingIns);
                }
            }
            return(null);
        }