Skip to content

Commit

Permalink
Reduce code duplication.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 208818826
  • Loading branch information
tewalds committed Aug 24, 2018
1 parent b436226 commit 999c66d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pysc2/lib/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,21 +899,17 @@ def or_zeros(layer, size):
score_details.spent_vespene,
], names=ScoreCumulative, dtype=np.int32)

def get_score_by_category_entry(key, details):
def get_score_details(key, details, categories):
row = getattr(details, key.name)
return [getattr(row, category.name) for category in ScoreCategories]
return [getattr(row, category.name) for category in categories]

out["score_by_category"] = named_array.NamedNumpyArray([
get_score_by_category_entry(key, score_details)
get_score_details(key, score_details, ScoreCategories)
for key in ScoreByCategory
], names=[ScoreByCategory, ScoreCategories], dtype=np.int32)

def get_score_by_vital_entry(key, details):
row = getattr(details, key.name)
return [getattr(row, category.name) for category in ScoreVitals]

out["score_by_vital"] = named_array.NamedNumpyArray([
get_score_by_vital_entry(key, score_details)
get_score_details(key, score_details, ScoreVitals)
for key in ScoreByVital
], names=[ScoreByVital, ScoreVitals], dtype=np.int32)

Expand Down

0 comments on commit 999c66d

Please sign in to comment.