Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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 2021 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Devvie




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: http://www.alice.unibo.it/xwiki/bin/view/Tuprolog/ 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 2p-2.1.1.zip:
COPYRIGHT
CHANGELOG
doc
lib
LICENSE
src
test

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:
1  
2  
member(X,[X|R]).
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:

1  
2  
yes.
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:

1  
2  
3  
4  
inventory(player,1,item(shield,ac(5),price(100))).
inventory(player,10,item(gold)).
inventory(player,10,item(potion,name(potion_of_healing),effect(heal))).
actor(player,name(x),str(10),int(10),agi(10),spd(10)).


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:

1  
2  
3  
yes.
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.

1  
2  
3  
4  
5  
script(myscript_1,[
instruction(...),
instruction(...),
...
]).


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!