Ejemplo n.º 1
0
        private void StartNewGame()
        {
            listBox1.Items.Clear();
            //var controller = new Keyboard(this);
            //var controller = new ProcessAI(new SimpleAI());
            //var controller = new ProcessAI(new KillerAI(8, 5)); // !!!
            //var controller = new ProcessAI(new LookingAI(1));

            //var controller = new ProcessAI(new WaveAI_2()); // !!!
            var controller = new ProcessAI(new KillerFallingAI());
            //var controller = new ProcessAI(new CollectorAI());
            //var controller = new ProcessAI(new CollectorAI_2());

            var world = default(World);

            // 14, 8080 !!! - validate check access to diamonds
            // 280, 301, 540
            // JS: 5, 11
            world = LoadFromFile2(8080, 0);//, true);

            _game          = new Game(controller, world);
            _world         = _game.world;
            _game.interval = 50;
            _game.start();
        }
Ejemplo n.º 2
0
        private void ProcessGames(IEnumerable <int> seeds)
        {
            var count   = seeds.Count();
            var counter = 0;

            KillerFallingAI.Logging = false;
            Timings.Clear();
            var data = seeds.AsParallel()
                       .Select(seed =>
            {
                var n     = System.Threading.Interlocked.Add(ref counter, 1);
                var watch = new System.Diagnostics.Stopwatch();
                watch.Start();
                var world = LoadFromFile2(seed, 0);     // 2
                var ai    = new WaveAI_2();
                //var ai = new CollectorAI_2(); world.frames_left = 800;
                //var ai = new KillerFallingAI(); world.frames_left = 600;
                var controller = new ProcessAI(ai);
                var game       = new Game(controller, world, seed);
                game.interval  = 0;
                game.start();
                watch.Stop();
                var txt = string.Format("[{0}/{1}] seed: {2} elapsed: {3:#0.0} sec",
                                        n, count, seed, watch.Elapsed.TotalSeconds);
                System.Diagnostics.Trace.WriteLine(txt);
                return(game.log);
            })
                       .OrderBy(x => x.seed)
                       .ToArray();

            var header = "seed\tscore\tdiamonds\tbufferfies\tstreaks\tlongest\tframes\toutcome";
            var lines  = data.Select(x => string.Join("\t", x.seed, x.score, x.diamonds_collected, x.butterflies_killed, x.streaks, x.longest_streak, x.duration_frames, x.outcome));

            System.IO.File.WriteAllLines("logs\\" + DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss"),
                                         new[] { header }.Concat(lines));

            var avg = data.Average(x => (float)x.score);
            var std = Math.Sqrt(data.Average(x => Math.Pow(x.score - avg, 2)));

            Game.log_function("");
            Game.log_function("total: " + data.Sum(x => x.score) + " of " + data.Length + " games");
            Game.log_function("avg:   " + avg);
            Game.log_function("std:   " + std);
            Game.log_function("killed: " + data.Sum(x => x.butterflies_killed) + ", avg: " + data.Average(x => (float)x.butterflies_killed));
            Game.log_function("");
            foreach (var s in Timings.ToString())
            {
                Game.log_function(s);
            }
        }