-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFeatureExtractor.py
61 lines (54 loc) · 2.21 KB
/
FeatureExtractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ships: [0 , 0 , 0 , 0, 0]
# missile: [0 . . . 0]
# numTargeting [ 1 2 3 4 5]
# missileTarget [ 2 4 0 0 0 0 0 0 0 0 ]
# actions [ [0 , 0], [0, 0] ... ]
# shipHealth [ 2 3 1 4 5 ]
# nearTarget [ 0 0 0 0 0 0 0 0 0 0 0 ] 0 or 1 depending if missile is 40 s from target
import numpy as np
import os
import UtilityFunctions
from PlannerProto_pb2 import StatePb, ShipActionPb, AssetPb, TrackPb
from UtilityFunctions import get_threat_target, parse_msg_to_ships_weapons_tracks, get_time_to_impact
from collections import Counter
class Extractor():
def __init__(self, state: StatePb):
self.state = state
self.ships, self.weapons, self.enemy = UtilityFunctions.parse_msg_to_ships_weapons_tracks(state)
def getFeatures(self, state, action):
pass
class ArrayExtractor(Extractor):
#more detailed features describing the game state
def __init__(self, state: StatePb):
super().__init__(state)
def getThreatArray(self, action):
# returns an array of enemy missiles, sorted by closest
# does not include missile that was targeted in "action"
actionID = 100
if action != None:
actionID = action.split(",")[1]
threatArray = [0]*30
count = 0
if (len(self.ships) != 0):
for threat in self.enemy:
if threat.ThreatRelationship == "Hostile" and threat.TrackId != actionID:
target = get_threat_target(threat, self.ships)
if target.isHVU:
value = 2
else:
value = 1
hitTime = float(get_time_to_impact(threat, target))
if hitTime > 0.0:
ratio = value / (hitTime + 0.001)
threatArray[count] = ratio
count += 1
threatArray.sort(reverse=True)
count = 1
enemyArray = Counter()
for item in threatArray:
enemyArray["ClosestEnemy_"+ str(count)] = item
count += 1
return enemyArray
def getFeatures(self, state, action):
enemyArray = self.getThreatArray(action)
return enemyArray