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; }
private void WriteGameToCsv(TimeSliceGame game, int gameId, StreamWriter sw, bool onlyWriteLastVector) { for (int i = 0; i < game.GameStateVectors.Count; i++) { if (onlyWriteLastVector) if (i != game.GameStateVectors.Count - 1) continue; sw.Write(gameId + SEPERATION_SYMBOL + i + SEPERATION_SYMBOL + game.Replay + SEPERATION_SYMBOL); int counter = 0; foreach (KeyValuePair<string, float> unit in game.GameStateVectors[i].UnitCounter) { sw.Write(unit.Value.ToString("F8", CultureInfo.CreateSpecificCulture(CULTURE))); if (counter != game.GameStateVectors[i].UnitCounter.Count - 1) sw.Write(SEPERATION_SYMBOL); counter++; } sw.WriteLine(""); } }