public static string GenerateDeck(int seed) { var cards = string.Empty; String[] suit = { "C", "S", "H", "D" }; String[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" }; // initialize cards in a deck var deck = new String[suit.Length * rank.Length]; for (var i = 0; i < rank.Length; i++) for (var j = 0; j < suit.Length; j++) deck[suit.Length*i + j] = rank[i] + suit[j]; // shuffle deck var d = deck.Length; var rand = new Random(seed); for (var i = 0; i < d; i++) { var r = i + (int) (rand.NextDouble() * (d-i)); var temp = deck[r]; deck[r] = deck[i]; deck[i] = temp; } var generateDeck = deck.Aggregate(cards, (current, s) => current + (s + " ")); Console.WriteLine(generateDeck); return generateDeck; }
/// <summary> /// Converts a four-char value to an unsigned integer. /// </summary> /// <param name = "fourCharValue">The four char value.</param> /// <returns>An unsigned integer</returns> public static uint FourCharToInt(String fourCharValue) { if (fourCharValue.Length != 4) { throw new ArgumentException(); } return fourCharValue.Aggregate(0u, (i, c) => (i*256) + c); }
public static void Main(String[] args) { // This fixes the current directory in case it is run from outside the launcher path. Environment.CurrentDirectory = Path.GetDirectoryName(typeof(SharpCraftApplication).Assembly.Location); // Check for optional map specified to launch string mapFile = ""; // Is there a loadfile arg specified? for (var i = 0; i < args.Length; i++) { if (args[i] == "-loadfile" && args.Last() != "-loadfile") // if -loadfile and there are still more args to read { // check the argument immediately to the right... it should be a map file (w3x or w3m) or a replay (w3g) if (args[i + 1].EndsWith(".w3x") || args[i + 1].EndsWith(".w3m") || args[i + 1].EndsWith(".w3g")) { mapFile = args[i + 1]; // clean string and wrap in quotes because path may contain spaces // note: even when passing in the arg in quotes, those will "disappear", so quotes are re-applied args[i + 1] = "\"" + args[i + 1].Trim() + "\""; } else { Console.WriteLine("The -loadfile param was specified, but was not immediately followed by a valid WarCraft map to open."); } } else { Console.WriteLine("The -loadfile param was specified, but no more valid arguments follow it!"); } } if (args.Contains("-game") || args.Contains("-editor")) { Debug.WriteLineIf(args.Contains("-game"), args.Aggregate((a, b) => a + ' ' + b)); Debug.WriteLineIf(mapFile.Length > 0, "Starting game with map: " + mapFile); StartDirect(args); } else { StartLauncher(args); } }
protected virtual String Deliminated(String deliminator, String[] strings) { return strings .Aggregate("", (a, s) => (a == "" ? a : a + deliminator) + s); }
/// /// <param name="values"></param> public static int hashCode(String[] values) { return values.Aggregate(31, (current, t) => current ^ t.GetHashCode()); }
public static void StartEditor(String[] args) { if (!Common.IsInitialized) Common.Initialize(); if (!File.Exists(Common.EditorPath)) throw new FileNotFoundException("Could not find worldedit.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "worldedit.exe"); if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll"))) throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll"); Boolean kill = false; Boolean debug = false; Boolean valid = true; while (valid && args.Length > 0) { switch (args[0]) { case "-kill": kill = true; args = args.Skip(1).ToArray(); break; case "-debug": debug = true; args = args.Skip(1).ToArray(); break; default: valid = false; break; } } var worldedits = Process.GetProcessesByName("worldedit"); if (worldedits.Count() > 0) { if (kill) { foreach (var worldedit in worldedits) worldedit.Kill(); } else throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it."); } Console.Write("Creating and injecting into World Editor . . . "); var cmd = '"' + Common.EditorPath + '"'; if (args.Length > 0) cmd += ' ' + args.Aggregate((a, b) => a + ' ' + b); Int32 processId; RemoteHooking.CreateAndInject(Common.EditorPath, cmd, 0, "SharpCraft.dll", "SharpCraft.dll", out processId, PluginContext.Editor, debug, Environment.CurrentDirectory, Common.InstallPath); Console.WriteLine("Done!"); }
static int GetProductOf5Digits(String s) { return s.Aggregate(1, (int prod, char ch) => prod * int.Parse(ch.ToString())); }
private String Dictionary2String(Dictionary<String, object> dict) { String[] tmp = new String[dict.Count]; var q = dict.OrderBy(p => p.Key); for (int i = 0; i < dict.Count; ++i) { tmp[i] = String.Format("{0}={1}", q.ElementAt(i).Key, q.ElementAt(i).Value.ToString()); } return tmp.Aggregate((s1, s2) => s1 + "&" + s2); }
public static string Translite(String input) { return input.Aggregate("", (current, _char) => current + (Char.IsLetter(_char) ? _dict[_char] : _char.ToString())); }