Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using tuProlog for games  (Read 2414 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Devvie

Medals: 1

Java games rock!

« Posted 2009-11-04 21:18:20 »

I'm currently testing tuProlog as a scripting language and a simple relational database to use in games. In case someone is interested here's my impressions.

tuProlog is a Prolog interpreter created in 100% pure Java code. The official site is here: hosted by a research institute of an italian university. Last modification and download size is 2008-12-23 and 1.8M. The number of core files (excluding guis and extras) is around 80 classes. The documentation includes a pdf user guide (which i find very well written and complete) and the api documentation which is also very complete.

The scructure of the installation file

It's refreshing to find a product like this, that is well organized, has a complete manual and doesn't force you to read source code or hack through a disorganized wiki in order to know how to use it.

tuProlog can be run double clicking on it's jar file (using a MacOSX) and a gui application will start. With this i can browse a theory, manage loaded libraries, enter queries to solve goals and see the results. In Prolog the source is called a theory which is a list of clauses. Running a program is solving a query goal which is the main method. Loading a library is like loading a package. This gui also let's me run a prolog program step by step and manage the methods  (clauses) to spy (breakpoints). It's very sophisticated and user friendly for research stuff.

Let's see how it works for a basic method to find a member in a list.

The source:
member(X,[Y|R]) :- member(X,R).

Press the Set Theory button and the new theory is accepted. Now try to solve for the goal "member(1,[3,2,1])." by writing the text on the query field. The final dot is necessary. Press Enter and solution view shows:

Solution: member(1,[3,2,1])

Pressing the Next button shows there are no more solutions:

This programming language is a bit weird but i find it very useful to store game data and execute queries.

For example, i entered the following theory:


Notice we can mix structured data similar to XML with tabular data and still query information in the same maner.

Inventory can be understood as a table with a reference to the player actor. To know how if the player has any potions and what effect they have i used the query string "Id=player, actor(Id, name(N), _, _, _, _), inventory(Id, Q, item(potion, name(PN), effect(PE)))." and the result is:

Id / player  N / x  Q / 10  PN / potion_of_healing  PE / heal
Solution: ','('='(player,player),','(actor(player,name(x),str(10),int(10),agi(10),spd(10)),inventory(player,10,item(potion,name(potion_of_healing),effect(heal)))))

I didn't made any tests to performance but the idea i have is that this should be much slower than SQL and SQL would be much slower than using optimized data structures, but we can use Prolog just to store data textually and process it to an internal data structure like we would do with XML and XSLT.

Extending the language with libraries is easy and is very well explained in the manual. A library is a Java class that extends Library and provides methods that will be added as predicates, functors or directives to the theory. Libraries can be loaded and unloaded dynamically. The libraries provided are Basic, ISO, DCG, IO.

Using tuProlog directly as a scripting language for moders, even with a Prolog engine configured to use only builtin clauses, would not be safe. The alternative is to encode a scripting language in Prolog terms, validate scripts when loading and interpret them. It's very slow but it would give full control and safety options.


Resuming, my opinion is tuProlog may be a very good alternative to xml, xquery and xslt. As a scripting language for moding games it needs a lot of work to make it secure and efficient.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (73 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (78 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (110 views)
2015-10-18 23:29:12

DarkCart (135 views)
2015-10-16 00:58:11

KaiHH (117 views)
2015-10-11 14:10:14

KaiHH (157 views)
2015-10-11 13:26:18

BurntPizza (172 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!