Esempio n. 1
0
        public Form1(string name,Simulator sim)
        {
            simulator = sim;
            map = sim.map;
            InitializeComponent();

            this.Text = name;

            pictureBox1.Width = CELL_SIZE * (map.width - map.height / 2) + CELL_SIZE / 2;
            pictureBox1.Height = CELL_SIZE * map.height;

            image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            render();
        }
Esempio n. 2
0
        static void Main(String[] args)
        {
            if (args.Length != 4 && args.Length !=5)
            {
                Console.WriteLine("Ant simulator (from ICFPC 2004)");
                Console.WriteLine("Usage:");
                Console.WriteLine("       simulator.exe <world> <ant1> <ant2> <randseed> [-nogui]");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Map m = new Map(args[0]);

            Automaton redProgram = new Automaton(args[1]);
            Automaton blackProgram = new Automaton(args[2]);

            int seed = Int32.Parse(args[3]);

            bool noGui = args.Contains("-nogui");

            Simulator sim = new Simulator(m,redProgram,blackProgram,seed);

            /*
            // make dump
            FileStream fs = new FileStream(@"..\..\data\dump", FileMode.Create);
            StreamWriter wr = new StreamWriter(fs);

            wr.WriteLine("random seed: {0}",seed);
            for (int i = 0; i <= 1000; i++)
            {
                sim.dump(wr);
                sim.step();
            }
            wr.Close();
            */

            if (noGui)
            {
                DateTime start = DateTime.Now;
                for (int i = 0; i < 100000; i++)
                    sim.step();
                sim.printScore();
                Console.WriteLine(DateTime.Now - start);
            }
            else
                Application.Run(new Form1(String.Join(" ", args), sim));
        }
        public Simulator(Map map, Automaton redProgram, Automaton blackProgram, int seed)
        {
            this.seed = (uint)seed;
            for (int i = 0; i < 4; i++)
                random(1);

            this.map = map;
            programs = new Automaton[] { redProgram, blackProgram };
            int id = 0;
            for (int j = 0; j < map.height; j++)
                for (int i = 0; i < map.width; i++)
                {
                    if (map.cells[i, j].type == CellType.RED_ANTHILL)
                    {
                        Ant ant = new Ant(id++, i, j, 0);
                        map.cells[i, j].ant = ant;
                        ants.Add(ant);
                    }
                    else if (map.cells[i, j].type == CellType.BLACK_ANTHILL)
                    {
                        Ant ant = new Ant(id++, i, j, 1);
                        map.cells[i, j].ant = ant;
                        ants.Add(ant);
                    }
                }
        }