public void Commit_move()//Nastaví pozice, aby odpovídali agentovo rozhodnutí { int old_X = 0; int old_Y = 0; if (brain.output[0] != 0) { old_X = pos_X; old_Y = pos_Y; if (brain.output[0] > 0) { Move_forward(speed * brain.output[0]); } if (pos_X >= 850) { pos_X = 850; } if (pos_X <= 0) { pos_X = 0; } if (pos_Y >= 850) { pos_Y = 850; } if (pos_Y <= 0) { pos_Y = 0; } if (!Logic.fast_forward) { Visual_bridge.Move_agent(old_X, old_Y, pos_X, pos_Y, max_health, color_string, orient); } } Turn(brain.output[1] * 1);//Tady najít vhodnou konstantu! if ((brain.output[2] > 0.5) && (time_to_fire == 0)) { attacking = true; } if ((old_X == pos_X) && (old_Y == pos_Y)) { fitness--; } }
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