public List<TimeSliceGame> Normalize(List<TimeSliceGame> games) { Dictionary<string, float> maxUnitCounts = new Dictionary<string, float>(); foreach (TimeSliceGame game in games) { foreach (GameStateVector vector in game.GameStateVectors) { foreach (KeyValuePair<string, float> unit in vector.UnitCounter) { if (maxUnitCounts.ContainsKey(unit.Key) == false) { maxUnitCounts.Add(unit.Key, unit.Value); } else if (maxUnitCounts[unit.Key] < unit.Value) { maxUnitCounts.Remove(unit.Key); maxUnitCounts.Add(unit.Key, unit.Value); } } } } List<TimeSliceGame> newGames = new List<TimeSliceGame>(); foreach (TimeSliceGame game in games) { TimeSliceGame newGame = new TimeSliceGame(); newGame.Race = game.Race; foreach (GameStateVector vector in game.GameStateVectors) { Dictionary<string, float> newUnitCounter = new Dictionary<string, float>(); foreach (KeyValuePair<string, float> unit in vector.UnitCounter) { float newValue = unit.Value / maxUnitCounts[unit.Key]; newUnitCounter.Add(unit.Key, newValue); } GameStateVector gsv = new GameStateVector(); gsv.UnitCounter = newUnitCounter; newGame.GameStateVectors.Add(gsv); } newGames.Add(newGame); } return newGames; }
public TimeSliceGame ProcessGame(ScGame game, int timeGranularity, int timeSlices) { List<GameStateVector> gameStateVectors = new List<GameStateVector>(); for (int i = 0; i < timeSlices; i++) { List<ScEvent> events = game.Events.Where(e => e.Time < timeGranularity * (i + 1)).ToList(); Dictionary<string, float> unitCounter = new Dictionary<string, float>(); IniUnitCounter(unitCounter, game.Race); foreach (ScEvent scEvent in events) { if (unitCounter.ContainsKey(scEvent.Unit)) { unitCounter[scEvent.Unit]++; } else { unitCounter.Add(scEvent.Unit, 1); } } GameStateVector gsv = new GameStateVector() { UnitCounter = unitCounter }; gameStateVectors.Add(gsv); } return new TimeSliceGame() { GameStateVectors = gameStateVectors, Race = game.Race , Replay = game.ReplayFile}; }