/// <summary> /// Parses the given file. /// </summary> /// <param name="pathToFile">The path of the file to parse.</param> /// <returns></returns> public static BigramMap ParseFile(string pathToFile) { BigramMap map = new BigramMap(); string jsonString = ""; using (FileStream reader = File.OpenRead(pathToFile)) using (var zip = new GZipStream(reader, CompressionMode.Decompress, true)) using (var unzip = new StreamReader(zip)) while (!unzip.EndOfStream) { jsonString += unzip.ReadLine(); } var json = JObject.Parse(jsonString); foreach (KeyValuePair <string, JToken> app in json) { // ignore cardIds, only parse data of bigramMap if (app.Key.Equals("bigramMap")) { var bigramArray = JArray.Parse(app.Value.ToString()); foreach (var jToken in bigramArray) { var bigramArrayEntry = (JObject)jToken; AddObjectToBigramMap(map, bigramArrayEntry); } } } map.Sort(); return(map); }
/// <summary> /// Adds the given JSON array object to the bigram map. /// </summary> /// <param name="map">The bigram map.</param> /// <param name="bigramArrayEntry">The new bigram array entry.</param> private static void AddObjectToBigramMap(BigramMap map, JObject bigramArrayEntry) { foreach (KeyValuePair <string, JToken> entry in bigramArrayEntry) { string keyCard = entry.Key; var occurrencesArray = JArray.Parse(entry.Value.ToString()); AddOccurrencesOfKeyCardToMap(map, keyCard, occurrencesArray); } }
public PredatorMCTSAgent(IScore scoring, MCTSParameters mctsParameters, PredictionParameters predictionParameters) : base(scoring, mctsParameters) { /*deck = ControlWarlock; * hero = CardClass.WARLOCK; */ _predictionParameters = predictionParameters; _map = BigramMapReader.ParseFile(_predictionParameters.File); }
public MCTSSimulatorExt(int playerId, IScore scoring, MCTSParameters mctsParameters, PredictionParameters predictionParameters, BigramMap map) : base(playerId, scoring, mctsParameters) { _predictionParameters = predictionParameters; _map = map; _oppHistory = null; _oppBoardCards = new BoardCards(); // the delta time for each simulation is: // a) depth * 2, because we simulation for every depth the opponent and the player at once // b) + 1, because we always simulation the player first _deltaTime = (_mctsParameters.SimulationTime - ((_predictionParameters.SimulationDepth * 2) + 1) * _mctsParameters.AggregationTime) / ((_predictionParameters.SimulationDepth * 2) + 1); }
/// <summary> /// Add a occurances array of entries of a card to the bigram map. /// </summary> /// <param name="map">The bigram map.</param> /// <param name="keyCard">The key card.</param> /// <param name="occurrencesArray">The list of entris with the occurrences.</param> private static void AddOccurrencesOfKeyCardToMap(BigramMap map, string keyCard, JArray occurrencesArray) { string valCard = ""; int numOcc = 0; foreach (var jToken in occurrencesArray) { var occObject = (JObject)jToken; foreach (KeyValuePair <string, JToken> occEntry in occObject) { if (occEntry.Key.Equals("numOcc")) { numOcc = (int)occEntry.Value; } else if (occEntry.Key.Equals("cardId")) { valCard = (string)occEntry.Value; } } map.Add(keyCard, valCard, numOcc); } }
public PredatorMctsAgent(IScore scoring, MctsParameters mctsParameters, PredictionParameters predictionParameters) : base(scoring, mctsParameters) { _predictionParameters = predictionParameters; _map = BigramMapReader.ParseFile(_predictionParameters.File); }