Exemplo n.º 1
0
        }//zjistí, co má každý brabenec za lubem podle jeho visuálního vstupu

        public static void Fire(Agent agent)
        {
            agent.time_to_fire = agent.reload_time;
            int x2 = agent.pos_X + (int)(Math.Cos(agent.orient) * Agent.FIRING_RANGE * 0.7);
            int y2 = agent.pos_Y + (int)(Math.Sin(agent.orient) * Agent.FIRING_RANGE * 0.7);

            Visual_bridge.Draw_bullet(agent.pos_X, agent.pos_Y, x2, y2, Visual_bridge.white_pen);

            int friendly_fire; //Multiplier for either adding or substracting score

            bool wasted_shot = true;

            for (int i = 0; i < PARTY_SIZE * 3; i++)
            {
                Agent second_agent = Current_agents[i];
                if ((second_agent.alive == true) &&
                    !second_agent.Equals(agent) && (Get_dist(agent, second_agent) < Agent.FIRING_RANGE))
                {
                    if ((agent.orient < Math.Abs(Get_angle(agent, second_agent)) + Math.PI / 6) &&
                        (agent.orient > Math.Abs(Get_angle(agent, second_agent)) - Math.PI / 6))
                    {
                        wasted_shot          = false;
                        second_agent.health -= agent.damage;
                        friendly_fire        = 1;
                        if (agent.color == second_agent.color)
                        {
                            wasted_shot   = true;
                            friendly_fire = -1;
                        }

                        agent.fitness += DMG_PTS_MULTIPLIER * agent.damage * friendly_fire;;
                        if (second_agent.health <= 0)
                        {
                            second_agent.alive = false;
                            Visual_bridge.Kill_agent(second_agent.pos_X, second_agent.pos_Y, second_agent.max_health);
                            Visual_bridge.Draw_dead_bullet(second_agent.pos_X, second_agent.pos_Y, second_agent.orient);
                            agent.fitness += KILL_PTS * friendly_fire * agent.enemies_killed;
                            if (friendly_fire == 1)
                            {
                                agent.enemies_killed++;
                                agent.health += (agent.max_health / 3) % agent.max_health; //Nechat nebo nenechat?
                            }
                        }
                    }
                }
            }
            if (wasted_shot)
            {
                agent.health -= MISS_PENALTY;
            }
            if (agent.health < 0)
            {
                agent.alive = false;
                Visual_bridge.Kill_agent(agent.pos_X, agent.pos_Y, agent.max_health);
                Visual_bridge.Draw_dead_bullet(agent.pos_X, agent.pos_Y, agent.orient);
            }
        }//Obstarává střelbu daného agenta
Exemplo n.º 2
0
        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