private bool GenerateDeck(int numOfMain, int numOfEx, string file) { if (CardPool.Count < numOfMain || CardPoolEx.Count < numOfEx) { return(false); } Dictionary <string, int> main = new Dictionary <string, int>(); Dictionary <string, int> ex = new Dictionary <string, int>(); for (int i = 0; i < numOfMain; i++) { int index = _rd.Next(CardPool.Count); if (main.ContainsKey(CardPool[index])) { main[CardPool[index]]++; } else { main.Add(CardPool[index], 1); } CardPool.RemoveAt(index); } for (int i = 0; i < numOfEx; i++) { if (CardPoolEx.Count == 0) { break; } int index = _rd.Next(CardPoolEx.Count); if (ex.ContainsKey(CardPoolEx[index])) { ex[CardPoolEx[index]]++; } else { ex.Add(CardPoolEx[index], 1); } CardPoolEx.RemoveAt(index); } FileStream fs = new FileStream(file, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("#created by DeckGen"); sw.WriteLine("#main"); foreach (var kvp in main) { for (int i = 0; i < kvp.Value; i++) { sw.WriteLine(kvp.Key); } } sw.WriteLine("#extra"); foreach (var kvp in ex) { for (int i = 0; i < kvp.Value; i++) { sw.WriteLine(kvp.Key); } } sw.WriteLine("!side"); sw.Close(); fs.Close(); main.Clear(); ex.Clear(); return(true); }
private void InitCardPool(string cdbFile, int mainNum, int exNum) { List <string> CardPoolLocal = new List <string>(); List <string> CardPoolExLocal = new List <string>(); SQLiteConnection sqlcon = new SQLiteConnection($"Data Source={cdbFile}"); sqlcon.Open(); SQLiteCommand cmd = new SQLiteCommand("SELECT id,type FROM datas", sqlcon); var reader = cmd.ExecuteReader(); while (reader.Read()) { string id = reader["id"].ToString(); long type = (long)reader["type"]; int num = 3; CardPoolLFList.Add(id, 0); if (LFList.ContainsKey(id)) { num = LFList[id]; } if (((type & TYPE_FUSION) > 0) || ((type & TYPE_XYZ) > 0) || ((type & TYPE_LINK) > 0) || ((type & TYPE_SYNCHRO) > 0)) { for (int i = 0; i < num; i++) { CardPoolExLocal.Add(id); } } else { for (int i = 0; i < num; i++) { CardPoolLocal.Add(id); } } } for (int i = 0; i < mainNum; i++) { int index = _rd.Next(0, CardPoolLocal.Count); CardPool.Add(CardPoolLocal[index]); CardPoolLocal.RemoveAt(index); if (!CardPoolLFList.ContainsKey(CardPoolLocal[index])) { CardPoolLFList.Add(CardPoolLocal[index], 1); } else { CardPoolLFList[CardPoolLocal[index]]++; } } for (int i = 0; i < exNum; i++) { int index = _rd.Next(0, CardPoolExLocal.Count); CardPoolEx.Add(CardPoolExLocal[index]); CardPoolLFList[CardPoolExLocal[index]]++; CardPoolExLocal.RemoveAt(index); } reader.Close(); cmd.Dispose(); sqlcon.Dispose(); CardPoolLocal.Clear(); CardPoolExLocal.Clear(); }