public void Initialize(Character parent) { _parentCharacter = parent; _workingMemory = _parentCharacter.MyAI.WorkingMemory; _parentCharacter.MyEventHandler.OnOneSecondTimer -= UpdatePerSecond; _parentCharacter.MyEventHandler.OnOneSecondTimer += UpdatePerSecond; PersonalThreatThreshold = 0.6f; }
public void doParsing() { //go ! WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); //Message message = new Message(); //message.status = Message.GOODBYE; workingMemory.assertObject(message); workingMemory.fireAllRules(); }
public void Initialize(Character parent) { _parentCharacter = parent; _workingMemory = _parentCharacter.MyAI.WorkingMemory; _parentCharacter.MyEventHandler.OnOneSecondTimer -= UpdatePerSecond; _parentCharacter.MyEventHandler.OnOneSecondTimer += UpdatePerSecond; PersonalThreatCritical = 1; PersonalThreatHigh = 0.6f; PersonalThreatLow = 0.3f; }
public void TestTroubleTicketwithDSL() { System.IO.Stream source = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.TroubleTicketWithDSL.drl"); System.IO.Stream dsl = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.ticketing.dsl"); PackageBuilder builder = new PackageBuilder(); builder.AddPackageFromDrl(source, dsl); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(builder.GetPackage()); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); Customer a = new Customer("A", "Gold"); Customer b = new Customer("B", "Platinum"); Customer c = new Customer("C", "Silver"); Customer d = new Customer("D", "Silver"); Ticket t1 = new Ticket(a); Ticket t2 = new Ticket(b); Ticket t3 = new Ticket(c); Ticket t4 = new Ticket(d); FactHandle fa = workingMemory.assertObject(a); FactHandle fb = workingMemory.assertObject(b); FactHandle fc = workingMemory.assertObject(c); FactHandle fd = workingMemory.assertObject(d); FactHandle ft1 = workingMemory.assertObject(t1); FactHandle ft2 = workingMemory.assertObject(t2); FactHandle ft3 = workingMemory.assertObject(t3); FactHandle ft4 = workingMemory.assertObject(t4); workingMemory.fireAllRules(); t3.Status = "Done"; workingMemory.modifyObject(ft3, t3); try { System.Console.Error.WriteLine("[[ Sleeping 5 seconds ]]"); System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5000)); } catch (System.Threading.ThreadInterruptedException e) { //SupportClass.WriteStackTrace(e, Console.Error); } workingMemory.fireAllRules(); //logger.writeToDisk(); }
public void SetWorkingMemory(WorkingMemory workingMemory) { this.workingMemory = workingMemory; this.workingMemory.ItemInserted -= new EventHandler(ThreadSafeShowMemory); // Just in case... (should not be needed). this.workingMemory.ItemInserted += new EventHandler(ThreadSafeShowMemory); this.workingMemory.ItemDeleted -= new EventHandler(ThreadSafeShowMemory); this.workingMemory.ItemDeleted += new EventHandler(ThreadSafeShowMemory); this.workingMemory.CurrentContextChanged -= new EventHandler(ThreadSafeShowContextID); this.workingMemory.CurrentContextChanged += new EventHandler(ThreadSafeShowContextID); this.workingMemory.CurrentIDChanged -= new EventHandler(ThreadSafeShowContextID); this.workingMemory.CurrentIDChanged += new EventHandler(ThreadSafeShowContextID); }
/// <summary> /// </summary> public override void retractLeft(Index linx, Rete engine, WorkingMemory mem) { Map leftmem = (Map)mem.getBetaLeftMemory(this); int prev = leftmem.size(); if (leftmem.containsKey(linx)) { // the memory contains the key, so we retract and propogate leftmem.remove(linx); } if (prev != 0 && leftmem.size() == 0) { propogateRetract(linx, engine, mem); } }
void Awake() { //WORKING MEMORY wMemory = new WorkingMemory(); subsystemFacts = new List <string>(); blackBoard = BlackBoard.Instance; agentNumber = System.Guid.NewGuid(); showClanGUI(); showPlan = false; }
public virtual void testFourThousandLoad() { try { System.String file = "4000_rules_type1.drl"; long loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; RuleBase ruleBase = readRule(file); long loadEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; System.Console.Out.WriteLine("time to load " + file + " " + (loadEnd - loadStart) + "ms"); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); } catch (System.Exception e) { // SupportClass.WriteStackTrace(e, Console.Error); } }
public void TestBLoadRuleBase() { RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); FileStream fstream = new FileStream("HelloworldRuleBase.rlb", FileMode.Open); ruleBase.Load(fstream); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); //go ! Message message = new Message(); message.message = "Hello World"; message.status = Message.HELLO; workingMemory.assertObject(message); workingMemory.fireAllRules(); }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID); _currentWorldStates = new List <GoapWorldState>(); _parentCharacter.MyEventHandler.OnCurrentActionComplete -= OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnPerFrameTimer -= PerFrameUpdate; _parentCharacter.MyEventHandler.OnPerFrameTimer += PerFrameUpdate; //update parent character for each action foreach (GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } //BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f); //BlackBoard.PatrolRange = new Vector3(30, 10, 15); if (ControlType != AIControlType.Player) { BlackBoard.GuardLevel = 1; _parentCharacter.SendCommand(CharacterCommands.SetAlert); } _currentGoal = null; _currentAction = null; _parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer; }
public void TestBLoadPkg() { //AppDomain.CurrentDomain.Load("tempAssembly.dll"); FileStream stream = new FileStream("TroubleticketRuleBase.rlb", FileMode.Open); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.Load(stream); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); Customer a = new Customer("A", "Gold"); Customer b = new Customer("B", "Platinum"); Customer c = new Customer("C", "Silver"); Customer d = new Customer("D", "Silver"); Ticket t1 = new Ticket(a); Ticket t2 = new Ticket(b); Ticket t3 = new Ticket(c); Ticket t4 = new Ticket(d); FactHandle fa = workingMemory.assertObject(a); FactHandle fb = workingMemory.assertObject(b); FactHandle fc = workingMemory.assertObject(c); FactHandle fd = workingMemory.assertObject(d); FactHandle ft1 = workingMemory.assertObject(t1); FactHandle ft2 = workingMemory.assertObject(t2); FactHandle ft3 = workingMemory.assertObject(t3); FactHandle ft4 = workingMemory.assertObject(t4); workingMemory.fireAllRules(); t3.Status = "Done"; workingMemory.modifyObject(ft3, t3); try { System.Console.Error.WriteLine("[[ Sleeping 5 seconds ]]"); System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5000)); } catch (System.Threading.ThreadInterruptedException e) { //SupportClass.WriteStackTrace(e, Console.Error); } System.Console.Error.WriteLine("[[ awake ]]"); }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID); _currentWorldStates = new List<GoapWorldState>(); _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnPerFrameTimer += PerFrameUpdate; //update parent character for each action foreach(GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } //BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f); //BlackBoard.PatrolRange = new Vector3(30, 10, 15); if(ControlType != AIControlType.Player) { BlackBoard.GuardLevel = 1; _parentCharacter.SendCommand(CharacterCommands.SetAlert); } _currentGoal = null; _currentAction = null; _parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer; }
public void Execute(WorkingMemory workingMemory, List <Rule> rules) { if (workingMemory == null) { throw new InvalidWorkingMemoryException(); } var facts = workingMemory.Facts; foreach (var rule in rules) { foreach (var action in rule.Actions) { action.Execute(facts); } } }
static void TestRules(RuleBase ruleBase, CustomerRecord workingObj) { if (workingMemory == null) { workingMemory = ruleBase.NewWorkingMemory(); } if (_currentCust == null) { _currentCust = workingMemory.assertObject(workingObj); } else { workingMemory.modifyObject(_currentCust, workingObj); } workingMemory.fireAllRules(); }
public void TestWaltzBenchmark() { System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark.waltz.waltz.drl"); PackageBuilder builder = new PackageBuilder(); builder.AddPackageFromDrl(stream); Package pkg = builder.GetPackage(); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); //this.loadLines( workingMemory, "waltz12.dat" ); Stage stage = new Stage(Stage.START); workingMemory.assertObject(stage); workingMemory.fireAllRules(); }
public void TestBLoadAndChangeSavedState() { FileStream fstream = new FileStream("StateDynamic.rlb", FileMode.Open); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.Load(fstream); fstream.Close(); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); State a = new State("A"); State b = new State("B"); State c = new State("C"); State d = new State("D"); State e = new State("E"); // By setting dynamic to TRUE, Drools will use JavaBean // PropertyChangeListeners so you don't have to call modifyObject(). //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" bool dynamic = true; workingMemory.assertObject(a, dynamic); workingMemory.assertObject(b, dynamic); workingMemory.assertObject(c, dynamic); workingMemory.assertObject(d, dynamic); workingMemory.assertObject(e, dynamic); workingMemory.fireAllRules(); Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.StateExampleDynamicRule.drl"); PackageBuilder builder = new PackageBuilder(); builder.AddPackageFromDrl(stream); Package pkg = builder.GetPackage(); ruleBase.AddPackage(pkg); fstream = new FileStream("StateDynamic.rlb", FileMode.Create); ruleBase.Save(fstream); stream.Close(); fstream.Close(); }
public void TestHelloWorldExample() { PackageBuilder builder = new PackageBuilder(); System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.HelloWorld.drl"); builder.AddPackageFromDrl("HelloWorld.drl", stream); Package pkg = builder.GetPackage(); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); //go ! Message message = new Message(); message.message = "Hello World"; message.status = Message.HELLO; workingMemory.assertObject(message); workingMemory.fireAllRules(); }
/// <summary> Assert will first pass the facts to the parameters. Once the /// parameters are set, it should call execute to get the result. /// </summary> public override void assertLeft(Index linx, Rete engine, WorkingMemory mem) { Map leftmem = (Map)mem.getBetaLeftMemory(this); if (!leftmem.containsKey(linx)) { Parameters = linx.Facts; ReturnVector rv = func.executeFunction(engine, params_Renamed); if (!rv.firstReturnValue().BooleanValue) { BetaMemory bmem = new BetaMemoryImpl(linx); leftmem.put(bmem.Index, bmem); } // only propogate if left memories count is zero if (leftmem.size() == 0) { propogateAssert(linx, engine, mem); } } }
/* * Method executed when event in MemoryChanged * Checks if there is any message needed to be sent to the InternetDataAcquisitionApplication */ private void HandleWorkingMemoryChanged2(object sender, EventArgs e) { MemoryItem idaItem = WorkingMemory.GetLastItemByTag(MemoryItemTags.InternetDataAcquisitionProcess); if (idaItem != null) { //Only go further if idaItem is a response (both IDA requests and responses share the same MemoryItemTag) string idaItemType = idaItem.Content.Split('*')[0]; //Keep timeOfLast... search requests and portfolio requests separate if (idaItemType.Equals("requestSearch")) // Filter on search requests { if (idaItem.CreationDateTime > timeOfLastIDASearchOutput) // To avoid incorrectly repeating a previous output { //get the IDA process ID string clientID = Server.GetFirstClientID(ProcessTagValues.InternetDataAcquisitionProcess); if (clientID != null) { //Send the content of idaItem to IDAProcess Server.Send(clientID, idaItem.Content); } timeOfLastIDASearchOutput = idaItem.CreationDateTime; } } if (idaItemType.Equals("requestPortfolio")) // Filter on search requests { if (idaItem.CreationDateTime > timeOfLastIDAPortfolioOutput) // To avoid incorrectly repeating a previous output { //get the IDA process ID string clientID = Server.GetFirstClientID(ProcessTagValues.InternetDataAcquisitionProcess); if (clientID != null) { //Send the content of idaItem to IDAProcess Server.Send(clientID, idaItem.Content); } timeOfLastIDAPortfolioOutput = idaItem.CreationDateTime; } } } }
public void TestFibonacciExample() { System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.Fibonacci.drl"); PackageBuilder builder = new PackageBuilder(); builder.AddPackageFromDrl(stream); Package pkg = builder.GetPackage(); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); // By setting dynamic to TRUE, Drools will use JavaBean // PropertyChangeListeners so you don't have to call modifyObject(). //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" bool dynamic = false; workingMemory.assertObject(new Fibonacci(50), dynamic); workingMemory.fireAllRules(); }
public List <int> ComputeOpcodes(int?noun = null, int?verb = null, int[] programInputs = null, bool resetComputer = true) { bool programEnded = false; int instructionLength; int ptr; if (resetComputer) { ResetToInitialMemory(); Output = new List <int>(); ptr = 0; } else { ptr = LastPointer; } if (noun != null) { WorkingMemory[1] = (int)noun; } if (verb != null) { WorkingMemory[2] = (int)verb; } while (!programEnded) { int opcodeInput = WorkingMemory[ptr]; List <OpcodeParameterMode> modes = new List <OpcodeParameterMode>(); Opcode opcode; //Console.WriteLine($"{Environment.NewLine}-- INSTRUCTION --"); //Console.WriteLine($"opcodeInput: {opcodeInput}"); // Handle <=2 digit input if (opcodeInput <= 99) { opcode = (Opcode)opcodeInput; } // Handle longer input as string else { List <string> operands = ParseOperands(opcodeInput); opcode = (Opcode)int.Parse(operands[0]); foreach (char m in operands[1].ToCharArray()) { modes.Add((OpcodeParameterMode)int.Parse(m.ToString())); } //Console.WriteLine($"Opcode: {opcode} | Operands: {operands[1]}"); } List <int> instruction = new List <int>(); //Console.WriteLine($"Modes:"); //Console.WriteLine(modes.Count > 0 ? string.Join(",", modes) : "none"); switch (opcode) { case Opcode.Halt: instructionLength = 1; OnProgramHalted?.Invoke(this, EventArgs.Empty); programEnded = true; break; case Opcode.Add: instructionLength = 4; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int add1, add2, addLocationToUpdate; if (modes.Count == 0) { add1 = WorkingMemory[instruction[1]]; add2 = WorkingMemory[instruction[2]]; addLocationToUpdate = instruction[3]; } else { List <int> values = new List <int>(); modes.Reverse(); for (int m = 0; m < modes.Count; m++) { OpcodeParameterMode mode = modes[m]; switch (mode) { case OpcodeParameterMode.Position: values.Add(WorkingMemory[instruction[m + 1]]); break; case OpcodeParameterMode.Value: values.Add(instruction[m + 1]); break; case OpcodeParameterMode.Relative: values.Add(WorkingMemory[instruction[m + 1] + RelativeBase]); break; default: throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[m]}' is not valid."); } } //Console.WriteLine("Values:"); //Console.WriteLine(string.Join(",", values)); add1 = values[0]; add2 = values[1]; addLocationToUpdate = instruction[3]; } WorkingMemory[addLocationToUpdate] = add1 + add2; //Console.WriteLine($"{opcode}: Memory location {addLocationToUpdate} updated to {WorkingMemory[addLocationToUpdate]}"); break; case Opcode.Multiply: instructionLength = 4; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int mult1, mult2, multLocationToUpdate; if (modes.Count == 0) { mult1 = WorkingMemory[instruction[1]]; mult2 = WorkingMemory[instruction[2]]; multLocationToUpdate = instruction[3]; } else { List <int> values = new List <int>(); modes.Reverse(); for (int m = 0; m < modes.Count; m++) { OpcodeParameterMode mode = modes[m]; switch (mode) { case OpcodeParameterMode.Position: values.Add(WorkingMemory[instruction[m + 1]]); break; case OpcodeParameterMode.Value: values.Add(instruction[m + 1]); break; case OpcodeParameterMode.Relative: values.Add(WorkingMemory[instruction[m + 1] + RelativeBase]); break; default: throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[m]}' is not valid."); } } //Console.WriteLine("Values:"); //Console.WriteLine(string.Join(",", values)); mult1 = values[0]; mult2 = values[1]; multLocationToUpdate = instruction[3]; } WorkingMemory[multLocationToUpdate] = mult1 * mult2; //Console.WriteLine($"{opcode}: Memory location {multLocationToUpdate} updated to {WorkingMemory[multLocationToUpdate]}"); break; case Opcode.Input: instructionLength = 2; int locationToUpdate = WorkingMemory[ptr + 1]; if (programInputs != null && programInputs.Length > 0) { WorkingMemory[locationToUpdate] = programInputs[0]; // Remove the input after use programInputs = programInputs.Skip(1).Take(programInputs.Length - 1).ToArray(); } else { //Console.WriteLine("Computer awaiting input"); instructionLength = 0; programEnded = true; } //Console.WriteLine($"Get instruction updated location {locationToUpdate} to {WorkingMemory[locationToUpdate]}"); break; case Opcode.Output: instructionLength = 2; int outputParam = WorkingMemory[ptr + 1]; int outputValue; if (modes.Count == 0) { outputValue = WorkingMemory[outputParam]; } else { modes.Reverse(); switch (modes[0]) { case OpcodeParameterMode.Position: outputValue = WorkingMemory[outputParam]; break; case OpcodeParameterMode.Value: outputValue = outputParam; break; case OpcodeParameterMode.Relative: outputValue = WorkingMemory[outputParam + RelativeBase]; break; default: throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } //Console.WriteLine($"{opcode}: outputIndex: {outputParam} | outputValue: {outputValue}"); Output.Add(outputValue); break; case Opcode.JumpIfTrue: instructionLength = 3; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int jumpIfTrueParam1, jumpIfTrueParam2; if (modes.Count == 0) { jumpIfTrueParam1 = WorkingMemory[instruction[1]]; jumpIfTrueParam2 = WorkingMemory[instruction[2]]; } else { modes.Reverse(); if (modes[0] == OpcodeParameterMode.Position) { jumpIfTrueParam1 = WorkingMemory[instruction[1]]; } else if (modes[0] == OpcodeParameterMode.Value) { jumpIfTrueParam1 = instruction[1]; } else if (modes[0] == OpcodeParameterMode.Relative) { jumpIfTrueParam1 = WorkingMemory[instruction[1] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } if (modes[1] == OpcodeParameterMode.Position) { jumpIfTrueParam2 = WorkingMemory[instruction[2]]; } else if (modes[1] == OpcodeParameterMode.Value) { jumpIfTrueParam2 = instruction[2]; } else if (modes[1] == OpcodeParameterMode.Relative) { jumpIfTrueParam2 = WorkingMemory[instruction[2] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } if (jumpIfTrueParam1 != 0) { ptr = jumpIfTrueParam2; instructionLength = 0; } //Console.WriteLine($"{opcode}: Param1: {jumpIfTrueParam1} | Param2: {jumpIfTrueParam2} | Pointer: {ptr}"); break; case Opcode.JumpIfFalse: instructionLength = 3; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int jumpIfFalseParam1, jumpIfFalseParam2; if (modes.Count == 0) { jumpIfFalseParam1 = WorkingMemory[instruction[1]]; jumpIfFalseParam2 = WorkingMemory[instruction[2]]; } else { modes.Reverse(); if (modes[0] == OpcodeParameterMode.Position) { jumpIfFalseParam1 = WorkingMemory[instruction[1]]; } else if (modes[0] == OpcodeParameterMode.Value) { jumpIfFalseParam1 = instruction[1]; } else if (modes[0] == OpcodeParameterMode.Relative) { jumpIfFalseParam1 = WorkingMemory[instruction[1] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } if (modes[1] == OpcodeParameterMode.Position) { jumpIfFalseParam2 = WorkingMemory[instruction[2]]; } else if (modes[1] == OpcodeParameterMode.Value) { jumpIfFalseParam2 = instruction[2]; } else if (modes[1] == OpcodeParameterMode.Relative) { jumpIfFalseParam2 = WorkingMemory[instruction[2] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } if (jumpIfFalseParam1 == 0) { ptr = jumpIfFalseParam2; instructionLength = 0; } //Console.WriteLine($"{opcode}: Param1: {jumpIfFalseParam1} | Param2: {jumpIfFalseParam2} | Pointer: {ptr}"); break; case Opcode.LessThan: instructionLength = 4; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int lessThanParam1, lessThanParam2; if (modes.Count == 0) { lessThanParam1 = WorkingMemory[instruction[1]]; lessThanParam2 = WorkingMemory[instruction[2]]; } else { modes.Reverse(); if (modes[0] == OpcodeParameterMode.Position) { lessThanParam1 = WorkingMemory[instruction[1]]; } else if (modes[0] == OpcodeParameterMode.Value) { lessThanParam1 = instruction[1]; } else if (modes[0] == OpcodeParameterMode.Relative) { lessThanParam1 = WorkingMemory[instruction[1] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } if (modes[1] == OpcodeParameterMode.Position) { lessThanParam2 = WorkingMemory[instruction[2]]; } else if (modes[1] == OpcodeParameterMode.Value) { lessThanParam2 = instruction[2]; } else if (modes[1] == OpcodeParameterMode.Relative) { lessThanParam2 = WorkingMemory[instruction[2] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } WorkingMemory[instruction[3]] = lessThanParam1 < lessThanParam2 ? 1 : 0; //Console.WriteLine($"{opcode}: Param1: {lessThanParam1} | Param2: {lessThanParam2} | Location updated: {instruction[3]}"); break; case Opcode.Equals: instructionLength = 4; instruction = WorkingMemory.GetRange(ptr, instructionLength); //Console.WriteLine("Instruction:"); //Console.WriteLine(string.Join(",", instruction)); int equalsParam1, equalsParam2; if (modes.Count == 0) { equalsParam1 = WorkingMemory[instruction[1]]; equalsParam2 = WorkingMemory[instruction[2]]; } else { modes.Reverse(); if (modes[0] == OpcodeParameterMode.Position) { equalsParam1 = WorkingMemory[instruction[1]]; } else if (modes[0] == OpcodeParameterMode.Value) { equalsParam1 = instruction[1]; } else if (modes[0] == OpcodeParameterMode.Relative) { equalsParam1 = WorkingMemory[instruction[1] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } if (modes[1] == OpcodeParameterMode.Position) { equalsParam2 = WorkingMemory[instruction[2]]; } else if (modes[1] == OpcodeParameterMode.Value) { equalsParam2 = instruction[2]; } else if (modes[1] == OpcodeParameterMode.Relative) { equalsParam2 = WorkingMemory[instruction[2] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } WorkingMemory[instruction[3]] = equalsParam1 == equalsParam2 ? 1 : 0; //Console.WriteLine($"{opcode}: Param1: {equalsParam1} | Param2: {equalsParam2} | Location updated: {instruction[3]}"); break; case Opcode.OffsetRelativeBase: instructionLength = 2; instruction = WorkingMemory.GetRange(ptr, instructionLength); int offsetRelativeBaseParam1; if (modes.Count == 0) { offsetRelativeBaseParam1 = WorkingMemory[instruction[1]]; } else { modes.Reverse(); if (modes[0] == OpcodeParameterMode.Position) { offsetRelativeBaseParam1 = WorkingMemory[instruction[1]]; } else if (modes[0] == OpcodeParameterMode.Value) { offsetRelativeBaseParam1 = instruction[1]; } else if (modes[0] == OpcodeParameterMode.Relative) { offsetRelativeBaseParam1 = WorkingMemory[instruction[1] + RelativeBase]; } else { throw new InvalidOperationException($"OpcodeParameterMode ID '{modes[0]}' is not valid."); } } RelativeBase += offsetRelativeBaseParam1; break; default: throw new InvalidOperationException($"Operation # {(int)opcode} is not a valid Opcode."); } ptr += instructionLength; LastPointer = ptr; } return(WorkingMemory); }
public TestSession() { WorkingMemory = new WorkingMemory(ContextSetup.LoggerFactory); }
public Builder WithWorkingMemory(WorkingMemory workingMemory) { _engine.SetWorkingMemory(workingMemory); return this; }
public void SetWorkingMemory(WorkingMemory workingMemory) { if (workingMemory == null) throw new ArgumentException("Working memory should not be null."); _workingMemory = workingMemory; }
private string clan; //The clan that the agent belongs to void Awake() { wMemory = new WorkingMemory(); subsystemFacts = new List <string>(); agentNumber = System.Guid.NewGuid(); }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.ID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.ID); _currentWorldStates = new List<GoapWorldState>(); _parentCharacter.MyEventHandler.OnNewEnemyTargetFound += OnImportantEvent; _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; //update parent character for each action foreach(GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } BlackBoard.PatrolLoc = new Vector3(-15, 0, -15); BlackBoard.PatrolRange = new Vector3(20, 10, 20); BlackBoard.HasPatrolInfo = true; if(ControlType != AIControlType.Player) { _currentGoal = null; _currentAction = null; FindAndExecuteAction(); } }
public WorkingMemoryTests() { _workingMemory = new WorkingMemory.Builder().Build(); }
public RuleMatcherServiceTests() { _workingMemory = GenerateWorkingMemory(); _ruleBase = GenerateRuleBase(); _matcher = new RuleMatcherService(); }
void Awake() { wMemory = new WorkingMemory(); subsystemFacts = new List<string>(); agentNumber = System.Guid.NewGuid(); }
public void Dispose() { _workingMemory = GenerateWorkingMemory(); _ruleBase = GenerateRuleBase(); _matcher = new RuleMatcherService(); }
/// <summary> retract right is a dummy, so it does nothing. /// </summary> public override void retractRight(Fact rfact, Rete engine, WorkingMemory mem) { }
void Awake() { //WORKING MEMORY wMemory = new WorkingMemory(); subsystemFacts = new List<string>(); blackBoard = BlackBoard.Instance; agentNumber = System.Guid.NewGuid(); showClanGUI(); showPlan = false; }
public bool Equals(WorkingMemory list) { if (!IsUsed) { bool returned = false; foreach (var item in list) { returned = DependsFact.Equals(item); if (returned) return returned; } } return false; }
/// <summary> clear the memory /// </summary> public override void clear(WorkingMemory mem) { ((Map)mem.getBetaLeftMemory(this)).clear(); }
/// <summary> clear the memory /// </summary> public override void clear(WorkingMemory mem) { ((Map) mem.getBetaLeftMemory(this)).clear(); }
public void Dispose() { _workingMemory = new WorkingMemory.Builder().Build(); }
/// <summary> /// </summary> public override void retractLeft(Index linx, Rete engine, WorkingMemory mem) { Map leftmem = (Map) mem.getBetaLeftMemory(this); int prev = leftmem.size(); if (leftmem.containsKey(linx)) { // the memory contains the key, so we retract and propogate leftmem.remove(linx); } if (prev != 0 && leftmem.size() == 0) { propogateRetract(linx, engine, mem); } }
/// <summary> Assert will first pass the facts to the parameters. Once the /// parameters are set, it should call execute to get the result. /// </summary> public override void assertLeft(Index linx, Rete engine, WorkingMemory mem) { Map leftmem = (Map) mem.getBetaLeftMemory(this); if (!leftmem.containsKey(linx)) { Parameters = linx.Facts; ReturnVector rv = func.executeFunction(engine, params_Renamed); if (!rv.firstReturnValue().BooleanValue) { BetaMemory bmem = new BetaMemoryImpl(linx); leftmem.put(bmem.Index, bmem); } // only propogate if left memories count is zero if (leftmem.size() == 0) { propogateAssert(linx, engine, mem); } } }
private void Awake() { _workingMemory = GetComponent <WorkingMemory>(); _navManager = GetComponent <NavigationManager>(); ai = GetComponent <RichAI>(); }