コード例 #1
0
        static void MyAgentEventCallback(sml.smlAgentEventId eventID, IntPtr callbackData, IntPtr kernelPtr, String agentName)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Kernel kernel = (sml.Kernel)((GCHandle)kernelPtr).Target ;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target ;

            // This callback returns the name of the agent as a string, to avoid having SWIG have to lookup the C# agent object
            // and pass that back.  We do something similar in Java for the same reasons.
            sml.Agent agent = kernel.GetAgent(agentName) ;

            if (agent == null)
                throw new Exception("Error looking up agent in callback") ;

            System.Console.Out.WriteLine(eventID + " agent " + agentName + " with user data " + userData) ;
        }
コード例 #2
0
ファイル: BlokusGUI.cs プロジェクト: sirctseb/Soar-Blokus
        //public delegate void UpdateEventCallback(smlUpdateEventId eventID, IntPtr callbackData, IntPtr kernel, smlRunFlags runFlags);
        public void HandleAgentOuput(sml.smlUpdateEventId eventID, IntPtr data, IntPtr kernel, sml.smlRunFlags runFlags)
        {
            // get stuff from output-link
            sml.Identifier moveCommand = agent.GetCommand("move");
            if (moveCommand != null)
            {
                // get placement info
                sml.Identifier placement = moveCommand.FindIDByAttribute("placement");
                if (placement != null)
                {
                    // iterate over squares
                    foreach (sml.Identifier squareID in placement.GetIDChildren("square"))
                    {
                        // get x,y from command
                        int x = (int)squareID.FindIntByAttribute("x");
                        int y = (int)squareID.FindIntByAttribute("y");

                        // color square in board view
                        ((Square)boardView[x, 19 - y].Value).color = BlokusColor.Blue;
                        boardView.InvalidateCell(x, 19 - y);

                        // put change in change list to send back to agent
                        changes[Tuple.Create(x, 19 - y)] = BlokusColor.Blue;
                    }

                    // clear output changes
                    agent.ClearOutputLinkChanges();
                    // mark command as complete
                    moveCommand.AddStatusComplete();
                    agent.Commit();
                }
                else
                {
                    Console.WriteLine("Error getting placement info: placement attribute DNE");
                }
            }
        }
コード例 #3
0
ファイル: SMLExtension.cs プロジェクト: sirctseb/SMLExtension
 public InvalidElementTypeException(string t, sml.WMElement el)
 {
     type = t;
     element = el;
 }
コード例 #4
0
ファイル: SMLExtension.cs プロジェクト: sirctseb/SMLExtension
 public AttributeNotFoundException(string attr, sml.Identifier el)
 {
     attribute = attr;
     element = el;
 }
コード例 #5
0
ファイル: SMLExtension.cs プロジェクト: sirctseb/SMLExtension
 // return a value at a path of member names held in the members array
 private static sml.WMElement GetChildAtAttributePathComponents(sml.Identifier element, string[] attributes)
 {
     // go through path and get children
     sml.Identifier current = element;
     foreach (string attribute in attributes.Take(attributes.Length - 1))
     {
         current = current.FindIDByAttribute(attribute);
         // if there was no Identifier found there, return null
         if (current == null)
         {
             return null;
         }
     }
     // get the last element
     return current.FindByAttribute(attributes.Last(),0);
 }
コード例 #6
0
        static void MyXMLEventCallback(sml.smlXMLEventId eventID, IntPtr callbackData, IntPtr agentPtr, IntPtr pXML)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Agent agent = (sml.Agent)((GCHandle)agentPtr).Target ;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target ;

            // Retrieve the xml object.  We don't own this object, so to keep it we'd need to copy it (or its contents).
            // This way when C# deallocated the object the underlying C++ object isn't deleted either (which is correct as the corresponding C++ code
            // doesn't pass ownership in the equivalent callback either).
            sml.ClientXML xml = (sml.ClientXML)((GCHandle)pXML).Target ;

            // Convert the XML to string form so we can look at it.
            String xmlString = xml.GenerateXMLString(true) ;

            String name = agent.GetAgentName() ;
            System.Console.Out.WriteLine(eventID + " agent " + name + " xml " + xmlString) ;
        }
コード例 #7
0
        static void MyUpdateEventCallback(sml.smlUpdateEventId eventID, IntPtr callbackData, IntPtr kernelPtr, smlRunFlags runFlags)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Kernel kernel = (sml.Kernel)((GCHandle)kernelPtr).Target ;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target ;

            System.Console.Out.WriteLine(eventID + " kernel " + kernel + " run flags " + runFlags + " with user data " + userData) ;
        }
コード例 #8
0
        static String MyTestRhsFunction(sml.smlRhsEventId eventID, IntPtr callbackData, IntPtr kernelPtr, String agentName, String functionName, String argument)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Kernel kernel = (sml.Kernel)((GCHandle)kernelPtr).Target ;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target ;

            // This callback returns the name of the agent as a string, to avoid having SWIG have to lookup the C# agent object
            // and pass that back.  We do something similar in Java for the same reasons.
            sml.Agent agent = kernel.GetAgent(agentName) ;

            if (agent == null)
                throw new Exception("Error looking up agent in callback") ;

            System.Console.Out.WriteLine(eventID + " agent " + agentName + " function " + functionName + " arg " + argument) ;

            // This is the result of the RHS function and can be placed into working memory as the result of the call
            // (whether this happens or not depends on how the RHS function is used in the production rule).
            return "result" ;
        }
コード例 #9
0
        static void MyRunEventCallback(sml.smlRunEventId eventID, IntPtr callbackData, IntPtr agentPtr, sml.smlPhase phase)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Agent agent = (sml.Agent)((GCHandle)agentPtr).Target ;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target ;

            String name = agent.GetAgentName() ;
            System.Console.Out.WriteLine(eventID + " agent " + name + " in phase " + phase + " with user data " + userData) ;
        }
コード例 #10
0
ファイル: Soar.cs プロジェクト: sleyzerzon/soar
        private void UpdateEventCallback(sml.smlUpdateEventId eventID, IntPtr callbackData, IntPtr kernelPtr, smlRunFlags runFlags)
        {
            // check for stop
            if (_stop)
            {
                _stop = false;
                OnLog("Soar: Update: Stopping all agents.");
                _kernel.StopAllAgents();
                return;
            }

            ProcessOutputLink();
            ProcessInputLink();

            // commit input link changes
            _agent.Commit();
        }