Пример #1
0
        public shootMup()
        {
            InitializeComponent();

            try
            {
                SuspendLayout();

                // initial setup
                AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
                AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
                ClientSize          = new System.Drawing.Size(1484, 1075);
                Name           = "shootMup";
                Text           = "shootMup";
                DoubleBuffered = true;

                // generate players
                var human = new ShootMPlayer()
                {
                    Name = "You"
                };
                var players = new Player[100];
                for (int i = 0; i < players.Length; i++)
                {
                    players[i] = new SimpleAI()
                    {
                        Name = string.Format("ai{0}", i)
                    }
                }
                ;

                // generate the world
                World = WorldGenerator.Generate(WorldType.Random, PlayerPlacement.Borders, human, ref players);

                // if we are training for AI, then capture telemetry
                World.OnBeforeAction += AITraining.CaptureBefore;
                World.OnAfterAction  += AITraining.CaptureAfter;
                World.OnDeath        += (elem) =>
                {
                    if (elem is Player)
                    {
                        var winners = new List <string>();

                        // capture the winners
                        foreach (var player in players)
                        {
                            winners.Add(string.Format("{0} [{1}]", player.Name, player.Kills));
                        }

                        AITraining.CaptureWinners(winners);
                    }
                };

                UI = new UIHookup(this, World);
            }
            finally
            {
                ResumeLayout(false);
            }
        }
Пример #2
0
        public static int Run(string type)
        {
            Console.WriteLine("Starting execution for {0}...", type);

            // generate the world
            var human = new ShootMPlayer()
            {
                Name = "human"
            };
            var players = new Player[100];

            for (int i = 0; i < players.Length; i++)
            {
                switch (type.ToLower())
                {
                case "ml":
                    players[i] = new TrainedAI(TrainedAIModel.ML_Net)
                    {
                        Name = string.Format("ai{0}", i)
                    };
                    break;

                case "cv":
                    players[i] = new TrainedAI(TrainedAIModel.OpenCV)
                    {
                        Name = string.Format("ai{0}", i)
                    };
                    break;

                default:
                    throw new Exception("Unknown model type " + type);
                }
            }
            var world = WorldGenerator.Generate(WorldType.Random, PlayerPlacement.Borders, human, ref players);

            // initialize with a void UI/Sound to display too
            world.InitializeGraphics(new VoidSurface(), new VoidSound());

            // start the game
            world.KeyPress(Constants.Esc);

            // ensure there are no blocking menus
            world.OnPaused += () => { return(null); };

            // wait until it is done or 1 minute has passed
            var timer = new Stopwatch();

            timer.Start();
            while (world.Alive > 1 && timer.ElapsedMilliseconds < (60 * 1024))
            {
                Console.WriteLine("Alive - {0}", world.Alive);
                System.Threading.Thread.Sleep(1000);
            }
            timer.Stop();

            // pause the game
            world.KeyPress(Constants.Esc);

            Console.WriteLine("Finished with {0} alive and {1} ms time executed", world.Alive, timer.ElapsedMilliseconds);

            return(0);
        }