public override bool Apllicable(Ants.GameState state)
        {
            foreach (float f in Globals.hillInfluence.influence)
            {
                if (f > 0)
                    return true;
            }

            return false;
        }
Exemple #2
0
        public Form1()
        {
            InitializeComponent();
            W = new World();
            C = new Clock(100);
            C.Worker.ProgressChanged    += ClockProgressChanged;
            C.Worker.RunWorkerCompleted += ClockCompleted;

            g          = pictureBox1.CreateGraphics();
            MessageHub = new TinyMessengerHub();
            this.Rand  = new Random();

            W.Trails.Add(new ChemTrail(200, 10, 800));

            this.Ants = new List <Ant>();
            Ants.Add(new Ant(200, 200, 4, 1, W, ref label2, 19));
            Ants.Add(new Ant(200, 200, 4, 2, W, ref label3, 18));
            Ants.Add(new Ant(200, 200, 4, 3, W, ref label4, 17));
            Ants.Add(new Ant(200, 200, 2, 4, W, ref label5));
            Ants.Add(new Ant(200, 200, 2, 5, W, ref label6));
            Ants.Add(new Ant(200, 200, 2, 6, W, ref label7));
            Ants.Add(new Ant(200, 200, 2, 7, W, ref label8));
            Ants.Add(new Ant(200, 200, 2, 8, W, ref label9));
            Ants.Add(new Ant(200, 200, 2, 9, W, ref label10));
            Ants.Add(new Ant(200, 200, 2, 10, W, ref label11));
            Ants.Add(new Ant(200, 200, 2, 11, W, ref label12));
            Ants.Add(new Ant(200, 200, 2, 12, W, ref label13));
            Ants.Add(new Ant(200, 200, 2, 13, W, ref label14));
            Ants.Add(new Ant(200, 200, 2, 14, W, ref label15));

            //MessageHub.Subscribe<MoveMsg>((m) =>
            //{
            //    //label1.Text = string.Format("Tick {0} - Playing", C.Count);
            //    pictureBox1.Refresh();
            //    //g.DrawLine(pen1, 190, 210, 210, 190);
            //    //g.DrawLine(pen1, 190, 190, 210, 210);

            //    //g.DrawLine(pen2, 190, 20, 210, 0);
            //    //g.DrawLine(pen2, 190, 0, 210, 20);
            //});

            foreach (Ant A in Ants)
            {
                MessageHub.Subscribe <MoveMsg>((m) =>
                {
                    A.Move();
                    g.FillRectangle(new System.Drawing.SolidBrush((A.Color)), A.X - 2, A.Y - 2, 5, 5);
                    ChemTrail t = W.AddTrail(new ChemTrail(A.X, A.Y, 50));
                });
            }
        }
        /// <summary>
        /// Make ants home in and raze a hill.
        /// </summary>
        /// <param name="state"></param>
        public override void DoAction(Ants.GameState state, int hashcode)
        {
            base.DoAction(state, hashcode);

            // Make all ants move towards the closest enemy hill.
            foreach (AntData ant in allAnts)
            {
                // Move towards the unoccupied/passable tile closest to the hill.
                Location next = ant.CurrentLocation.Neighbors[0];
                float max =  Globals.hillInfluence[next.Row, next.Col];
                foreach (Location l in ant.CurrentLocation.Neighbors)
                    if (Globals.hillInfluence[l.Row, l.Col] > max && Globals.state.GetIsUnoccupied(l) && Globals.state.GetIsPassable(l))
                    {
                        max = Globals.hillInfluence[l.Row, l.Col];
                        next = l;
                    }
                // Perform move.
                ant.AntRoute = new Route(ant.CurrentLocation, next, new Location[] { ant.CurrentLocation, next });
                ant.AdvancePath(this);
            }
        }