Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  script interpreter/compiler (custom language)  (Read 2866 times)
0 Members and 1 Guest are viewing this topic.
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Posted 2004-12-13 12:12:01 »

Hello,

I'm trying to do a custom language for AI scripting. This language will have a set of basic functions for detection and actions which are the exclusive entry points of my java AI engine, a simple expression evaluator for basic arithmetic/boolean operations and some control statements such as foreach and if/then/else.

I'm not trying to do java scripting at all but really a custom language.

So do you think there is already an existing free licence API that could help me doing this ?

thanks
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2004-12-13 12:47:04 »

There is a LUA version for java. And there's beanshell... and uhm... something else, I've forgotten.

However, I suggest you take a look at janino. It's java, it gets compiled(*) to byte code and it runs fast (it's the same like your usual java stuff). You can also (besides complete classes) compile single methods or just expressions. It's really awesome Smiley

(* Compilation is very fast.)

弾幕 ☆ @mahonnaiseblog
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #2 - Posted 2004-12-13 12:50:48 »

ok but I want to prevent user from using java and only allow the use of my custom language exclusively.

I already had a look at beanshell and janino but AFAIK they are compiling java, which I do not want to do.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #3 - Posted 2004-12-13 12:53:24 »

Then do a google for JLua and Groovy...They dont have java like syntax and are pretty powerful.

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #4 - Posted 2004-12-13 13:00:20 »

er no... That's not what I meant either.
:-/

What I'm looking for is a tool that helps me creating my own programming language and the interpreter or compiler that goes with. Like lex or yacc.
But I found an interresting pointer https://javacc.dev.java.net/
Someone knows it ?
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2004-12-13 13:58:39 »

JavaCC is one way, but what I think you're really looking for is something like the Rhino Javascript Engine. It allows you to produce "standard" JavaScript code, but using only the core libraries you specify. Since the core libraries can be in Java, you can expose your AI to the Javascript programmer.

Does that help, or were you looking for something more along the lines of a Rete-based Rules Engine?

Java Game Console Project
Last Journal Entry: 12/17/04
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #6 - Posted 2004-12-13 14:16:00 »

Quote
ok but I want to prevent user from using java and only allow the use of my custom language exclusively.

I already had a look at beanshell and janino but AFAIK they are compiling java, which I do not want to do.


beanshell has nothing to do with "compiling java" so I'm not sure what you're saying here.

It is quite easy to "prevent" your users from using java from within beanshell: you could try searching the mailing list archives, or asking on the list for help in doing this.

IIRC unless you explicitly "allow full access to everything everywhere" then people writing beanshell scripts only have access to things you make available to them AND the default things that get imported into java (java.lang.*). You might be able to disable access to java.lang.* using a security manager or some beanshell-specific feature. I know that a lot of people are interested in doing this with beanshell; I don't know how easy/successful it is.

However...WHY do you want to police access to java? You do realise that you will never prevent people from wiritng malicious code, e.g.:

while( true )
  ;

...so you need to put in introspection and stuff anyway, and once you're doing that why not just introspect for any java stuff you want to prevent access to?

Also, there's a lot of stuff you can disable in java by altering the security manager / security policy.

malloc will be first against the wall when the revolution comes...
Offline Tzan

Junior Member





« Reply #7 - Posted 2004-12-13 14:38:31 »

I havent looked at beanshell recently, but about 1.5 years ago I talked with the developer about limiting access to java specific stuff. He mentioned that he could add a feature where you could turn off access by package name. Since we never pursued beanshell, we didnt ask him to do it.

He may have added it on his own since then, or if not, I'm sure he would if you ask nice Smiley

Of course while(true) ; sure is mean.

You need to trust scripters a little or spend lots of time figuring out all the holes you left behind.
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #8 - Posted 2004-12-14 13:39:01 »

It's not that I don't trust scripters or whatever. I just do not want them to play too much with memory or cpu because that's not the purpose.
What I want is create a scripting language a bit like baldur's gate's.

This is exactly the kind of stuff I want them to write : (this is a draft of course)

** beginning of the ai script **
if (damageLevelOf(myself) > 80)
{
    moveTo(nearestBuilding(ally, repairSation))
    endScript
}

Unit lastAttacker=lastAttackerOf(myself)
if (lastAttacker)
{
   attack(lastAttacker)
   endScript
}

[ and so on... ]
** end of the ai script **
Offline KONI

Junior Member




Java games rock!


« Reply #9 - Posted 2004-12-15 20:10:33 »

If you're really interested, I have a complete course about writing a compiler:

1. lexical check (spelling mistakes)
2. syntax check
3. type and name check for var's and functions
4. produce the code

This is exactly what you need to do if you want to write your own small language and interpet it afterwards. Instead of producing code as does a compiler, you need to run the specific commands in your program.

ATTENTION: this is a course given in 3rd year university so if you don't want to really dig into this, then just forget what I've written.

If you're interested, the slides (they are in french but java code is pretty self-explanatory) document everything from start to end.

I also have a nearly-complete program running that takes a source code and generates a tree-structure. It has several visitor techniques to run through the tree and check for sth. You just need to write a new visitor and call the stuff you need to call.

Gimme a quick msg if you're interested.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #10 - Posted 2004-12-15 21:42:10 »

This is the best lex/yacc doc/tute I've seen.

You really need to have some backround in fsm's and language theory though.
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #11 - Posted 2004-12-16 05:22:12 »

Quote

This is exactly the kind of stuff I want them to write : (this is a draft of course)

** beginning of the ai script **
if (damageLevelOf(myself) > 80)
{
    moveTo(nearestBuilding(ally, repairSation))
    endScript
}

Unit lastAttacker=lastAttackerOf(myself)
if (lastAttacker)
{
   attack(lastAttacker)
   endScript
}

[ and so on... ]
** end of the ai script **


Hm, make them add a ';' at the end of each line and you compile it with a javac ?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #12 - Posted 2004-12-16 06:53:49 »

Quote
If you're really interested, I have a complete course about writing a compiler:

1. lexical check (spelling mistakes)
2. syntax check
3. type and name check for var's and functions
4. produce the code

This is exactly what you need to do if you want to write your own small language and interpet it afterwards. Instead of producing code as does a compiler, you need to run the specific commands in your program.


Yes that's what i figured out. I've got some background with that kind of stuff although I have not practiced since university.

Quote

ATTENTION: this is a course given in 3rd year university so if you don't want to really dig into this, then just forget what I've written.

If you're interested, the slides (they are in french but java code is pretty self-explanatory) document everything from start to end.

I also have a nearly-complete program running that takes a source code and generates a tree-structure. It has several visitor techniques to run through the tree and check for sth. You just need to write a new visitor and call the stuff you need to call.

Gimme a quick msg if you're interested.


Ok. I'll see if I need them. Thanks. And by the I'm french so it's ok.
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #13 - Posted 2004-12-16 07:00:42 »

Quote


Hm, make them add a ';' at the end of each line and you compile it with a javac ?


Using javac would also allow users to use the entire java language which implies that the ai scripts would not be lightweight anymore.
Since the kind of game I'm working on is a turn based strategy game and that each unit could have a customised ai script, you probably guess what would happen...
So I must keep users inside boundaries of lightweight.
Offline abies

Senior Member





« Reply #14 - Posted 2004-12-16 07:13:08 »

I think we will be able to help you more if you will exactly describe the roles in your game. Who is writing scripts, who is running them, who can be 'bad' and who is trusted, etc.

If person writing and running the script is the same, then two jvm solution might be possible. Run all dangerous scripts on one jvm and communicate with server/second jvm through remote calls (be it RMI or custom protocol). This may equal to running AI for units in client program instead on server for example. If you plan to run everything offline on server, then it might be also a solution - run jvm with minimal access rights, plus use some OS-specific tools to limit it's memory/CPU usage (and kill it after timeout for example).

Please describe your use cases in detail.

Artur Biesiadowski
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #15 - Posted 2004-12-16 07:47:17 »

Quote
I think we will be able to help you more if you will exactly describe the roles in your game. Who is writing scripts, who is running them, who can be 'bad' and who is trusted, etc.

[...]

Please describe your use cases in detail.


Ok here we go :

- end user will be able to use this language to make his own ai scripts
- this game is a turn based strategy game (standalone application) that will be playable offline but also through internet, the way warcraft can be played for instance.
- the scripts should not be too complicated since they will be used by many units (maybee 100 per player) and it's not a RPG so basic functions are : find enemy, attack one of them depending on some parameters, repair when too much damaged and so on...
- scripts should be editable in-game for ease of use/test. So no external tools should be used.
- ai is hierarchical



Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #16 - Posted 2004-12-16 10:02:57 »

Quote

Since the kind of game I'm working on is a turn based strategy game and that each unit could have a customised ai script, you probably guess what would happen...


Nope. Can't think of anything bad that would happen. What are you afraid of?

malloc will be first against the wall when the revolution comes...
Offline abies

Senior Member





« Reply #17 - Posted 2004-12-16 10:25:33 »

So all code will be written by you or by user and executed on user's computer ? Then I see no problem at all. You cannot stop people from shooting themselves in the leg - even if they won't be able to run out CPU/memory resources, they will program their units to make very stupid things.

Use on of existing scripting languages, create reasonable API to game, implement few macros to make programming easier and make sure that players cannot modify game internal resolution by scripts - and it will be ok.

Artur Biesiadowski
Offline KONI

Junior Member




Java games rock!


« Reply #18 - Posted 2004-12-17 08:03:14 »

Ok, here you go:

http://lamp.epfl.ch/teaching/compilation/2004/

In the slides we define a custom language called "EINS" (Eins is not Scala) based on the functional language SCALA.

On the site you will find the language grammar, the abstract grammar and the attributed grammar for name and type checking.

I'd start be defining the grammar of your language then implement the lexical check part. Then define the abstract grammar and construct the tree. Finally write 4 visitors, one for printing the tree, one for checking name, one for checking type and finally the last one for creating the executable script. (or make function calls in your case).

If you want a running project with the tree construction already implemented, I can send it to you.
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #19 - Posted 2004-12-17 09:28:29 »

ok merci Wink
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!