public void FromString(string textExp, List <Variable> variables) { queue = new ExpressionParser(textExp, StandardFunctions.Get(), StandardConstants.Get(), variables ).Build(); Variables = variables; ToExpressionTree(); }
/// <summary> /// If the given <paramref name="value"/> is not effective, the algorithm searches /// for the first effective value in <paramref name="deflts"/>, otherwise the <paramref name="value"/> is returned. /// </summary> /// <returns><paramref name="value"/> if effective, otherwise the first effective value of /// <paramref name="deflts"/> if exists, otherwise <c>null</c>.</returns> /// <param name="value">The value to check and possible return.</param> /// <param name="deflts">An list of default values that must be tried all until a non-effective /// value is found, or the end of the list is reached.</param> /// <typeparam name="T">The type of elements over which the function is defined.</typeparam> /// <remarks> /// <para>If the list of default values is not effective as well, null is returned.</para> /// <para>It is still possible that the result is not effective if both <paramref name="value"/> /// and all items in <paramref name="deflt"/> are <c>null</c> (or the list itself is <c>null</c>).</para> /// </remarks> public static T IfNull <T> (this T value, IEnumerable <T> deflts) where T : class { if (value != null || deflts == null) { return(value); } else { return(Enumerable.FirstOrDefault(deflts, StandardFunctions.NotNull <T> ().Invoke)); } }
public void SpecialMoveChance(Character attacker, Character defender, Fight1v1 fight) { bool activateSpecialMove = false; float specialChanceDivisonFactor = 1000f; float fighterSpecialChanceValue = attacker.Magic + attacker.Strategy; float fighterSpecialChance = fighterSpecialChanceValue / specialChanceDivisonFactor; activateSpecialMove = StandardFunctions.CheckPercentageChance(fighterSpecialChance); if (activateSpecialMove) { //TODO_P: Add a system for handling selection of special moves SpecialMoves.PowerStrike(attacker, defender, fight); } }
public void SecondWindChance(Character fighter, Audience audience) { float comebackitudeChance = fighter.Comebackitude / 10f; bool activateSecondWind = StandardFunctions.CheckPercentageChance(comebackitudeChance); if (activateSecondWind) { fighter.ActivateSecondWind(); if (PlayerWatchingFight) { string secondWindActivation = fighter.FirstName + " has activated " + fighter.Gender.HerHis + " Second Wind!"; fightPanel.UpdateTextLog(secondWindActivation); } } }
void SetAge() { int minAge = 0; int maxAge = 0; int peakAge = 0; minAge = Race.MinAge; maxAge = Race.MaxAge; peakAge = Race.PeakAge; int randomAge = GameObject.Find("GameController").GetComponent <GameController>().GameRandom.Next(minAge, maxAge); //Roll for inital age if (randomAge < peakAge) //Check difference from peak age, if lower have a chance of adjusting it up by half of the difference between set age and peak { int randomPeakDiff = peakAge - randomAge; bool adjust = StandardFunctions.CheckPercentageChance(50); //50% chance if (adjust) { int adjustValue = randomPeakDiff / 2; Age = randomAge + adjustValue; } else { Age = randomAge; } } else if (randomAge > peakAge) //If age is greater than peak age, chance of doing the opposite { int randomPeakDiff = randomAge - peakAge; bool adjust = StandardFunctions.CheckPercentageChance(50); //50% chance if (adjust) { int adjustValue = randomPeakDiff / 2; Age = randomAge + adjustValue; } else { Age = randomAge; } } else { Age = randomAge; } }
public static void CheckNextWeek() { GameController GameController = GameObject.Find("GameController").GetComponent <GameController> (); int nextWeekToPlan = GameController.TotalWeekCount + WeeksPlanned + 1; bool scheduleFight = RegularFightChance(); if (scheduleFight) { bool freeSlot = StandardFunctions.CheckPercentageChance(FreeSlotChance); MatchPlan newMatch = new MatchPlan(); newMatch.SetFightDate(nextWeekToPlan); SetFighters(newMatch, freeSlot); GameController.BookingManager.Calendar.Add(newMatch); } WeeksPlanned = WeeksPlanned++; }
public void LevelUp() { Level = Level + 1; MonoBehaviour.print(FirstName + " is now level " + Level + "!"); Attack = Attack + LevelUpSkillIncrease("attack"); Defense = Defense + LevelUpSkillIncrease("defense"); Magic = Magic + LevelUpSkillIncrease("magic"); Strategy = Strategy + LevelUpSkillIncrease("strategy"); Showcreatureship = Showcreatureship + LevelUpSkillIncrease("showcreatureship"); Comebackitude = Comebackitude + LevelUpSkillIncrease("comebackitude"); MaxHealth = MaxHealth + LevelUpHealthIncrease(); MaxEnergy = MaxEnergy + LevelUpEnergyIncrease(); if (StandardFunctions.CheckPercentageChance(BasicValues.fightMoneyCutLevelIncreaseChance)) { FightMoneyCut++; } ExperiencePoints = 0; }
internal async Task <List <RectangleF> > GenerateBoxes(FixedSizeImage iActivated, Image <Pixel> img, Image <byte> gray) { var ctx = img.Clone(); MoyskleyTech.ImageProcessing.Image.Graphics <Pixel>?graphics = null; if (iActivated != null) { graphics = MoyskleyTech.ImageProcessing.Image.Graphics.FromImage(ctx); Application.Invoke((_, _1) => { iActivated.Image = ctx; }); } //ctx.Width = gray.Width; //ctx.Height = gray.Height; graphics?.Clear(Pixels.White); graphics?.DrawImage(img, 0, 0); List <RectangleF> proposedBoxes = new List <RectangleF>(); AttentionMapAnalizer c = new AttentionMapAnalizer(); //Foreach config, keep proposed boxes foreach (var(p, wz) in StandardFunctions.ListXMeansModes(img)) { proposedBoxes.AddRange(await c.Cluster(gray, graphics, p, wz)); if (iActivated != null) { Application.Invoke((_, _1) => { iActivated.Image = ctx; }); } if (Program.verbose) { Console.WriteLine("MODE {0} {1}", p, wz); } } return(proposedBoxes); }
protected void Page_PreRender(object sender, EventArgs e) { if (CurrentlySelectedFieldId != Guid.Empty) { var defaultFunction = StandardFunctions.GetDefaultFunctionByType(this.CurrentlySelectedType); btnDefaultValueFunctionMarkup.Attributes["label"] = GetString(btnDefaultValueFunctionMarkup.Value.IsNullOrEmpty() ? "DefaultValueSpecify" : "DefaultValueEdit"); btnDefaultValueFunctionMarkup.Attributes["url"] = "${root}/content/dialogs/functions/editFunctionCall.aspx?type=" + this.CurrentlySelectedType.FullName + "&dialoglabel=" + HttpUtility.UrlEncodeUnicode(GetString("DefaultValueDialogLabel")) + "&multimode=false&functionmarkup="; btnTestValueFunctionMarkup.Attributes["label"] = GetString(btnTestValueFunctionMarkup.Value.IsNullOrEmpty() ? "TestValueSpecify" : "TestValueEdit"); btnTestValueFunctionMarkup.Attributes["url"] = "${root}/content/dialogs/functions/editFunctionCall.aspx?type=" + this.CurrentlySelectedType.FullName + "&dialoglabel=" + HttpUtility.UrlEncodeUnicode(GetString("TestValueDialogLabel")) + "&multimode=false&functionmarkup="; btnWidgetFunctionMarkup.Attributes["label"] = CurrentlySelectedWidgetText; btnWidgetFunctionMarkup.Attributes["url"] = "${root}/content/dialogs/functions/editFunctionCall.aspx?functiontype=widget&type=" + this.CurrentlySelectedWidgetReturnType.FullName + "&dialoglabel=" + HttpUtility.UrlEncodeUnicode(GetString("WidgetDialogLabel")) + "&multimode=false&functionmarkup="; if (defaultFunction != null) { string defaultValue = new FunctionRuntimeTreeNode(defaultFunction).Serialize().ToString(); btnDefaultValueFunctionMarkup.DefaultValue = defaultValue; btnTestValueFunctionMarkup.DefaultValue = defaultValue; } } btnDelete.Attributes["isdisabled"] = CurrentlySelectedFieldId == Guid.Empty ? "true" : "false"; if (nameChanged) { UpdateFieldsPanel(); } _state.Parameters = this.CurrentFields.ToList(); SessionStateManager.GetProvider(SessionStateProviderName).SetState(StateId, _state, DateTime.Now.AddDays(7.0)); }
public static bool RegularFightChance() { bool scheduleFight = StandardFunctions.CheckPercentageChance(RegularFightDefaultChance); return(scheduleFight); }
private static void GenerateCode(ProgramNode root, string outputPath) { outputPath = Path.GetFullPath(outputPath); string name = Path.GetFileNameWithoutExtension(outputPath); string filename = Path.GetFileName(outputPath); AssemblyName assemblyName = new AssemblyName(name); AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetDirectoryName(outputPath) ); ModuleBuilder moduleBuilder = assembly.DefineDynamicModule(name, filename); TypeBuilder programType = moduleBuilder.DefineType("Program"); MethodBuilder mainMethod = programType.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes); assembly.SetEntryPoint(mainMethod); //-------------------------------------------------- // Obtener El Generador Para 'Main'. //-------------------------------------------------- ILGenerator MainILGenerator = mainMethod.GetILGenerator(); //-------------------------------------------------- // Generar El Código Para Las Funciones Estándares. //-------------------------------------------------- StandardFunctions.GenerateCodeForStandardFunctions( programType, scope); //-------------------------------------------------- // Generar El Metodo 'run' Para Program. //-------------------------------------------------- MethodBuilder run = programType.DefineMethod( "run", MethodAttributes.Static | MethodAttributes.Public ); //-------------------------------------------------- // Desde Main Hacer Un LLamado A 'run'. Encapsular Con // try/catch //-------------------------------------------------- LocalBuilder exc = MainILGenerator.DeclareLocal(typeof(Exception)); MainILGenerator.BeginExceptionBlock(); MainILGenerator.Emit(OpCodes.Call, run); MainILGenerator.BeginCatchBlock(typeof(Exception)); MainILGenerator.Emit(OpCodes.Stloc_S, exc); MainILGenerator.Emit(OpCodes.Call, typeof(Console).GetProperty("Error").GetMethod); MainILGenerator.Emit(OpCodes.Ldstr, "Exception of type ‘{0}’ was thrown."); MainILGenerator.Emit(OpCodes.Ldloc_S, exc); MainILGenerator.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod("GetType")); MainILGenerator.Emit(OpCodes.Callvirt, typeof(MemberInfo).GetProperty("Name").GetMethod); MainILGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("Format", new Type[] { typeof(string), typeof(string) })); MainILGenerator.Emit(OpCodes.Callvirt, typeof(TextWriter).GetMethod("WriteLine", new Type[] { typeof(string) })); MainILGenerator.Emit(OpCodes.Ldc_I4, 1); MainILGenerator.Emit(OpCodes.Call, typeof(Environment).GetMethod("Exit")); MainILGenerator.EndExceptionBlock(); MainILGenerator.Emit(OpCodes.Ret); //-------------------------------------------------- // Comenzar La Generación De Código. //-------------------------------------------------- root.GenerateCode(moduleBuilder, programType, run.GetILGenerator()); //-------------------------------------------------- // Crear 'Program'. //-------------------------------------------------- programType.CreateType(); moduleBuilder.CreateGlobalFunctions(); assembly.Save(filename); //---------------------------------------------------------------------- // Open ildasm //---------------------------------------------------------------------- //string ildasm = @"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\ildasm.exe"; //(new Process() //{ // StartInfo = { FileName = ildasm, Arguments = @"..\..\program.exe" } //}).Start(); }
/// <summary> /// Closes the scope, used at the end of adding items to the scope. /// </summary> /// <param name="scope">The outer scope, used to attach a fallback mechanism to each /// scope, optionally, by default not effective.</param> public override void CloseScope(IZincIdentScope scope = null) { base.CloseScope(scope); Dictionary <IZincIdent, IZincIdent> replace = new Dictionary <IZincIdent, IZincIdent> (); foreach (Tuple <IZincIdentScope, IZincIdent> matcher in ICompositionUtils.DoubleBlanket <IZincIdentScope, IZincElement> (this, StandardFunctions.AllPredicate <IZincElement> (), x => x is IZincIdent, StandardFunctions.AllPredicate <IZincIdentScope> ()).Cast <Tuple <IZincIdentScope, IZincIdent> > ()) { replace.Add(matcher.Item2, matcher.Item1.NameRegister.Lookup(matcher.Item2)); } this.Replace(replace); }