예제 #1
0
파일: Logic.cs 프로젝트: 0rbit3r/BrABENECi
        static bool Is_in_sight(Agent first, Agent second, out double[] vis_input)//Zjistí, jestli jeden vidí druhého a případně mu přiřadí visuální vstup
        {
            int dist = Get_dist(first, second);

            vis_input = new double[Agent.EYES_NUM];
            bool output = false;

            if (dist > Agent.SIGHT_LENGTH)
            {
                return(false);
            }
            else
            {
                double angle     = Get_angle(first, second);
                double tolerance = Math.Atan((double)Visual_bridge.Health_to_size(second.max_health) / (double)dist);
                for (int i = 0; i < Agent.EYES_NUM; i++)
                {
                    vis_input[i] = 0.0;
                    double eye_angle = first.orient + first.eyes[i];
                    Normalize_angle(ref eye_angle);
                    if (Math.Abs(angle - eye_angle) < tolerance)
                    {
                        vis_input[i] = (double)(Agent.SIGHT_LENGTH - dist) / (double)Agent.SIGHT_LENGTH;
                        if (first.color == second.color)
                        {
                            vis_input[i] *= -1;
                        }
                        output = true;
                    }
                }
                return(output);
            }
        }
예제 #2
0
파일: Logic.cs 프로젝트: 0rbit3r/BrABENECi
        public static void Excite_agents()
        {
            double[] sensory_input;
            double[] local_sens_input;
            for (int first_num = 0; first_num < PARTY_SIZE * 3; first_num++)
            {
                Agent agent = Current_agents[first_num];
                if (agent.alive == true)
                {
                    if (Visual_bridge.SHOW_ID)
                    {
                        Visual_bridge.Write_text(Convert.ToString(agent.id), agent.pos_X, agent.pos_Y, Visual_bridge.black_pen);
                    }

                    sensory_input = new double[Agent.SENSOR_NUM];
                    for (int sec_num = 0; sec_num < PARTY_SIZE * 3; sec_num++)
                    {
                        Agent sec_agent = Current_agents[sec_num];
                        if ((first_num != sec_num) && (Is_in_sight(agent, sec_agent, out local_sens_input)))
                        {
                            for (int i = 0; i < Agent.EYES_NUM; i++)
                            {
                                if (Math.Abs(local_sens_input[i]) > Math.Abs(sensory_input[i]))
                                {
                                    sensory_input[i] = local_sens_input[i];
                                }
                            }
                        }
                    }
                    sensory_input[8] = 1 - agent.time_to_fire / agent.reload_time;

                    agent.input = sensory_input;
                    agent.Make_decision();
                    agent.Commit_move();

                    if (Collisions)
                    {
                        for (int i = 0; i < Current_agents.Length; i++)
                        {
                            Agent sec_agent = Current_agents[i];
                            if ((!agent.Equals(sec_agent)) && (sec_agent.alive == true) &&
                                (Get_dist(agent, sec_agent) < Visual_bridge.Health_to_size(agent.max_health) + Visual_bridge.Health_to_size(sec_agent.max_health)))
                            {
                                double angle = Get_angle(agent, sec_agent);
                                angle = angle - Math.PI;
                                Normalize_angle(ref angle);
                                int old_x = agent.pos_X;
                                int old_y = agent.pos_Y;
                                agent.pos_X = agent.pos_X + (int)(Math.Cos(angle) * (Visual_bridge.Health_to_size(agent.max_health) + Visual_bridge.Health_to_size(sec_agent.max_health) - Get_dist(agent, sec_agent)));
                                agent.pos_Y = agent.pos_Y + (int)(Math.Sin(angle) * (Visual_bridge.Health_to_size(agent.max_health) + Visual_bridge.Health_to_size(sec_agent.max_health) - Get_dist(agent, sec_agent)));
                                Visual_bridge.Move_agent(old_x, old_y, agent.pos_X, agent.pos_Y, agent.max_health, agent.color_string, agent.orient);
                            }
                        }
                    }

                    if (agent.attacking == true)
                    {
                        Fire(agent);
                    }
                    agent.attacking = false;
                    if (agent.time_to_fire > 0)
                    {
                        agent.time_to_fire--;
                    }
                    if (Visual_bridge.SHOW_ID)
                    {
                        Visual_bridge.Write_text(Convert.ToString(agent.id), agent.pos_X, agent.pos_Y, Visual_bridge.white_pen);
                    }
                }
                else
                if (!fast_forward)
                {
                    Visual_bridge.Kill_agent(agent.pos_X, agent.pos_Y, agent.max_health);
                }
            }
        }//zjistí, co má každý brabenec za lubem podle jeho visuálního vstupu