Example #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();
        }
        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 override void execute(Ant ant, Simulator simulator)
 {
     ant.direction += dDir;
     ant.direction = (ant.direction + 6) % 6;
     ant.state = nextState;
     simulator.map.cells[ant.x, ant.y].updated = true;
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     Cell cell = simulator.map.cells[ant.x, ant.y];
     if (ant.hasFood || cell.food == 0)
         ant.state = failState;
     else
     {
         cell.food--;
         cell.updated = true;
         ant.hasFood = true;
         ant.state = nextState;
     }
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     int x = ant.x;
     int y = ant.y;
     if (dir == Dir.Ahead)
     {
         x += Map.directions[ant.direction, 0];
         y += Map.directions[ant.direction, 1];
     }
     else if (dir == Dir.LeftAhead)
     {
         x += Map.directions[(ant.direction + 5) % 6, 0];
         y += Map.directions[(ant.direction + 5) % 6, 1];
     }
     else if (dir == Dir.RightAhead)
     {
         x += Map.directions[(ant.direction + 1) % 6, 0];
         y += Map.directions[(ant.direction + 1) % 6, 1];
     }
     Cell cell = simulator.map.cells[x, y];
     if (cellMatches(cell, ant.color))
         ant.state = trueState;
     else
         ant.state = falseState;
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     int newX = ant.x + Map.directions[ant.direction, 0];
     int newY = ant.y + Map.directions[ant.direction, 1];
     Cell oldCell = simulator.map.cells[ant.x, ant.y];
     Debug.Assert(oldCell.ant == ant);
     Cell newCell = simulator.map.cells[newX, newY];
     if (newCell.type == CellType.ROCK || newCell.ant != null)
         ant.state = failState;
     else
     {
         oldCell.updated = true;
         newCell.updated = true;
         oldCell.ant = null;
         newCell.ant = ant;
         ant.x = newX;
         ant.y = newY;
         ant.resting = 14;
         ant.state = nextState;
         simulator.checkForSurroundedAnts(ant.x, ant.y);
     }
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     Cell cell = simulator.map.cells[ant.x, ant.y];
     if (unMark)
         cell.markers[ant.color] &= ~(1 << bit);
     else
         cell.markers[ant.color] |= 1 << bit;
     cell.updated = true;
     ant.state = nextState;
 }
 public virtual void execute(Ant ant, Simulator simulator)
 {
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     if (simulator.random(p) == 0)
         ant.state = nextState1;
     else
         ant.state = nextState2;
 }
 public override void execute(Ant ant, Simulator simulator)
 {
     if (ant.hasFood)
     {
         ant.hasFood = false;
         Cell cell = simulator.map.cells[ant.x, ant.y];
         cell.food++;
         cell.updated = true;
     }
     ant.state = nextState;
 }