Пример #1
0
        public Problem()
            : base()
        {
            DirectoryValue robocodeDir = new DirectoryValue {
                Value = @"c:\Thesis\robocode"
            };

            EnemyCollection   robotList = EnemyCollection.ReloadEnemies(robocodeDir.Value);
            FeatureCollection features  = FeatureCollection.ReloadFeatures("");

            robotList.RobocodePath = robocodeDir.Value;

            Parameters.Add(new FixedValueParameter <DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.", robocodeDir));
            Parameters.Add(new FixedValueParameter <IntValue>(NrOfRoundsParameterName, "Number of rounds a robot has to fight against each opponent.", new IntValue(1)));
            Parameters.Add(new ValueParameter <EnemyCollection>(EnemiesParameterName, "The enemies that should be battled.", robotList));
            Parameters.Add(new ValueParameter <FeatureCollection>(FeaturesParameterName, "The enemies that should be battled.", features));

            Encoding = new SymbolicExpressionTreeEncoding(new Grammar(), 1000, 10);
            Encoding.FunctionArguments   = 0;
            Encoding.FunctionDefinitions = 0;

            RegisterEventHandlers();
        }
Пример #2
0
        public static EnemyCollection ReloadEnemies(string robocodeDir)
        {
            EnemyCollection robotList = new EnemyCollection();

            try
            {
                var robotsDir  = new DirectoryInfo(Path.Combine(robocodeDir, "robots"));
                var robotFiles = robotsDir.GetFiles("*", SearchOption.AllDirectories)
                                 .Where(x => x.Extension == ".class" || x.Extension == ".jar");
                var robotSet = new Dictionary <string, StringValue>();
                foreach (var robot in robotFiles)
                {
                    string robotName = Path.Combine(robot.DirectoryName, Path.GetFileNameWithoutExtension(robot.FullName));
                    robotName = robotName.Remove(0, robotsDir.FullName.Length);
                    string[] nameParts = robotName.Split(new[] { Path.DirectorySeparatorChar },
                                                         StringSplitOptions.RemoveEmptyEntries);
                    robotName = string.Join(".", nameParts);
                    robotSet[robot.FullName] = new StringValue(robotName);
                }
                robotList.AddRange(robotSet.Values);

                foreach (var robot in robotList)
                {
                    robotList.SetItemCheckedState(robot, false);
                }
            }
            catch { }

            //select one robot so that if a user tries out the Robocode problem it works with the default settings
            if (robotList.Exists(x => x.Value == sampleRobotToSelect))
            {
                StringValue sampleRobot = robotList.Single(x => x.Value == sampleRobotToSelect);
                robotList.SetItemCheckedState(sampleRobot, true);
            }

            return(robotList);
        }
Пример #3
0
 protected EnemyCollection(EnemyCollection original, Cloner cloner)
     : base(original, cloner)
 {
     RobocodePath = original.RobocodePath;
 }
Пример #4
0
        public static double Evaluate(ISymbolicExpressionTree tree, string path, Robot robot, EnemyCollection enemies, string robotName = null, bool showUI = false, int nrOfRounds = 200)
        {
            if (robotName == null)
            {
                robotName = GenerateRobotName();
            }

            string interpretedTree = InterpretProgramTree(tree.Root, robotName);

            return(RunGamesLocaly(@"c:\Thesis\robocode", interpretedTree, robotName));
        }