/// <summary> /// This method will scrape the value from text files /// The values of Friendly Decks will be stored /// </summary> public List <List <List <int> > > scrapeFriendFromText(int genFolderCount, int iterable) { List <List <List <int> > > friendDecksFinal = new List <List <List <int> > >(); Dictionary <string, cardDefs> cards = allCards.getAllCards(); Console.WriteLine("*************** Get the friend decks from Gen Folders ******************\n\n"); for (int i = 0; i < genFolderCount; i++) { Console.WriteLine("Scraping friend decks info for gen Folder no: " + i); List <List <int> > friendDecks = new List <List <int> >(); for (int j = 0; j < iterable; j++) { List <int> friendDeckTemp = new List <int>(); string fileName = ""; if (i == 0) { fileName = "C:/Development/HeartstoneDataCapture/HeartstoneDataCapture/Data/FriendDeckDuplicate150/gen-" + i + "/Overall/Deck" + j + "/" + 0 + "-" + j + ".txt"; } else { fileName = "C:/Development/HeartstoneDataCapture/HeartstoneDataCapture/Data/FriendDeckDuplicate150/gen" + (i + 1) + "-0/Overall/Deck" + j + "/" + 0 + "-" + j + ".txt"; } string lines = File.ReadAllText(fileName); string[] items = lines.Split('*'); int count = 0; List <friendDeckModel> fModelWhole = new List <friendDeckModel>(); foreach (string item in items) { friendDeckModel fModel = new friendDeckModel(); if (count < 30) { fModel.cardName = cards.GetValueOrDefault(item).dbfId; fModel.cost = cards.GetValueOrDefault(item).cost; fModelWhole.Add(fModel); } else { break; } count++; } fModelWhole = fModelWhole.OrderBy(x => x.cost).ToList(); foreach (friendDeckModel fMod in fModelWhole) { friendDeckTemp.Add(fMod.cardName); } friendDecks.Add(friendDeckTemp); } friendDecksFinal.Add(friendDecks); } return(friendDecksFinal); }
/// <summary> /// This method will conver the JSON data to one hot representation /// </summary> /// <param name="json"></param> /// <returns></returns> public string convertJSONToOneHot1(String json, Dictionary <string, string> CardPool) { Dictionary <int, cardDefs> cardsInfo = cPro.getAllCardsWithId(); Dictionary <string, cardDefs> cardsInfoStr = cPro.getAllCards(); List <csvStructure> data = JsonConvert.DeserializeObject <List <csvStructure> >(json); /***/ List <int> CardPoolIdMain = new List <int>(); foreach (string keys in CardPool.Keys) { CardPoolIdMain.Add(cardsInfoStr.GetValueOrDefault(keys.Split('\r')[0]).dbfId); } /***/ List <csvStructure> finalOneHotStr = new List <csvStructure>(); foreach (csvStructure struc in data) { List <int> FriendDeck = new List <int>(); List <int> EnemyDeck = new List <int>(); Dictionary <int, int> cardCountFriend = new Dictionary <int, int>(); Dictionary <int, int> cardCountEnemy = new Dictionary <int, int>(); List <int> CardPoolId = new List <int>(); csvStructure cStructTemp = new csvStructure(); foreach (string keys in CardPool.Keys) { CardPoolId.Add(cardsInfoStr.GetValueOrDefault(keys.Split('\r')[0]).dbfId); } foreach (int id in struc.FriendDeck) { string cardName = cardsInfo.GetValueOrDefault(id).name; if (CardPool.ContainsKey(cardName)) { if (cardCountFriend.ContainsKey(id)) { cardCountFriend[id] = cardCountFriend[id] + 1; } else { cardCountFriend.Add(id, 1); } } } foreach (int id in struc.EnemyDeck) { string cardName = cardsInfo.GetValueOrDefault(id).name; if (CardPool.ContainsKey(cardName)) { if (cardCountEnemy.ContainsKey(id)) { cardCountEnemy[id] = cardCountEnemy[id] + 1; } else { cardCountEnemy.Add(id, 1); } } } foreach (int id in CardPoolId) { if (cardCountFriend.ContainsKey(id)) { FriendDeck.Add(cardCountFriend[id]); } else { FriendDeck.Add(0); } if (cardCountEnemy.ContainsKey(id)) { EnemyDeck.Add(cardCountEnemy[id]); } else { EnemyDeck.Add(0); } } cStructTemp.FriendDeck = FriendDeck; cStructTemp.EnemyDeck = EnemyDeck; cStructTemp.WinnerDeck = struc.WinnerDeck; finalOneHotStr.Add(cStructTemp); } string result = JsonConvert.SerializeObject(finalOneHotStr); return(result); }