Refactor "Missile" -> "Interceptor"
This commit is contained in:
@@ -2,35 +2,35 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// The assignment class is an interface for assigning a threat to each missile.
|
||||
// The assignment class is an interface for assigning a threat to each interceptor.
|
||||
public interface IAssignment {
|
||||
// Assignment item type.
|
||||
// The first element corresponds to the missile index, and the second element
|
||||
// The first element corresponds to the interceptor index, and the second element
|
||||
// corresponds to the threat index.
|
||||
public struct AssignmentItem {
|
||||
public int MissileIndex;
|
||||
public int InterceptorIndex;
|
||||
public int ThreatIndex;
|
||||
|
||||
public AssignmentItem(int missileIndex, int threatIndex) {
|
||||
MissileIndex = missileIndex;
|
||||
InterceptorIndex = missileIndex;
|
||||
ThreatIndex = threatIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// A list containing the missile-target assignments.
|
||||
// A list containing the interceptor-target assignments.
|
||||
|
||||
// Assign a target to each missile that has not been assigned a target yet.
|
||||
// Assign a target to each interceptor that has not been assigned a target yet.
|
||||
public abstract IEnumerable<AssignmentItem> Assign(List<Agent> missiles, List<Agent> targets);
|
||||
|
||||
// Get the list of assignable missile indices.
|
||||
protected static List<int> GetAssignableMissileIndices(List<Agent> missiles) {
|
||||
List<int> assignableMissileIndices = new List<int>();
|
||||
// Get the list of assignable interceptor indices.
|
||||
protected static List<int> GetAssignableInterceptorIndices(List<Agent> missiles) {
|
||||
List<int> assignableInterceptorIndices = new List<int>();
|
||||
for (int missileIndex = 0; missileIndex < missiles.Count; missileIndex++) {
|
||||
if (missiles[missileIndex].IsAssignable()) {
|
||||
assignableMissileIndices.Add(missileIndex);
|
||||
assignableInterceptorIndices.Add(missileIndex);
|
||||
}
|
||||
}
|
||||
return assignableMissileIndices;
|
||||
return assignableInterceptorIndices;
|
||||
}
|
||||
|
||||
// Get the list of active target indices.
|
||||
|
||||
@@ -9,11 +9,11 @@ public class RoundRobinAssignment : IAssignment {
|
||||
// Previous target index that was assigned.
|
||||
private int prevTargetIndex = -1;
|
||||
|
||||
// Assign a target to each missile that has not been assigned a target yet.
|
||||
// Assign a target to each interceptor that has not been assigned a target yet.
|
||||
public IEnumerable<IAssignment.AssignmentItem> Assign(List<Agent> missiles, List<Agent> targets) {
|
||||
List<IAssignment.AssignmentItem> assignments = new List<IAssignment.AssignmentItem>();
|
||||
List<int> assignableMissileIndices = IAssignment.GetAssignableMissileIndices(missiles);
|
||||
if (assignableMissileIndices.Count == 0) {
|
||||
List<int> assignableInterceptorIndices = IAssignment.GetAssignableInterceptorIndices(missiles);
|
||||
if (assignableInterceptorIndices.Count == 0) {
|
||||
return assignments;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RoundRobinAssignment : IAssignment {
|
||||
return assignments;
|
||||
}
|
||||
|
||||
foreach (int missileIndex in assignableMissileIndices) {
|
||||
foreach (int missileIndex in assignableInterceptorIndices) {
|
||||
int nextActiveTargetIndex = activeThreatIndices.FindIndex(index => index > prevTargetIndex);
|
||||
|
||||
if (nextActiveTargetIndex == -1) {
|
||||
|
||||
@@ -7,12 +7,12 @@ using UnityEngine;
|
||||
// The threat assignment class assigns missiles to the targets based
|
||||
// on the threat level of the targets.
|
||||
public class ThreatAssignment : IAssignment {
|
||||
// Assign a target to each missile that has not been assigned a target yet.
|
||||
// Assign a target to each interceptor that has not been assigned a target yet.
|
||||
public IEnumerable<IAssignment.AssignmentItem> Assign(List<Agent> missiles, List<Agent> targets) {
|
||||
List<IAssignment.AssignmentItem> assignments = new List<IAssignment.AssignmentItem>();
|
||||
|
||||
List<int> assignableMissileIndices = IAssignment.GetAssignableMissileIndices(missiles);
|
||||
if (assignableMissileIndices.Count == 0) {
|
||||
List<int> assignableInterceptorIndices = IAssignment.GetAssignableInterceptorIndices(missiles);
|
||||
if (assignableInterceptorIndices.Count == 0) {
|
||||
return assignments;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ public class ThreatAssignment : IAssignment {
|
||||
List<ThreatInfo> threatInfos =
|
||||
CalculateThreatLevels(targets, activeThreatIndices, positionToDefend);
|
||||
|
||||
foreach (int missileIndex in assignableMissileIndices) {
|
||||
foreach (int missileIndex in assignableInterceptorIndices) {
|
||||
if (missiles[missileIndex].HasAssignedTarget())
|
||||
continue;
|
||||
if (threatInfos.Count == 0)
|
||||
break;
|
||||
|
||||
// Find the optimal target for this missile based on distance and threat
|
||||
// Find the optimal target for this interceptor based on distance and threat
|
||||
ThreatInfo optimalTarget = null;
|
||||
float optimalScore = float.MinValue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user