private static Tuple <ChessColors, ChessTimeControl, ChessGameVariants, string, string, string> ParseSettings(string settings) { //!chess new color:{Color}, timemode:{TimeControl}, variant:{GameVariant}, fen:{string}, increment:{int}, time:{double} int settingsIndexStart = settings.IndexOf("new", StringComparison.Ordinal) + 4; if (settings.Length <= settingsIndexStart) { return (new Tuple <ChessColors, ChessTimeControl, ChessGameVariants, string, string, string>( ChessColors.Random, ChessTimeControl.Unlimited, ChessGameVariants.Standard, "", "8", "5.0")); } string[] settingStrings = settings.Substring(settingsIndexStart).ToLower().Replace(" ", "").Split(','); string color = string.Empty; string timemode = string.Empty; string variant = string.Empty; string fen = string.Empty; string increment = "8"; string time = "5.0"; foreach (string setting in settingStrings) { if (setting.Contains("color")) { color = setting.Substring(6, setting.Length - 6); } else if (setting.Contains("timemode")) { timemode = setting.Substring(9, setting.Length - 9); } else if (setting.Contains("variant")) { variant = setting.Substring(8, setting.Length - 8); } else if (setting.Contains("fen")) { fen = setting.Substring(4, setting.Length - 4); } else if (setting.Contains("increment")) { increment = setting.Substring(10, setting.Length - 10); } else if (setting.Contains("time")) { time = setting.Substring(5, setting.Length - 5); } } ChessColors chessColors = (ChessColors)(string.IsNullOrEmpty(color) ? ChessColors.Random : color.GetEnum <ChessColors>()); ChessTimeControl chessTimeControl = (ChessTimeControl)(string.IsNullOrEmpty(timemode) ? ChessTimeControl.Unlimited : timemode.GetEnum <ChessTimeControl>()); ChessGameVariants chessGameVariants = (ChessGameVariants)(string.IsNullOrEmpty(variant) ? ChessGameVariants.Standard : variant.GetEnum <ChessGameVariants>()); return(new Tuple <ChessColors, ChessTimeControl, ChessGameVariants, string, string, string>(chessColors, chessTimeControl, chessGameVariants, fen, increment, time)); }
public static string GetInfo(ChessGameVariants chessGame) { switch (chessGame) { case ChessGameVariants.Standard: return(">Standard: Standard rules of chess (FIDE)"); case ChessGameVariants.Crazyhouse: return(">Crazyhouse: Captured pieces can be dropped back on the board instead of moving a piece."); case ChessGameVariants.Chess960: return(">Chess960: Starting position of the home rank pieces is randomized."); case ChessGameVariants.KingOfTheHill: return(">KingOfTheHill: Bring your King to the center to win the game."); case ChessGameVariants.ThreeCheck: return(">ThreeCheck: Check your opponent 3 times to win the game."); case ChessGameVariants.AntiChess: return(">AntiChess: Lose all your pieces (or reach a stalemate) to win the game."); case ChessGameVariants.Atomic: return(">Atomic: Nuke your opponent's king to win."); case ChessGameVariants.Horde: return(">Horde: Destroy the horde to win!"); case ChessGameVariants.RacingKings: return(">RacingKings: Race your King to the eighth rank to win."); case ChessGameVariants.FromPosition: return(">FromPosition: Custom starting position, needs to set fen parameter to work."); default: return($"{chessGame}: Not Found."); } }