Esempio n. 1
0
        public override void Move()
        {
            base.Move();
            Predator predator = CheckArea();

            if (predator != null)
            {
                //Console.WriteLine(this.Label + " viu o predador " + predator.Label);
                SendSignal(predator);
            }
        }
Esempio n. 2
0
        public static void Initialize()
        {
            Random random = new Random();

            for (int i = 0; i < Monkeys.Length; i++)
            {
                Monkeys[i] = new Monkey(random);
            }

            for (int i = 0; i < Predators.Length; i++)
            {
                Predators[i] = new Predator(random);
            }
        }
Esempio n. 3
0
        public void SendSignal(Predator predator)
        {
            double highest       = 0.0;
            int    indexSymbol   = 0;
            int    indexPredator = 0;



            int iRecalc;
            int jRecalc;

            //Console.WriteLine(this.Name + " enviou um sinal de alerta");
            // Verifica os agentes dentro do raio do sinal enviado para atualizar suas tabelas se forem macacos
            for (int i = Position.X - Program.SignalRadius; i <= Position.X + Program.SignalRadius; i++)
            {
                // O mapa é esférico: o fim da borda direita recomeça na borda esquerda, por exemplo
                if (i >= Program.Map.GetLength(0))
                {
                    iRecalc = i - Program.Map.GetLength(0);
                }
                else if (i < 0)
                {
                    iRecalc = i + Program.Map.GetLength(0);
                }
                else
                {
                    iRecalc = i;
                }

                for (int j = Position.Y - Program.SignalRadius; j <= Position.Y + Program.SignalRadius; j++)
                {
                    if (j >= Program.Map.GetLength(1))
                    {
                        jRecalc = j - Program.Map.GetLength(1);
                    }
                    else if (j < 0)
                    {
                        jRecalc = j + Program.Map.GetLength(1);
                    }
                    else
                    {
                        jRecalc = j;
                    }

                    // Se existe algum agente na posição atual e este agente é um macaco
                    if (Program.Map[iRecalc, jRecalc] != null && Program.Map[iRecalc, jRecalc].GetType() == typeof(Monkey) && Program.Map[iRecalc, jRecalc] != this)
                    {
                        Monkey monkey = (Monkey)Program.Map[iRecalc, jRecalc];

                        Predator predatorSeen = monkey.CheckArea();

                        for (int k = 0; k < Program.Predators.Count(); k++)
                        {
                            if (Program.Predators[k] == predatorSeen)
                            {
                                indexPredator = k;
                            }
                        }

                        // Obtém o sinal de maior valor para o predador encontrado
                        for (int k = 0; k < Table.GetLength(0); k++)
                        {
                            if (Table[k, indexPredator] > highest)
                            {
                                highest     = Table[k, indexPredator];
                                indexSymbol = k;
                            }
                        }

                        if (predatorSeen != null)
                        {
                            double newValue = monkey.Table[indexSymbol, indexPredator] + 0.01;

                            if (newValue <= 1)
                            {
                                monkey.Table[indexSymbol, indexPredator] = newValue;
                            }
                            else
                            {
                                monkey.Table[indexSymbol, indexPredator] = 1;
                            }
                        }
                        //Console.WriteLine(monkey.Name + " recebeu o sinal enviado por " + this.Name);
                    }
                }
            }
        }