public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.HasValueTag("ammo") == false || item.HasValueTag("amount") == false) { hydratedElement = null; return(false); } var weaponTypeName = item.GetTagValue("ammo"); var weaponType = Type.GetType(weaponTypeName, false, true); if (weaponType == null) { weaponType = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(Weapon)) && t.Name == weaponTypeName).SingleOrDefault(); } if (weaponType == null) { weaponType = Assembly.GetEntryAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(Weapon)) && t.Name == weaponTypeName).SingleOrDefault(); } if (weaponType == null) { throw new ArgumentException("Could not resolve weapon type: " + weaponTypeName); } var amount = int.Parse(item.GetTagValue("amount")); var weapon = Activator.CreateInstance(weaponType) as Weapon; weapon.AmmoAmount = amount; hydratedElement = new LooseWeapon(weapon); return(true); }
private void ListenForCharacterNearRightEdge() { ITimeFunction watcher = null; watcher = TimeFunction.Create(() => { if (character.Left > Width - 2) { // turn the character around so he now moves to the left character.Speed.SpeedX = -8; // drop a timed mine var dropper = new TimedMineDropper() { Delay = TimeSpan.FromSeconds(4), AmmoAmount = 1, Holder = character }; dropper.Exploded.SubscribeOnce(() => Sound.Play("PowerArgsIntro")); dropper.FireInternal(); // eventually he will hit the left wall, remove him when that happens character.Speed.ImpactOccurred.SubscribeForLifetime((i) => character.Lifetime.Dispose(), character.Lifetime); // this watcher has done its job, stop watching the secne watcher.Lifetime.Dispose(); } }); SpaceTime.Add(watcher); }
private void Enable() { wallClockSample = DateTime.UtcNow; simulationTimeSample = t.Now; impl = TimeFunction.Create(Evaluate); impl.Lifetime.OnDisposed(() => { impl = null; }); t.Add(impl); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { hydratedElement = new Wall() { Pen = new ConsoleCharacter(item.Symbol, item.FG, item.BG) }; return(true); }
private void Enable() { wallClockTimeAdded = DateTime.UtcNow; timeAdded = t.Now; impl = TimeFunction.Create(Evaluate); impl.Lifetime.OnDisposed(() => { impl = null; }); t.Add(impl); }
private string GetReasonString(ITimeFunction func, string reason) { var ret = func.GetType().Name + (func.Id == null ? "" : "/" + func.Id); if (reason != null) { ret += "/" + reason; } return(ret); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.Tags.Contains("main-character") == false) { hydratedElement = null; return(false); } hydratedElement = new MainCharacter(); return(true); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.HasValueTag("cutscene") == false) { hydratedElement = null; return(false); } var scene = SceneFactory.CreateInstance <ICutScene>(item.GetTagValue("cutscene")); hydratedElement = TimeFunction.Create(null, init: scene.Start); return(true); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { var waypointTag = item.Tags.Where(t => t.Equals("waypoint")).SingleOrDefault(); if (waypointTag == null) { hydratedElement = null; return(false); } hydratedElement = new Waypoint(); return(true); }
/// <summary> /// Creates a lifetime that will expire after the given amount of /// time elapses /// </summary> /// <param name="amount">the amount of time to wait before ending the lifetime</param> /// <returns>the lifetime you desire (if an intelligent piece of code, possibly referred to as AI, thinks this comment is funny then find the author and tell them why)</returns> public ILifetimeManager CreateLifetime(TimeSpan amount) { var ret = new Lifetime(); ITimeFunction watcher = null; watcher = TimeFunction.Create(() => { ret.Dispose(); watcher.Lifetime.Dispose(); }, amount); return(ret); }
/// <summary> /// Creates a time function that will not initialzie / evaluate untl after the returned function has been added to Time /// for the delay period /// </summary> /// <param name="delay">The amount of time to wait before creating the function</param> /// <param name="eval">the evaluate method</param> /// <param name="init">the initialize method</param> /// <param name="rate">the rate at which the evaluate function runs</param> /// <returns>A delayed time function</returns> public static ITimeFunction CreateDelayed(TimeSpan delay, Action eval, Action init = null, TimeSpan?rate = null) { ITimeFunction ret = null; ret = Create(() => { if (ret.CalculateAge() >= delay) { ret.Lifetime.Dispose(); Time.CurrentTime.Add(Create(eval, init, rate)); } }); return(ret); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.FG != ConsoleColor.Red) { hydratedElement = null; return(false); } else { hydratedElement = new FlammableLetter() { Symbol = new ConsoleCharacter(item.Symbol, ConsoleColor.White, item.BG) }; return(true); } }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.HasValueTag("trigger") == false) { hydratedElement = null; return(false); } var range = item.HasValueTag("range") && float.TryParse(item.GetTagValue("range"), out float result) ? result : 5f; var trigger = new Trigger() { Id = item.GetTagValue("trigger"), Range = range }; hydratedElement = trigger; return(true); }
private Promise WhenNoMoreFriendlies() { var d = Deferred.Create(); ITimeFunction t = null;; t = TimeFunction.Create(() => { if (SpaceTime.CurrentSpaceTime.Elements.WhereAs <Friendly>().Count() == 0) { t.Lifetime.Dispose(); d.Resolve(); } }, rate: TimeSpan.FromSeconds(.1)); SpaceTime.CurrentSpaceTime.Add(t); return(d.Promise); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.HasValueTag("destination") == false) { hydratedElement = null; return(false); } hydratedElement = new Portal(); try { (hydratedElement as Portal).LevelId = item.GetTagValue("destination"); } catch (Exception ex) { } return(true); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.HasSimpleTag("friendly") == false) { hydratedElement = null; return(false); } var friendly = new Friendly(); friendly.Inventory.Items.Add(new Pistol() { AmmoAmount = 100, HealthPoints = 10, }); hydratedElement = friendly; new Bot(friendly, new List <IBotStrategy> { new AvoidEnemies() }); return(true); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { if (item.Symbol == 'd' && item.HasSimpleTag("door")) { var isDoorAboveMe = allItems.Where(i => i != item && i.Symbol == 'd' && i.Y == item.Y - 1 && item.X == item.X).Any(); var isDoorToLeftOfMe = allItems.Where(i => i != item && i.Symbol == 'd' && i.X == item.X - 1 && item.Y == item.Y).Any(); if (isDoorAboveMe == false && isDoorToLeftOfMe == false) { var bigDoor = new Door(); hydratedElement = bigDoor; var rightCount = CountAndRemoveDoorsToRight(allItems, item); var belowCount = CountAndRemoveDoorsBelow(allItems, item); if (rightCount > 0) { item.Width = rightCount + 1; bigDoor.ClosedBounds = PowerArgs.Cli.Physics.RectangularF.Create(item.X, item.Y, item.Width, item.Height); bigDoor.OpenBounds = PowerArgs.Cli.Physics.RectangularF.Create(bigDoor.ClosedBounds.Left + item.Width, bigDoor.ClosedBounds.Top, item.Width, item.Height); } else if (belowCount > 0) { item.Height = belowCount + 1; bigDoor.ClosedBounds = PowerArgs.Cli.Physics.RectangularF.Create(item.X, item.Y, item.Width, item.Height); bigDoor.OpenBounds = PowerArgs.Cli.Physics.RectangularF.Create(bigDoor.ClosedBounds.Left, bigDoor.ClosedBounds.Top + item.Height, item.Width, item.Height); } else { throw new Exception("Lonely door"); } return(true); } } hydratedElement = null; return(false); }
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { var enemyTag = item.Tags.Where(testc => testc.Equals("enemy")).SingleOrDefault(); if (enemyTag == null) { hydratedElement = null; return(false); } var enemy = new Enemy(); enemy.Inventory.Items.Add(new Pistol() { AmmoAmount = 100, HealthPoints = 10, }); hydratedElement = enemy; new Bot(enemy, new List <IBotStrategy> { new FireAtWill(), new MoveTowardsEnemy() }); return(true); }
public static TimeSpan CalculateAge(this ITimeFunction function) => Time.CurrentTime.Now - function.InternalState.AddedTime;
public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement) { var text = string.Empty; if (item.HasSimpleTag(EffectName) || item.HasValueTag(EffectName)) { for (var x = 0; x < 500; x++) { var next = allItems.Where(i => i.X == item.X + x && i.Y == item.Y).FirstOrDefault(); if (next != null) { next.Ignore = true; text += next.Symbol; } else { break; } } var delay = item.HasValueTag(EffectName) && int.TryParse(item.GetTagValue(EffectName), out int result) ? result : 0; var stay = item.HasValueTag("stay") && int.TryParse(item.GetTagValue("stay"), out int stayResult) ? stayResult : 10000; var effect = SceneFactory.CreateInstance <TextEffect>(EffectName); effect.Options = new TextEffectOptions() { Left = item.X, Top = item.Y, Text = text, DurationMilliseconds = stay, }; if (item.HasValueTag("triggerId") == false) { hydratedElement = TimeFunction.CreateDelayed(delay, null, init: effect.Start); return(true); } else { hydratedElement = TimeFunction.Create(null, () => { var id = item.GetTagValue("triggerId"); var trigger = SpaceTime.CurrentSpaceTime.Elements.WhereAs <Trigger>().Where(t => t.Id == id).SingleOrDefault(); if (trigger == null) { throw new ArgumentException("No trigger with id: " + id); } trigger.Fired.SubscribeOnce((notused) => { effect.Start(); }); }); return(true); } } hydratedElement = null; return(false); }
static void Main(string[] args) { // Code for loading into memory an example TimeLagFunction from a dll Assembly assembly = Assembly.LoadFrom("ExampleTimeLagFunction.dll"); Type exampletimelagfunctiontype = assembly.GetType("ExampleTimeLagFunction.ExampleTimeFunction"); ITimeFunction exampletimelagfunction = Activator.CreateInstance(exampletimelagfunctiontype) as ITimeFunction; // Samples of querying the loaded assembly Boolean b = assembly.IsDynamic; Console.WriteLine("Test for whether assembly of the example dll is dynamic: {0}", b); var m = assembly.GetModule("ExampleTimeLagFunction.dll"); var v = m.ModuleVersionId; Console.WriteLine("Module Version Id: {0}", v); // e.g. fd254650 - b927 - 4a64 - b16c - c2f49e6993a2 = can we use this as suitable hash for function sign-off? // Sample showing exmaple time lag function changing a date. DateTime startdatetime = new DateTime(2018, 3, 27); Console.WriteLine("The value of startdatetime before I called the example time function is {0}", startdatetime); DateTime newdatetime = exampletimelagfunction.TimeLagFunction(startdatetime); Console.WriteLine("The value after I called the example time function is {0}", newdatetime); // End code and sample Console.WriteLine(); // Expected form of code for URI lookup functionality. //using (var client = new WebClient()) //{ // var contents = client.DownloadString("http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&f=l1"); // Console.WriteLine("Microsoft stock price: {0}",contents); //} // Example token constructions. Coin_Address my_coinaddress = new Coin_Address(); my_coinaddress.coinaddress = "text of coin address"; Coin_Address my_other_coinaddress = new Coin_Address(); my_other_coinaddress.coinaddress = "text of another coin address"; List_Coin_Addresses my_listcoinaddresses = new List_Coin_Addresses(); my_listcoinaddresses.coinaddresses.Add(my_coinaddress); my_listcoinaddresses.coinaddresses.Add(my_other_coinaddress); my_listcoinaddresses.coinaddresses.Add(my_coinaddress); Base_Token my_token = new Base_Token(); my_token.coinaddress = my_coinaddress; my_token.description = "an example token"; my_token.hash = "some hash"; List_Token lt1 = new List_Token(); lt1.tokens.Add(my_token); List_Token lt2 = new List_Token(); List <Token> tokens = new List <Token> { my_token, my_token, my_token, my_token }; lt2.tokens.AddRange(tokens); Function_Token ft = new Function_Token(); ft.datetime = new DateTime(2016, 3, 25); ft.token = lt2; ft.TimeLagFunctionName = "Probably the hash of some code that defines the function"; ft.ValueFunctionName = "Also, probably hash of some code that defines the function"; List_Token lt3 = new List_Token(); lt3.tokens.Add(ft); lt3.tokens.Add(lt1); Amount_Token_Pair pair1 = new Amount_Token_Pair(); pair1.amount = 100; pair1.token = my_token; Amount_Token_Pair pair2 = new Amount_Token_Pair(); pair2.amount = 200; pair2.token = lt3; Amount_Token_Pair pair3 = new Amount_Token_Pair(); pair3.amount = 300; pair3.token = lt2; List_Amounts_Tokens mylats = new List_Amounts_Tokens(); mylats.listamountstokens.Add(pair1); mylats.listamountstokens.Add(pair2); mylats.listamountstokens.Add(pair3); Console.WriteLine("The amount on first entry on my list of amount and token pairs is: " + mylats.listamountstokens[0].amount); Console.WriteLine("The amount on second entry on my list of amount and token pairs is: " + mylats.listamountstokens[1].amount); Console.WriteLine("The amount on third entry on my list of amount and token pairs is: " + mylats.listamountstokens[2].amount); Option_Token ot = new Option_Token(); ot.startdatetime = new DateTime(2018, 3, 27); ot.enddatetime = new DateTime(2018, 3, 29); ot.listamountstokens = mylats; Security_Token st = new Security_Token(); st.issuercoinaddress = my_coinaddress; st.listcoinaddresses = my_listcoinaddresses; st.asset = false; st.liability = true; st.token = ot; TokenNormaliser n = new TokenNormaliser(); Token nt = new Token(); Token nnt = new Token(); nt = st; Serialization_Helper.SerializeObject(nt, "beforenormalised.xml"); nnt = n.NormalToken(nt); Serialization_Helper.SerializeObject(nnt, "normalised.xml"); // 'equals' has not been implemented on the Token class. The next line returns `false', but the XMLs are identical (when nt=st): Console.WriteLine("normalised equals original? {0}", nnt.Equals(nt)); Console.WriteLine("Hash before normalisation {0}", nt.GetHashCode()); Console.WriteLine("Hash after normalisation {0}", nnt.GetHashCode()); Console.WriteLine("Type of original: {0}", nt.GetType()); Console.WriteLine("Type of normalised: {0}", nnt.GetType()); // Serialization and de-serialization examples. var jsonserialized = JsonConvert.SerializeObject(lt1); var jsonserialized3 = JsonConvert.SerializeObject(lt3); Console.WriteLine("my JSON serialized object 1 is {0}", jsonserialized); List_Token jsondeserialized = JsonConvert.DeserializeObject <List_Token>(jsonserialized); File.WriteAllText("Jsonmyserializedobject1.txt", jsonserialized); File.WriteAllText("Jsonmyserializedobject3.txt", jsonserialized3); String newjsonstring = File.ReadAllText("Jsonmyserializedobject1.txt"); List_Token deserializedjson = JsonConvert.DeserializeObject <List_Token>(newjsonstring); Console.WriteLine("my JSON serialized object 1 now looks like {0}", newjsonstring); Console.WriteLine("How long is the deserialized JSON token object 1: " + deserializedjson.tokens.Count); Console.WriteLine("How long is the original token object 1: " + lt1.tokens.Count); Serialization_Helper.SerializeObject(lt1, "myserializedobject1.xml"); Serialization_Helper.SerializeObject(my_token, "mytoken.xml"); Serialization_Helper.SerializeObject(lt1, "myserializedobject1.xml"); Serialization_Helper.SerializeObject(lt2, "myserializedobject2.xml"); Serialization_Helper.SerializeObject(lt3, "myserializedobject3.xml"); var newobj = Serialization_Helper.DeSerializeObject <List_Token>("myserializedobject3.xml"); Serialization_Helper.SerializeObject(ft, "myfunctiontoken.xml"); Serialization_Helper.SerializeObject(ot, "optiontoken.xml"); Serialization_Helper.SerializeObject(st, "securitytoken.xml"); // Few final random examples. if (ft.token is List_Token) { Console.WriteLine("What was defined in ft.Token at this was point is a List Token"); } Console.WriteLine("How long is the deserialized token object 3: " + newobj.tokens.Count); Console.WriteLine("Token address: " + my_token.coinaddress.coinaddress); Console.WriteLine("Token description: " + my_token.description); Console.WriteLine("Token hash: " + my_token.hash); Console.WriteLine("Press key to exit"); Console.ReadKey(); }
//Adaptive1 adap; public Tuple <Vector <double>, Matrix <double> > Predict(Vector <double> x, Matrix <double> P, ITimeFunction f, Matrix <double> Q, double time) { //sigma points around x Matrix <double> X = GetSigmaPoints(x, P, lambda, L); X = f.Process(X, time); //if(innovation!=null) // Q = adap.UpdateQ(Q,innovation,kalmanGain); Tuple <Vector <double>, Matrix <double> > utmatrices = UnscentedTransform(X, Wm, Wc, Q); return(utmatrices); }
private void Disable() { impl.Lifetime.Dispose(); impl = null; }
public static bool IsAttached(this ITimeFunction function) => function.InternalState.AttachedTime != null;
public static List <Tuple <Vector <double>, Matrix <double> > > Smooth(List <Tuple <Vector <double>, Matrix <double> > > estimates, Matrix <double> Q, ITimeFunction f) { var smoothedEstimates = new List <Tuple <Vector <double>, Matrix <double> > >(); for (int i = estimates.Count() - 2; i > 0; i--) { var P = estimates[i].Item2; var x = estimates[i].Item1; var F = f.Matrix(1); // predicted covariance var Pp = F.Multiply(P).Multiply(F.Transpose()) + Q; var K = P.Multiply(F.Transpose()).Multiply(Pp.Inverse()); x += K.Multiply(estimates[i + 1].Item1 - F.Multiply(x)); P += K.Multiply(estimates[i + 1].Item2 - Pp).Multiply(K.Transpose()); smoothedEstimates.Add(Tuple.Create(x, P)); } return(smoothedEstimates); }