Ejemplo n.º 1
0
        public void HasTagTest()
        {
            FilesAndFolderStructure.SetFolder("C:\\Development\\robot-scripts\\jennyvegas");
            FilesAndFolderStructure.FindAllRobotFilesAndAddToStructure();
            string FileName = "C:\\Development\\robot-scripts\\jennyvegas\\Resources\\RegisterForm.robot";

            ThisFile = new RobotFile(FileName);
            Assert.AreEqual(0, ThisFile.HasTag(Forms.FormType.Settings));
            Assert.AreEqual(6, ThisFile.HasTag(Forms.FormType.Variable));
            Assert.AreEqual(9, ThisFile.HasTag(Forms.FormType.Keyword));
        }
Ejemplo n.º 2
0
        // Batch open a bunch of robots
        private void open_robots(String[] filenames)
        {
            foreach (String filename in filenames)
            {
                RobotFile result = RobotFile.OpenFile(filename);

                Robot robot = arena.loadRobot(result);
                robotlist[robot.number].robot = robot;
                robotlist[robot.number].update_info();
                arenaview.Invalidate();
            }
        }
Ejemplo n.º 3
0
        public void ReadVariablesFromFile()
        {
            FilesAndFolderStructure.SetFolder("C:\\Development\\robot-scripts\\jennyvegas");
            FilesAndFolderStructure.FindAllRobotFilesAndAddToStructure();
            string FileName = "C:\\Development\\robot-scripts\\jennyvegas\\Resources\\RegisterForm.robot";

            ThisFile = new RobotFile(FileName);
            List <Variables> VariablesList = new List <Variables>();

            VariablesList = ThisFile.ReadVariablesFromFile();
            Assert.AreEqual(1, VariablesList[0].VariableNames.Count);

            FileName      = "C:\\Development\\robot-scripts\\jennyvegas\\Data\\DepositLocators.robot";
            ThisFile      = new RobotFile(FileName);
            VariablesList = ThisFile.ReadVariablesFromFile();
            Assert.AreEqual(35, VariablesList[0].VariableNames.Count);
        }
Ejemplo n.º 4
0
        // Robot is the only ArenaObject with no OnSpawn.
        internal Robot(Arena P, double X, double Y, int number, RobotFile file) : base(P, X, Y)
        {
            this.number = number;
            this.file   = file;

            interp = new Interpreter(new MemoryStream(file.program));

            // Load all the default registers
            StockRegisters.inject(this);

            team        = 0;
            alive       = true;
            deathReason = DeathReason.Suicided;
            icon        = 0;

            hardware = file.hardware;
            energy   = hardware.energyMax;
            damage   = hardware.damageMax;
            shield   = 0;
            aim      = 90;
            look     = 0;
            scan     = 0;

            collision = false;
            wall      = false;
            friend    = false;
            stunned   = 0;
            hit       = 0;

            kills    = 0;
            survival = 0;
            killTime = new int[6] {
                -1, -1, -1, -1, -1, -1
            };
            deathTime = -1;
            killer    = null;

            // FIXME: actually implement the history
            history = new Int16[50];

            // FIXME: actually implement signals
            signals = new Int16[10];
        }
Ejemplo n.º 5
0
        // Instantiate a Robot based on the loaded RobotFile
        public Robot loadRobot(RobotFile f)
        {
            // FIXME: Can this be done during a match?

            // Arena full?
            if (robots.Count == Constants.MAX_ROBOTS)
            {
                return(null);
            }

            // Try to find a starting position not too close to the other robots.
            // FIXME: construct a list of starting positions in the constructor
            // so the outcome of prng.Next() is consistent.
            int    x, y;
            double dist;

            do
            {
                x    = prng.Next(Constants.ARENA_SIZE - 30) + 15;
                y    = prng.Next(Constants.ARENA_SIZE - 30) + 15;
                dist = 1000;
                foreach (Robot other in robots)
                {
                    double test = Math.Pow(x - other.x, 2) + Math.Pow(y - other.y, 2);
                    if (test < dist)
                    {
                        dist = test;
                    }
                }
            } while (dist < 625);

            // Instantiate
            Robot robot = new Robot(this, x, y, robots.Count, f);

            // Update state
            robots_.Add(robot);
            numAlive++;

            return(robot);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads a robot from stdin
        /// </summary>
        /// <returns>False if the quit character was seen, true otherwise.</returns>
        private bool ReadRobot(string name)
        {
            StringBuilder roboFile = new StringBuilder();
            string        readLine;

            while ((readLine = Console.ReadLine()) != EOF_STR)
            {
                if (readLine == QUIT_STR)
                {
                    return(false);
                }
                roboFile.AppendLine(readLine);
            }
            MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(roboFile.ToString()));

            RobotFile result = new RobotFile();

            result.name = name;
            SourceTestLoader.read(result, ms);
            AddRobot(result);

            return(true);
        }
Ejemplo n.º 7
0
        public void ReadKeywordsFromFileTest()
        {
            FilesAndFolderStructure.SetFolder("C:\\Development\\robot-scripts\\jennyvegas");
            FilesAndFolderStructure.FindAllRobotFilesAndAddToStructure();
            string FileName = "C:\\Development\\robot-scripts\\jennyvegas\\Resources\\RegisterForm.robot";

            ThisFile = new RobotFile(FileName);
            List <Keyword> KeywordsList = new List <Keyword>();

            KeywordsList = ThisFile.ReadKeywordsFromFile();
            Assert.AreEqual(29, KeywordsList.Count);

            /*
             * foreach (Keyword temp in KeywordsList)
             * {
             *  Console.WriteLine(temp.Name);
             *  if (temp.Documentation != null)
             *      Console.WriteLine(temp.Documentation);
             *  if (temp.Keywords != null)
             *      foreach (Keyword t in temp.Keywords)
             *          Console.WriteLine("\t" + t.GetName());
             * }
             */
        }
Ejemplo n.º 8
0
        private void open_robots(String[] filenames)
        {
            foreach (String filename in filenames)
            {
                RobotFile result = RobotFile.OpenFile(filename);

                // Assign a number first, before adding to the lists
                Robot robot = arena.loadRobot(result);
                files[robot.number] = result;

                RobotWidget widget = new RobotWidget();
                robotlist[robot.number] = widget;
                robotvbox.PackStart(widget, false, true, 0);
                widget.robot = robot;
                widget.update_info();

                /* FIXME: implement closing
                 * Gtk.VBox rvbox = new Gtk.VBox();
                 * widget.AddChild(rvbox);
                 * rvbox.Homogeneous = true;
                 *
                 * Gtk.Button closebutton = new Gtk.Button(Stock.Close);
                 * Gtk.Action closeaction = robotactions[robot.number].getRobotAction("CloseAction");
                 * closeaction.ConnectProxy(closebutton);
                 * rvbox.PackStart(closebutton);
                 */

                widget.ShowAll();

                Gtk.HSeparator rsep = new Gtk.HSeparator();
                robotvbox.PackStart(rsep, false, true, 0);
                rsep.ShowAll();

                arenaview.QueueDraw();
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds a robot to the arena.
 /// </summary>
 /// <param name="file"></param>
 public void AddRobot(RobotFile file)
 {
     robots.Add(new RobotWrapper(arena.loadRobot(file)));
 }
        public Keyword GetDataForInternalKeywords(Keyword keyword, RobotFile file)
        {
            var returnKeyword = new Keyword(keyword.Parent);

            returnKeyword.CopyKeyword(keyword);
            returnKeyword.Keywords = new List <Keyword>();

            foreach (Keyword currentKeyword in keyword.Keywords)
            {
                var tempKeyword = new Keyword(keyword);
                tempKeyword.CopyKeyword(currentKeyword);
                if (currentKeyword.Type == KeywordType.Custom)
                {
                    if (currentKeyword.ImportFileName != null && !currentKeyword.ImportFileName.Equals(""))
                    {
                        foreach (RobotFile importFile in RobotFiles)
                        {
                            if (importFile.fileName.EndsWith("\\" + currentKeyword.ImportFileName + ".robot"))
                            {
                                foreach (Keyword importKeyword in importFile.KeywordsList)
                                {
                                    if (importKeyword.Name.Equals(currentKeyword.Name))
                                    {
                                        if (currentKeyword.Params != null && currentKeyword.Params.Count > 0)
                                        {
                                            for (int i = 0; i < currentKeyword.Params.Count; i++)
                                            {
                                                tempKeyword.Params[i].Name = importKeyword.Params[i].Name;
                                            }
                                        }
                                        tempKeyword.Keywords.AddRange(importKeyword.Keywords);
                                        tempKeyword.OutputFilePath = importFile.fileName;
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        bool isFound = false;
                        foreach (string fileName in file.resources)
                        {
                            foreach (RobotFile importFile in RobotFiles)
                            {
                                if (importFile.fileName.Equals(fileName))
                                {
                                    foreach (Keyword importKeyword in importFile.KeywordsList)
                                    {
                                        if (importKeyword.Name.Equals(currentKeyword.Name))
                                        {
                                            if (currentKeyword.Params != null && currentKeyword.Params.Count > 0)
                                            {
                                                for (int i = 0; i < currentKeyword.Params.Count; i++)
                                                {
                                                    tempKeyword.Params[i].Name = importKeyword.Params[i].Name;
                                                }
                                            }
                                            tempKeyword.Keywords.AddRange(importKeyword.Keywords);
                                            tempKeyword.OutputFilePath = importFile.fileName;
                                            isFound = true;
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            if (isFound)
                            {
                                break;
                            }
                        }
                    }

                    if (tempKeyword.Keywords != null && tempKeyword.Keywords.Count > 0)
                    {
                        foreach (RobotFile importFile in RobotFiles)
                        {
                            if (importFile.fileName.Equals(tempKeyword.OutputFilePath))
                            {
                                GetDataForInternalKeywords(tempKeyword, importFile);
                                break;
                            }
                        }
                    }
                }

                returnKeyword.Keywords.Add(tempKeyword);
            }

            return(returnKeyword);
        }
Ejemplo n.º 11
0
        public static void LoadStartHeader()
        {
            // Load the header and robots from the file

            byte[] buffer = new byte[258];
            f.Read(buffer, 0, 8);
            Debug.Assert(MacUtil.readString(buffer, 0, 4) == "RDMP");
            int seed    = MacUtil.read16(buffer, 4);
            int numBots = MacUtil.read16(buffer, 6);

            Debug.Assert(numBots < 7);

            robotFiles = new RobotFile[numBots];
            for (int i = 0; i < numBots; i++)
            {
                RobotFile nf = new RobotFile();
                robotFiles[i] = nf;

                f.Read(buffer, 0, 258);
                Debug.Assert(buffer[0] > 0);
                nf.name = MacUtil.readString(buffer, 1, buffer[0]);
                int progLen = MacUtil.read16(buffer, 256);
                Debug.Assert(progLen <= (int)Bytecodes.NUM_MAX_CODE);

                nf.program = new byte[progLen * 2];
                f.Read(nf.program, 0, progLen * 2);

                f.Read(buffer, 0, 40);

                nf.hardware.energyMax      = MacUtil.read16(buffer, 0);
                nf.hardware.damageMax      = MacUtil.read16(buffer, 2);
                nf.hardware.shieldMax      = MacUtil.read16(buffer, 4);
                nf.hardware.processorSpeed = MacUtil.read16(buffer, 6);
                int gun = MacUtil.read16(buffer, 8);
                switch (gun)
                {
                case 1: nf.hardware.gunType = BulletType.Rubber; break;

                case 3: nf.hardware.gunType = BulletType.Explosive; break;

                case 2:
                default: nf.hardware.gunType = BulletType.Normal; break;
                }
                nf.hardware.hasMissiles       = MacUtil.read16(buffer, 10) > 0;
                nf.hardware.hasTacNukes       = MacUtil.read16(buffer, 12) > 0;
                nf.hardware.hasLasers         = MacUtil.read16(buffer, 16) > 0;
                nf.hardware.hasHellbores      = MacUtil.read16(buffer, 18) > 0;
                nf.hardware.hasDrones         = MacUtil.read16(buffer, 20) > 0;
                nf.hardware.hasMines          = MacUtil.read16(buffer, 22) > 0;
                nf.hardware.hasStunners       = MacUtil.read16(buffer, 24) > 0;
                nf.hardware.noNegEnergy       = MacUtil.read16(buffer, 26) > 0;
                nf.hardware.probeFlag         = MacUtil.read16(buffer, 28) > 0;
                nf.hardware.deathIconFlag     = MacUtil.read16(buffer, 30) > 0;
                nf.hardware.collisionIconFlag = MacUtil.read16(buffer, 32) > 0;
                nf.hardware.shieldHitIconFlag = MacUtil.read16(buffer, 34) > 0;
                nf.hardware.hitIconFlag       = MacUtil.read16(buffer, 36) > 0;
                nf.hardware.shieldOnIconFlag  = MacUtil.read16(buffer, 38) > 0;

                int advantages = MacUtil.read16(buffer, 14);
                Debug.Assert(advantages == nf.hardware.advantages);
            }

            // Print info header
            Console.WriteLine("Replaying match with mac seed {0} and {1} robot(s):",
                              seed, numBots);
            string[] names = new string[numBots];
            for (int i = 0; i < numBots; i++)
            {
                names[i] = robotFiles[i].name;
            }
            Console.WriteLine(String.Join(", ", names));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Parses out the commandline arguments into the arena
        /// </summary>
        /// <param name="args">The list of commandline arguments</param>
        /// <param name="ha">The instance of the headless arena</param>
        /// <returns>true if the parsing was successful, false otherwise</returns>
        static bool parseArgs(string[] args, HeadlessArena ha)
        {
            if (args.Length == 0)
            {
                showHelp();
                return(false);
            }

            for (int i = 0; i < args.Length; i++)
            {
                // parse out chronon's per second
                if (args[i] == "-cpu")
                {
                    int?cs = loadNextInt("-cpu", args, i);
                    if (cs.HasValue)
                    {
                        ha.ChrononsPerUpdate = cs.Value;
                        i++;
                    }
                    else
                    {
                        return(false);
                    }
                }
                // parse out updates per second
                else if (args[i] == "-cl")
                {
                    int?us = loadNextInt("-cl", args, i);
                    if (us.HasValue)
                    {
                        ha.ChrononLimit = us.Value;
                        i++;
                    }
                    else
                    {
                        return(false);
                    }
                }
                // check for interactive mode
                else if (args[i] == "-i")
                {
                    ha.InteractiveMode = true;
                }
                // show help when requested
                else if (args[i].ToLower() == "-h")
                {
                    showHelp();
                    return(false);
                }
                // otherwise, assume it's a filename and try to load it
                else
                {
                    try
                    {
                        ha.AddRobot(RobotFile.OpenFile(args[i]));
                    }
                    catch (Exception e)
                    {
                        showError(String.Format("Unable to load robot file: {0}\n {1}",
                                                args[i], e.Message));
                    }
                }
            }
            return(true);
        }