public EngineCapabilities(string capabilitiesString) { if (!string.IsNullOrWhiteSpace(capabilitiesString)) { foreach (string capabilityString in capabilitiesString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { try { switch (capabilityString.ToLower()) { case "mosquito": ExpansionPieces |= ExpansionPieces.Mosquito; break; case "ladybug": ExpansionPieces |= ExpansionPieces.Ladybug; break; case "pillbug": ExpansionPieces |= ExpansionPieces.Pillbug; break; } } catch (Exception) { } } } }
public static ExpansionPieces ParseExpansionPieces(string s) { ExpansionPieces expansionPieces = ExpansionPieces.None; if (!string.IsNullOrWhiteSpace(s)) { string[] split = s.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries); if (split[0] != NoExpansionsString) { throw new ArgumentException(); } if (split.Length == 2) { if (split[1].Contains("M")) { expansionPieces |= ExpansionPieces.Mosquito; } if (split[1].Contains("L")) { expansionPieces |= ExpansionPieces.Ladybug; } if (split[1].Contains("P")) { expansionPieces |= ExpansionPieces.Pillbug; } } } return(expansionPieces); }
public void UpdateRecord(int rating, GameResult result, ExpansionPieces expansionPieces) { if (rating < EloUtils.MinRating) { throw new ArgumentOutOfRangeException("rating"); } Records[(int)expansionPieces].EloRating = rating; switch (result) { case GameResult.Loss: Records[(int)expansionPieces].Losses++; break; case GameResult.Draw: Records[(int)expansionPieces].Draws++; break; case GameResult.Win: Records[(int)expansionPieces].Wins++; break; } Update(); }
private void NewGame(ExpansionPieces expansionPieces) { _gameBoard = new GameBoard(expansionPieces); _gameAI.ResetCaches(); ConsoleOut(_gameBoard.ToString()); }
private void InitPieces(ExpansionPieces expansionPieces) { ExpansionPieces = expansionPieces; for (int i = 0; i < EnumUtils.NumPieceNames; i++) { _pieces[i] = EnumUtils.IsEnabled((PieceName)i, ExpansionPieces) ? new Piece((PieceName)i) : null; } }
private void SetEndMetricWeights(ExpansionPieces expansionPieces, MetricWeights metricWeights) { if (!MetricWeightSet.ContainsKey(expansionPieces)) { MetricWeightSet.Add(expansionPieces, new MetricWeights[2]); } MetricWeightSet[expansionPieces][1] = metricWeights; }
private void NewGame(ExpansionPieces expansionPieces) { StopPonder(); _gameBoard = new GameBoard(expansionPieces); InitAI(); ConsoleOut(_gameBoard.ToGameString()); }
public void LoadGameAIConfig(XmlReader reader) { if (null == reader) { throw new ArgumentNullException(nameof(reader)); } while (reader.Read()) { if (reader.IsStartElement()) { ExpansionPieces expansionPieces = EnumUtils.ParseExpansionPieces(reader["GameType"]); switch (reader.Name) { case "TranspositionTableSizeMB": ParseTranspositionTableSizeMBValue(reader.ReadElementContentAsString()); break; case "MaxHelperThreads": ParseMaxHelperThreadsValue(reader.ReadElementContentAsString()); break; case "PonderDuringIdle": ParsePonderDuringIdleValue(reader.ReadElementContentAsString()); break; case "MaxBranchingFactor": ParseMaxBranchingFactorValue(reader.ReadElementContentAsString()); break; case "ReportIntermediateBestMoves": ParseReportIntermediateBestMovesValue(reader.ReadElementContentAsString()); break; case "MetricWeights": SetStartMetricWeights(expansionPieces, MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree())); SetEndMetricWeights(expansionPieces, MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree())); break; case "StartMetricWeights": SetStartMetricWeights(expansionPieces, MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree())); break; case "EndMetricWeights": SetEndMetricWeights(expansionPieces, MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree())); break; case "InitialTranspositionTable": SetInitialTranspositionTable(expansionPieces, TranspositionTable.ReadTranspositionTableXml(reader.ReadSubtree())); break; } } } }
public static bool TryParseExpansionPieces(string s, out ExpansionPieces expansionPieces) { try { expansionPieces = ParseExpansionPieces(s); return(true); } catch (Exception) { expansionPieces = default(ExpansionPieces); return(false); } }
public MetricWeights[] GetMetricWeights(ExpansionPieces expansionPieces) { MetricWeights[] result; // Start with the weights for the base game type if (!MetricWeightSet.TryGetValue(ExpansionPieces.None, out result)) { // No base game type, start with nulls result = new MetricWeights[2]; } if (expansionPieces != ExpansionPieces.None) { // Try to get weights specific to this game type if (MetricWeightSet.TryGetValue(expansionPieces, out MetricWeights[] mw))
public static bool IsEnabled(BugType bugType, ExpansionPieces expansionPieces) { switch (bugType) { case BugType.Mosquito: return((expansionPieces & ExpansionPieces.Mosquito) == ExpansionPieces.Mosquito); case BugType.Ladybug: return((expansionPieces & ExpansionPieces.Ladybug) == ExpansionPieces.Ladybug); case BugType.Pillbug: return((expansionPieces & ExpansionPieces.Pillbug) == ExpansionPieces.Pillbug); default: return(true); } }
public static bool IsEnabled(PieceName pieceName, ExpansionPieces expansionPieces) { switch (pieceName) { case PieceName.WhiteMosquito: case PieceName.BlackMosquito: return((expansionPieces & ExpansionPieces.Mosquito) == ExpansionPieces.Mosquito); case PieceName.WhiteLadybug: case PieceName.BlackLadybug: return((expansionPieces & ExpansionPieces.Ladybug) == ExpansionPieces.Ladybug); case PieceName.WhitePillbug: case PieceName.BlackPillbug: return((expansionPieces & ExpansionPieces.Pillbug) == ExpansionPieces.Pillbug); default: return(true); } }
public static ExpansionPieces ParseExpansionPieces(string s) { ExpansionPieces expansionPieces = ExpansionPieces.None; if (!string.IsNullOrWhiteSpace(s)) { string[] split = s.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries); if (split[0] != NoExpansionsString) { throw new ArgumentException(); } if (split.Length == 2) { foreach (char c in split[1]) { switch (char.ToLowerInvariant(c)) { case 'm': expansionPieces |= ExpansionPieces.Mosquito; break; case 'l': expansionPieces |= ExpansionPieces.Ladybug; break; case 'p': expansionPieces |= ExpansionPieces.Pillbug; break; default: throw new ArgumentException(); } } } } return(expansionPieces); }
public static string GetExpansionPiecesString(ExpansionPieces expansionPieces) { string s = NoExpansionsString; if (expansionPieces != ExpansionPieces.None) { s += "+"; if ((expansionPieces & ExpansionPieces.Mosquito) == ExpansionPieces.Mosquito) { s += "M"; } if ((expansionPieces & ExpansionPieces.Ladybug) == ExpansionPieces.Ladybug) { s += "L"; } if ((expansionPieces & ExpansionPieces.Pillbug) == ExpansionPieces.Pillbug) { s += "P"; } } return(s); }
public void UpdateMetricWeights(MetricWeights startMetricWeights, MetricWeights endMetricWeights, ExpansionPieces expansionPieces) { StartMetricWeights = startMetricWeights ?? throw new ArgumentNullException(nameof(startMetricWeights)); EndMetricWeights = endMetricWeights ?? throw new ArgumentNullException(nameof(endMetricWeights)); Records[(int)expansionPieces].AutoTrains++; Update(); }
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(); }
public static GameAI GetTestGameAI(ExpansionPieces expansionPieces) { return(TestUtils.DefaultGameEngineConfig.GetGameAI(expansionPieces)); }
public Board(ExpansionPieces expansionPieces = ExpansionPieces.None) { InitPieces(expansionPieces); }
public MockBoard(ExpansionPieces expansionPieces = ExpansionPieces.None) : base(expansionPieces) { }
public GameBoard(ExpansionPieces expansionPieces = ExpansionPieces.None) : base(expansionPieces) { }