private void Construct(int id, Rectangle sourceRect, DictionaryWithDefault <string, bool> customBools, DictionaryWithDefault <string, string> customStrings) { ID = id; SourceRect = sourceRect; CustomBools = customBools; CustomStrings = customStrings; }
public GarbageCollector() { _nodes = new DictionaryWithDefault <long, Node>(id => new Node(id) { Color = _color }); }
private static long Run(HashSet <MultiDimensionalPosition> initialState) { return(Produce.Iterate(initialState, 6, current => { var adjacentCounts = new DictionaryWithDefault <MultiDimensionalPosition, int>(0); // Look at all active cells and all cells adjacent to active cells var cells = new HashSet <MultiDimensionalPosition>(); foreach (var position in current) { cells.Add(position); foreach (var pos2 in position.Adjacents()) { cells.Add(pos2); adjacentCounts[pos2] += 1; } } var next = cells.Where(position => { var active = current.Contains(position); return (active && adjacentCounts[position].IsInRange(2, 3)) || (!active && adjacentCounts[position] == 3); }).ToHashSet(); return next; }) .Count); }
public Serializers(SerializerFactory serializerFactory) { _serializerFactory = serializerFactory; _objectToId = new DictionaryWithDefault <object, long>( _ => _nextObjectId++, new Dictionary <object, long>(new ObjectReferenceEqualityComparer <object>()) ); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException; if (!Environment.UserInteractive) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } else { string parameter = string.Concat(args); switch (parameter) { case "--install": ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); break; case "--uninstall": ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); break; default: // running as console app // Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); // Console.WriteLine(String.Format("Install servicve using {0} --install (or --uninstall).", System.AppDomain.CurrentDomain.FriendlyName)); // Console.WriteLine("Press [CTRL][C] to stop..."); // Service1 myService = new Service1(); // myService.onDebug(); // System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); DictionaryWithDefault <string, string> arg = commandArgumentsParser(args); DateTime UTCtime = GetNetworkUTCTime(); if (!string.IsNullOrEmpty(arg["add"])) { int addMin = 0; int.TryParse(arg["add"], out addMin); UTCtime = UTCtime.AddMinutes(addMin); } if (!string.IsNullOrEmpty(arg["set"])) { Console.WriteLine("Setting time: " + UTCtime.ToLocalTime().ToString()); setSystemTime(UTCtime); } if (!string.IsNullOrEmpty(arg["showoffset"])) { Console.WriteLine("Time difference: " + (DateTime.UtcNow - UTCtime).TotalSeconds + " seconds."); } Console.WriteLine(UTCtime.ToLocalTime().ToString()); break; } } }
private void RecursiveAddHeavyDown(DictionaryWithDefault <Point, bool> canSee, Point seenHeavyTile, List <Point> possiblePoints) { var potentialPoint = new Point(seenHeavyTile.X, seenHeavyTile.Y + 1); if (GameWorld.Map.Exists(potentialPoint) && GameWorld.Map[potentialPoint].Cover == Cover.Heavy && possiblePoints.Contains(potentialPoint)) { canSee[potentialPoint] = true; RecursiveAddHeavyUp(canSee, potentialPoint, possiblePoints); } }
/// <summary> /// Getting named command line parameters /// </summary> static DictionaryWithDefault <string, string> commandArgumentsParser(string[] args) { DictionaryWithDefault <string, string> arg = new DictionaryWithDefault <string, string>() { }; string name = null; int i = 0; foreach (string a in args) { string[] parts = a.Split('='); if (Regex.IsMatch(parts[0], @"^(--|\/)")) { if (!string.IsNullOrEmpty(name)) { arg[name] = "1"; arg[i.ToString()] = name; i++; name = null; } if (parts.Length > 1) { arg[Regex.Replace(parts[0], @"^(--|\/)", "")] = parts[1]; arg[i.ToString()] = Regex.Replace(a, @"^(--|\/)", ""); i++; } else { name = Regex.Replace(parts[0], @"^(--|\/)", ""); } } else { if (!string.IsNullOrEmpty(name)) { arg[name] = parts[0]; name = null; arg[i.ToString()] = a; i++; } else { arg[i.ToString()] = a; i++; } } } if (!string.IsNullOrEmpty(name)) { arg[name] = "1"; name = null; arg[i.ToString()] = name; i++; } return(arg); }
public void UpdatePerception() { var friendlyPerception = new DictionaryWithDefault <Point, bool>(false); GameWorld.Friendlies.ForEach(friendly => { friendly.State.SeeableTiles.ForEach(tile => friendlyPerception[tile.Key] = true); friendly.State.PerceivedTiles.ForEach(tile => friendlyPerception[tile.Key] = true); }); GameWorld.FriendlyPerception = friendlyPerception; }
public TsxTile(int id, Rectangle sourceRect, XElement tile) { var customBools = new DictionaryWithDefault <string, bool>(false); var customStrings = new DictionaryWithDefault <string, string>(""); var properties = tile.Element(XName.Get("properties")).Elements(XName.Get("property")).ToList(); properties.Where(x => new XValueWithDefault(x, "type", "string").AsString() == "bool").ToList() .ForEach(x => customBools[new XValue(x, "name").AsString()] = new XValue(x, "value").AsBool()); properties.Where(x => new XValueWithDefault(x, "type", "string").AsString() == "string").ToList() .ForEach(x => customStrings[new XValue(x, "name").AsString()] = new XValue(x, "value").AsString()); Construct(id, sourceRect, customBools, customStrings); }
public static DictionaryWithDefault<string, string> MatchGroup(this string input, string pattern) { DictionaryWithDefault<string, string> ret = new DictionaryWithDefault<string, string>(); Match matchRegex = Regex.Match(input, pattern); if (matchRegex.Success) { IList<string> groupNameList = new List<string>(); //string groupNamePattern = @"\(\?<(?<name>.+?)>.+?\)"; MatchCollection mc = Regex.Matches(pattern, GroupPattern, RegexOptions.Compiled); foreach (Match m in mc) { Group group = m.Groups[GroupPatternName]; if (group.Success) { groupNameList.Add(group.Value); } } if (groupNameList == null || groupNameList.Count == 0) { return ret; } else { if (matchRegex.Groups != null && matchRegex.Groups.Count > 0) { foreach (string groupName in groupNameList) { Group group = matchRegex.Groups[groupName]; if (group != null && group.Success) { ret[groupName] = group.Value; } } return ret; } else { return ret; } } } else { return ret; } }
string GetBestGroup(IEnumerable <string> source, int minNameLength) { var s = new Stack <string>(source); var counter = new DictionaryWithDefault <string, int>(0); while (s.Any()) { var g = GetCommonPrefix(s); if (!string.IsNullOrEmpty(g) && g.Length >= minNameLength) { counter[g]++; } s.Pop(); } return(counter.OrderBy(c => c.Value).Last().Key); }
private static HashSet <Position> Initialize(List <string> input) { var counts = new DictionaryWithDefault <Position, int>(0); foreach (var s in input) { var directions = Regex.Matches(s, "se|sw|nw|ne|e|w"); var key = directions.Aggregate(Position.Zero, (position, match) => match.Value switch { "se" => position + SouthEast, "sw" => position + SouthWest, "w" => position + West, "nw" => position + NorthWest, "ne" => position + NorthEast, "e" => position + East, _ => throw new ApplicationException() });
public DictionaryWithDefault <Point, bool> Calculate() { DictionaryWithDefault <Point, bool> canSee = new DictionaryWithDefault <Point, bool>(false); var possibleTiles = new PointRadiusCalculation(_character.CurrentTile.Position, calculation).Calculate() .Where(x => GameWorld.Map.Exists(x)).ToList(); possibleTiles .Where(x => new ShotCalculation(_character.CurrentTile, GameWorld.Map[x]).CanShoot()) .ForEach(x => canSee[x] = true); canSee.Where(x => GameWorld.Map[x.Key].Cover == Cover.Heavy) .ForEach(x => { RecursiveAddHeavyUp(canSee, x.Key, possibleTiles); RecursiveAddHeavyDown(canSee, x.Key, possibleTiles); }); return(canSee); }
public LevelMusic(string ambientSongName, string actionSongName, string bossSongName, float ambientMusicVolume = 1, float actionMusicVolume = 0.6f, float bossMusicVolume = 0.6f) { AudioDirector.Instance.MaxMusic = 3; _songs = new DictionaryWithDefault <MusicType, Sound>(Sound.Music(ambientSongName)) { { MusicType.Ambient, Sound.Music(ambientSongName, 0) }, { MusicType.Action, Sound.Music(actionSongName, 0) }, { MusicType.Boss, Sound.Music(bossSongName, 0) } }; _volumes = new DictionaryWithDefault <MusicType, float>(0.6f) { { MusicType.Ambient, ambientMusicVolume }, { MusicType.Action, actionMusicVolume }, { MusicType.Boss, bossMusicVolume } }; _currentSound = MusicType.Boss; }
public Color ColorFor(ThemeElement element) { var colors = new DictionaryWithDefault <ThemeElement, Color>(defaultColor) { { ThemeElement.ButtonTextTint, menuButtonTextTint }, { ThemeElement.PrimaryTextColor, headerTextColor }, { ThemeElement.SecondaryTextColor, dialogueButtonTextTint }, { ThemeElement.PrimaryBorderColor, borderTint }, { ThemeElement.PanelTint, panelTint }, { ThemeElement.SettingsTextTint, settingsTextTint }, { ThemeElement.IconButtonTint, iconButtonTint }, { ThemeElement.IconButtonHoverTint, iconButtonHoverTint }, { ThemeElement.IconButtonPressedTint, iconButtonPressedTint }, { ThemeElement.CreditsTint, creditsTint }, }; return(colors[element]); }
public StateMaps(Serializers serializers) { _stateMaps = new DictionaryWithDefault <long, StateMap>(_ => new StateMap(serializers)); }
public BuildPropertiesContext(IBuildPropertiesSession properties) { Properties = properties; ScriptArgs = new DictionaryWithDefault <string, string>(null, StringComparer.OrdinalIgnoreCase); }
public ExecutionPlan(string[] inputlines) { if (inputlines == null) { throw new ArgumentException("inputlines must not be null."); } this.wasQueryProcessed = new DictionaryWithDefault <Query, bool>(false); this.networkPlan = new Dictionary <NodeName, NodeParams>(); this.sourceNodesByEventName = new Dictionary <EventType, HashSet <NodeName> >(); this.forwardRulesByNodeName = new Dictionary <NodeName, Dictionary <EventType, ForwardRule> >(); this.queriesByNodeName = new Dictionary <NodeName, HashSet <Query> >(); // parsing the which nodes there are and what primitive events they generate at what rates parseNetworkPlan(inputlines); // initialize members now that the nodeCount is known foreach (var nodeName in networkPlan.Keys) { forwardRulesByNodeName[nodeName] = new Dictionary <EventType, ForwardRule>(); queriesByNodeName[nodeName] = new HashSet <Query>(); } var remaining = inputlines.Skip(numberOfNodes + 1).ToArray(); var primitiveInputModeLine = remaining[0]; if (primitiveInputModeLine.Trim().ToLower().Contains("randomized rate-based")) { primitiveInputMode = PrimitiveInputMode.RANDOM_WITH_RATES; if (!remaining[1].Trim().StartsWith("-")) { throw new ArgumentException("dash separation line expected after randomized rate-based primitive event generation statement "); } remaining = remaining.Skip(2).ToArray(); } else { primitiveInputMode = PrimitiveInputMode.DATASET; datasetFileNameTemplate = remaining[1].Trim(); if (!remaining[2].Trim().StartsWith("-")) { throw new ArgumentException("dash separation line expected after Dataset-Based Primitive Event Generation statement and a single next line with the dataset configuration"); } remaining = remaining.Skip(3).ToArray(); } // parsing what queries and compex events there are parseComplexQueries(remaining); // foreach (var eventName in parsedQueries.Keys) // { // sourceNodesByEventName[eventName] = new HashSet<NodeName>(); // } // deriving forward rules and query placements on node ids deriveQueryPlacementAndForwardRules(); }
private PlayerStatAddends(DictionaryWithDefault <string, float> values) => _values = values;
private StatMultipliers(DictionaryWithDefault <string, float> values) => _values = values;
public static void Main(string[] args) { DictionaryWithDefault<string, Action> d = new DictionaryWithDefault<string, Action>(delegate { }); d["mirko"](); }
public BuildPropertiesContext(IBuildPropertiesSession properties) { Properties = properties; ScriptArgs = new DictionaryWithDefault <string, string>(null); }
public static State Load(IStorageEngine storageEngine, ISet <object> ephemeralInstances) { var valuesDictionaries = new DictionaryWithDefault <long, Dictionary <string, object> >(_ => new Dictionary <string, object>()); //Load all entries from log file var storedState = storageEngine.Load(); var serializers = new Serializers(new SerializerFactory()); var stateMaps = new StateMaps(serializers); var entriesPerOwner = storedState.StorageEntries; //var entriesPerOwner = storedState.StorageEntries; var serializersTypeEntries = storedState.Serializers; var toDeserialize = new Queue <long>(); var referenced = new DictionaryWithDefault <long, List <Reference> >(_ => new List <Reference>()); ISerializer Deserialize(long id) { if (serializers.ContainsKey(id)) { return(serializers[id]); } var ownerEntries = entriesPerOwner.ContainsKey(id) ? entriesPerOwner[id] : Enumerable.Empty <StorageEntry>(); var resolvedValues = valuesDictionaries[id]; //deserialize non-referencing values var resolvableEntries = ownerEntries .Where(e => !e.Reference.HasValue) .ToList(); foreach (var resolvableEntry in resolvableEntries) { resolvedValues[resolvableEntry.Key] = resolvableEntry.Value; } var referencedEntries = ownerEntries.Where(e => e.Reference.HasValue); foreach (var referencedEntry in referencedEntries) { // ReSharper disable once PossibleInvalidOperationException var wp = Deserialize(referencedEntry.Reference.Value); resolvedValues[referencedEntry.Key] = wp.Instance; } var serializer = (ISerializer)DeserializationMethodInvoker .Invoke( id, serializersTypeEntries[id], valuesDictionaries[id], ephemeralInstances ); stateMaps[id] = new StateMap(serializers, resolvedValues); serializers.Add(serializer); if (serializer.Instance is Reference r && r.Id.HasValue) { toDeserialize.Enqueue(r.Id.Value); referenced[r.Id.Value].Add(r); } return(serializer); } var roots = (Roots)Deserialize(0).Instance; ephemeralInstances.Add(roots); while (toDeserialize.Any()) { Deserialize(toDeserialize.Dequeue()); } foreach (var serializer in serializers) { foreach (var reference in referenced[serializer.Id]) { reference.SetSerializer(serializer); } } return(new State(roots, stateMaps, serializers)); }