public void SaveConfig(Stream outputStream, string rootName, ConfigSaveType configSaveType) { if (null == outputStream) { throw new ArgumentNullException(nameof(outputStream)); } if (string.IsNullOrWhiteSpace(rootName)) { throw new ArgumentNullException(nameof(rootName)); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(outputStream, settings)) { writer.WriteStartElement(rootName); writer.WriteAttributeString("version", GetVersion()); writer.WriteAttributeString("date", DateTime.UtcNow.ToString()); SaveGameAIConfig(writer, "GameAI", configSaveType); writer.WriteEndElement(); } }
public void SaveGameAIConfig(XmlWriter writer, string rootName, ConfigSaveType configSaveType) { if (null == writer) { throw new ArgumentNullException(nameof(writer)); } if (string.IsNullOrWhiteSpace(rootName)) { throw new ArgumentNullException(nameof(rootName)); } writer.WriteStartElement(rootName); if (configSaveType.HasFlag(ConfigSaveType.BasicOptions)) { if (TranspositionTableSizeMB.HasValue) { writer.WriteElementString("TranspositionTableSizeMB", TranspositionTableSizeMB.Value.ToString()); } if (!_maxHelperThreads.HasValue) { writer.WriteElementString("MaxHelperThreads", "Auto"); } else if (_maxHelperThreads.Value == 0) { writer.WriteElementString("MaxHelperThreads", "None"); } else { writer.WriteElementString("MaxHelperThreads", _maxHelperThreads.Value.ToString()); } writer.WriteElementString("PonderDuringIdle", PonderDuringIdle.ToString()); if (MaxBranchingFactor.HasValue) { writer.WriteElementString("MaxBranchingFactor", MaxBranchingFactor.Value.ToString()); } writer.WriteElementString("ReportIntermediateBestMoves", ReportIntermediateBestMoves.ToString()); } if (configSaveType.HasFlag(ConfigSaveType.MetricWeights)) { foreach (KeyValuePair <ExpansionPieces, MetricWeights[]> kvp in MetricWeightSet) { ExpansionPieces gameType = kvp.Key; MetricWeights[] mw = kvp.Value; if (null != mw[0] && null != mw[1]) { mw[0].WriteMetricWeightsXml(writer, "StartMetricWeights", gameType); mw[1].WriteMetricWeightsXml(writer, "EndMetricWeights", gameType); } else if (null != mw[0] && null == mw[1]) { mw[0].WriteMetricWeightsXml(writer, gameType: gameType); } } } if (configSaveType.HasFlag(ConfigSaveType.InitialTranspositionTable)) { foreach (KeyValuePair <ExpansionPieces, TranspositionTable> kvp in InitialTranspositionTables) { ExpansionPieces gameType = kvp.Key; TranspositionTable tt = kvp.Value; tt?.WriteTranspositionTableXml(writer, "InitialTranspositionTable", gameType); } } writer.WriteEndElement(); }