| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Diagnostics.Contracts; |
| | 7 | |
|
| | 8 | | // The assignment class is an interface for assigning a threat to each interceptor. |
| | 9 | | public interface IAssignment { |
| | 10 | | // Assignment item type. |
| | 11 | | // The first element corresponds to the interceptor index, and the second element |
| | 12 | | // corresponds to the threat index. |
| | 13 | | public struct AssignmentItem { |
| | 14 | | public Interceptor Interceptor; |
| | 15 | | public Threat Threat; |
| | 16 | |
|
| 0 | 17 | | public AssignmentItem(Interceptor interceptor, Threat threat) { |
| 0 | 18 | | Interceptor = interceptor; |
| 0 | 19 | | Threat = threat; |
| 0 | 20 | | } |
| | 21 | | } |
| | 22 | |
|
| | 23 | | // Assign a target to each interceptor that has not been assigned a target yet. |
| | 24 | | [Pure] |
| | 25 | | public abstract IEnumerable<AssignmentItem> Assign(in IReadOnlyList<Interceptor> interceptors, |
| | 26 | | in IReadOnlyList<ThreatData> threatTable); |
| | 27 | |
|
| | 28 | | // Get the list of assignable interceptor indices. |
| | 29 | | [Pure] |
| | 30 | | protected static List<Interceptor> GetAssignableInterceptors( |
| 1 | 31 | | in IReadOnlyList<Interceptor> interceptors) { |
| 2 | 32 | | return interceptors.Where(interceptor => interceptor.IsAssignable()).ToList(); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | // Get the list of active threats. |
| | 36 | | [Pure] |
| 0 | 37 | | protected static List<ThreatData> GetActiveThreats(in IReadOnlyList<ThreatData> threats) { |
| 0 | 38 | | return threats.Where(t => t.Status != ThreatStatus.DESTROYED).ToList(); |
| 0 | 39 | | } |
| | 40 | | } |