Menu

Integrating into Unity Engine and Some Enquiries

Help
2015-09-23
2015-10-11
  • Jason RT Bond

    Jason RT Bond - 2015-09-23

    So I'm looking to run a Prolog interpreter within the Unity game engine for implementing some AI logic. At first, I just want to be able to have a "story script" (text game data, not C#) include some reasonably-concise but powerful code logic for guiding how game characters behave, and Prolog seemed like the perfect language for this. Going forward, I'm hoping to use it to do some more advanced modelling of knowledge and belief.

    So, what I'm really aiming for is a Prolog interpreter to which queries are made one at a time, often in the form of asserts. (I know this is usually bad form in Prolog, but in my case I'm modelling an ever-changing system, so asserts and retractions will be frequent.) Queries will be passed from and returned to C# scripts within the game engine based on the game's logic. That is, the user knows nothing of Prolog — they are just playing a game — but the game designer/writer has prepared Prolog code to guide the experience / model AI and the programmer has built game logic in C# which leverages that Prolog code to make decisions about the game world. Hope that makes a bit of sense :)

    Anyhoo, long story short, C#Prolog looks like a great fit for my purposes, and I would like to extend my thanks to you, John, for your efforts!

    Enquiries:

    1. For my purposes, I want the interpreter to be free of any its own file IO logic. That is, I'll wrap it within the file IO of my application and I really just want a "pure" interpreter in the form of queries (or consulted "files") passed as strings. So far, I've hit one specific issue with ApplicationStorage using file IO methods which throw security exceptions on some platforms — that happens on creating the PrologEngine in the first place. I've got things working with generous line-commenting (could be pre-processor statements), but as you can probably imagine this gets ugly quickly and would make integrating any future updates to C#Prolog really difficult.
      I know this is a bit of a broad issue, but do you have any general advice on how I can "prune" such file IO elements from C#Prolog while keeping it easy to sync with your most recent changes?

    2. On a similar note, some of the nice "extras" have dependencies which aren't available in my version of Mono (such as System.Data for the SQL features). Do you have any advice on how to cleanly remove those extras from my project?

    3. Does C#Prolog start any threads of its own which need to be cleaned up? (Hoping not, as I'd like to just use it within a thread of my own managing.)

    4. Do you have advice on having many instances of the Prolog database in memory?
      Somewhat complex background:
      My application uses a graph of states similar to many AI Planning applications (directed, acyclic graph) to model a dynamic system in discrete steps. That is, we begin in one state and explore several possible following states, each of which may have several other following states, and so on. With each change of state some facts and rules may be added or deleted (thus each state is a somewhat changed database of facts and rules than the preceding one). I don't need Prolog to have any awareness of the graph itself — rather I just want to use it to make queries about a given state. If it means anything to you, I'm essentially using Prolog in much the same way one uses PDDL to model a state within a planning domain, with the key benefit being Prolog's ability to do somewhat sophisticated reasoning over a given set of facts and rules.
      Anyway, the key thing is that I want to have many instances of the Prolog database of facts and rules, easily copyable into new instances (so I can have these different "states" which give different query results). I'm aware this is beyond normal usage of Prolog, but it makes sense for my case, and has implications for how I manage the interpreter itself.
      So, can I easily make cloned copies of the current database? What's the overhead look like? Do I need multiple PrologEngine instances or is there another way? Really, any thoughts you could offer would be appreciated.

     

    Last edit: Jason RT Bond 2015-09-23
  • Jason RT Bond

    Jason RT Bond - 2015-09-25

    For what it's worth, with some generous commenting out of incompatible sections (mainly filesystem/security related), I've got CSP running in a Unity project showing some basic queries and working correctly on Mac/Win, iOS and HTML5/WebGL!

    It's very ugly how I got there, but really encouraging to see it across all these platforms. THIS is why I wanted a Mono-based interpreter :)

     
    • John Pool

      John Pool - 2015-10-11

      Hello Jason,

      Sorry for the delay in answering, I just returned from a two-weeks holiday in Spain. I will look into your posts and do my best to give you a reply this week.

      Regards, John

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.