Author Topic: Ai Scripting  (Read 7629 times)

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« on: February 23, 2006, 04:03:10 PM »
As i'm getting closer to the "general AI" idea, i will need a simple scripting language, that anyone can learn within a couple minutes.


Things like CreateUnit can be copied almost unchanged, since that is pretty self-explanitory, but the other things like AI settings may need some thought. I won't go into too much detail yet about what the AI can do, and how it does it,but i'm open to suggestions as to how the general format for such a scripting language should be. Remember, it's probebly upto us, coders to explain stuff and help along the coding n00bs, so the easier it is to explain (and understand), the better.

I found that things like the very first BASIC V1.0 was very simple, and can be taught to child in less then an hour. A C- or Pascal-style is too difficult to explain in a quick, and i do not want to write a complex compiler for it either.

The basic outline of the scripting language will be a simple (cmdLine) version of MSVC++ that takes 1 (or more) script files and 1 or more DLLs as input, and creates a mission DLL as an output. The mission DLL then runs without any outside help from other files. That way a user-created (multiplayer) mission cannot be altered too easily and prevent cheating in this manner (and saved me from writing cheat-checking code); remember: OP2 only checks the DLLs of the participating machines, but not any miscellanious files.


Code: [Select]
# I prefer the #-sign as a remark line, rather then // or;

BEGIN  InitProc
# to keep it simple, i think we should use BEGIN...END blocks, so ANYone can understand them
# also, CaSe should not matter, like in pascal or basic
  CReaTeUnit ( 1, 1, mapLynx, mapLaser )

# of course the in-script coordinates will NOT be offset with (31,-1)
END

Any more ideas are welcome !
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #1 on: February 24, 2006, 01:32:36 PM »
I've created an example AI Script file. Comments anyone ?
Quote


# ----------------------------
# == Example AI SCRIPT file ==
# ----------------------------


# ------------------
# Set mission params
# ------------------

SET PLAYERS=4
SET MAP="eden04.map"
SET MAXTECHLEVEL=12
SET STARTTECH=2



# ---------------------
# Create mining beacons
# ---------------------

COMMON BEACON ( 40, 18, 2BAR, variant1)
COMMON BEACON ( 19, 44, 2BAR, variant3)

RARE BEACON ( 36, 31, 3bar, Variant2)



# ---------------
# Create AI bases
# ---------------

# This is player one's base
# The CONNECT keyword connects the building to the CC

BEGIN FIXED BASE 1

   UNIT (CommandCenter,   52, 6)
   UNIT (StructureFactory,52,12, agridome, residence) CONNECT
   UNIT (CommonSmelter,   46,12) CONNECT
   UNIT (MINE,             40,18)
   UNIT (tokamak,         56, 3)

   UNIT (convec,     48,10)
   UNIT (cargotruck,42,15)
   UNIT (cargotruck,44,16)

END

# This is player two's base

BEGIN FIXED BASE 2

   UNIT (CommandCenter,   23,54)
   UNIT (StructureFactory,28,54) CONNECT
   UNIT (CommonSmelter,   23,48) CONNECT
   UNIT (MINE,             19,44)
   UNIT (tokamak,         16,60)

   UNIT (convec,     28,60, agridome)
   UNIT (cargotruck,19,47)
   UNIT (cargotruck,20,49)

END


PS: 2 spaces in a [ quote ] block are translated into 2 &nbsp pairs with a space inbetween... sorry
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Ai Scripting
« Reply #2 on: February 25, 2006, 04:39:28 AM »
The quote box is emtpy. I see nothing but gray. Even selection doesn't make it visible. Because I don't have the Courier font.
« Last Edit: February 25, 2006, 04:51:23 AM by TH300 »

Offline zigzagjoe

  • Hero Member
  • *****
  • Posts: 626
Ai Scripting
« Reply #3 on: February 25, 2006, 01:29:14 PM »
the course of action there seems failry obvious...? here: http://zigzagjoe.no-ip.com/fontz

quoted text: {

# ----------------------------
# == Example AI SCRIPT file ==
# ----------------------------


# ------------------
# Set mission params
# ------------------

SET PLAYERS=4
SET MAP="eden04.map"
SET MAXTECHLEVEL=12
SET STARTTECH=2



# ---------------------
# Create mining beacons
# ---------------------

COMMON BEACON ( 40, 18, 2BAR, variant1)
COMMON BEACON ( 19, 44, 2BAR, variant3)

RARE BEACON ( 36, 31, 3bar, Variant2)



# ---------------
# Create AI bases
# ---------------

# This is player one's base
# The CONNECT keyword connects the building to the CC

BEGIN FIXED BASE 1

  UNIT (CommandCenter,  52, 6)
  UNIT (StructureFactory,52,12, agridome, residence) CONNECT
  UNIT (CommonSmelter,  46,12) CONNECT
  UNIT (MINE,            40,18)
  UNIT (tokamak,        56, 3)

  UNIT (convec,    48,10)
  UNIT (cargotruck,42,15)
  UNIT (cargotruck,44,16)

END

# This is player two's base

BEGIN FIXED BASE 2

  UNIT (CommandCenter,  23,54)
  UNIT (StructureFactory,28,54) CONNECT
  UNIT (CommonSmelter,  23,48) CONNECT
  UNIT (MINE,            19,44)
  UNIT (tokamak,        16,60)

  UNIT (convec,    28,60, agridome)
  UNIT (cargotruck,19,47)
  UNIT (cargotruck,20,49)

END

hmm, perhaps ya could support both # and // /* */ styles? i rather like the later

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #4 on: February 25, 2006, 02:33:57 PM »
I will see what i can do
there's a standard for now, so i can at least CREATE remarks -- later on i can add more commands etc..

I've started an editor tool that combines both a simple text-editor (kinda like notepad) and the commandline version of Microsoft's C++ (coz that's free to download & use)
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Ai Scripting
« Reply #5 on: February 25, 2006, 03:16:22 PM »
thanks, zzj. I had that font, whereas I shouldn't have it.
Deleted it and everything displays fine.

Linux can sometimes be weird^^

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai Scripting
« Reply #6 on: February 27, 2006, 08:07:33 AM »
I think it might serve well to remove the need for parentheses, etc. This makes the language semantics a lot easier to learn (especially for beginners). For example:
Code: [Select]
Unit Mine, 19, 44

I think of QBasic, since it's extremely easy to learn.

And yes, it would be nice to allow // /* */ commenting styles.

As for your parser, how do you plan for that to work? By attaching some sort of overlay or metadata onto the end of a pre made DLL? or by generating some sort of C++ source and then compiling and linking it?

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #7 on: February 27, 2006, 05:08:34 PM »
I've worked out a prelimenary editor for the scripts. it will include an editor and some preparation for the cmdLine msvc compiler.
Play with it, if you like.

It may be best to leave out the parentheses.. i'm trying to make this scripting language as easy as possible, but it does need to have a syntax, so the scripter can read it, and point out errors.  I've alrerady decided i should change BEACON COMMON blabla into COMMON BEACON. It's an extra step to overcome for the compiler (cache the first word, and check the second), but it makes more sence that way to noobs.


[edit]  RAR download removed
« Last Edit: March 02, 2006, 11:24:59 AM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline zigzagjoe

  • Hero Member
  • *****
  • Posts: 626
Ai Scripting
« Reply #8 on: February 27, 2006, 09:14:30 PM »
http://outpostuniverse.net/~zzj/codin/vct...vc6-min-cmp.zip

a small ver of the compiler a while ago i made that has the minimum required to compile a op2 dll. it also has a sample build script-- look at readme for details

also in that dir is the last ver of my complete cmdline compiling system for op2sdk.


all this is for devs ONLY.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #9 on: February 28, 2006, 04:37:59 AM »
I slightly changed the example code. Either # or // can be used for remarks now.

Code: [Select]
# ----------------------------
# == Example AI SCRIPT file ==
# ----------------------------


SET NAME="Example"


# ------------------
# Set mission params
# ------------------

SET PLAYERS=4
SET MAP="eden04.map"
SET MAXTECHLEVEL=12
SET STARTTECH=2


# ---------------------
# Create mining beacons
# ---------------------

COMMON BEACON 40, 18, 2BAR, variant1
COMMON BEACON 19, 44, 2BAR, variant3

RARE BEACON   36, 31, 3bar, Variant2


# ---------------
# Create AI bases
# ---------------

# This is player one's base
# The CONNECT keyword connects the building to the CC

BEGIN FIXED BASE 1

   UNIT CommandCenter,   52, 6
   CONNECT UNIT StructureFactory,52,12, agridome, residence
   CONNECT UNIT CommonOreSmelter,46,12
   UNIT MINE,            40,18
   UNIT tokamak,         56, 3

   UNIT convec,    48,10
   UNIT cargotruck,42,15
   UNIT cargotruck,44,16

END

# This is player two's base

BEGIN FIXED BASE 2

   UNIT CommandCenter,   23,54
   CONNECT UNIT StructureFactory,28,54
   CONNECT UNIT CommonOreSmelter,23,48
   UNIT MINE,            19,44
   UNIT tokamak,         16,60

   UNIT convec,    28,60, agridome
   UNIT cargotruck,19,47
   UNIT cargotruck,20,49

END

 
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Ai Scripting
« Reply #10 on: March 02, 2006, 11:01:28 AM »
Nice work, looking good and simple to do :)

Offline instigator

  • Jr. Member
  • **
  • Posts: 89
Ai Scripting
« Reply #11 on: March 02, 2006, 11:29:26 AM »
Ok i want links files and tutorials. Example code for maps how to edit them. what is that about placing a cc and factory? how do you get the tubes to auto connect. yeah well im n00b but give me enough stuff so that can indepandanly work and mess around for awhile without asking tons of questions. you want to design an AI? i better start with rare or placement lol. whenever i do something i suck royally but over time i get better than the rest (never you though eddy b :P). i want some stuff!!! but sadly i only have weekends to work on it. but hey thats at least 30 hours... hehe

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #12 on: March 05, 2006, 05:38:43 PM »
I've added some of the compiling code today.
Last couple days i been working on a replacement for the syntax-view that i use now, but this new one is just as flawd as the one i have now.. but i'll make it work, without the flicker problems.

I've stuck to the example displayed above, and i can compile only a small part of it at this moment. The compiler is capable of reading in the lines and sorting out numbers, strings and property names.
Next step will be to translate the script source to a c++ source, that tyhe c-compiler can read.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #13 on: March 08, 2006, 06:19:55 AM »
I've successfully tested the first script interpreting.
My example script, although slightly modified, compiled into what looks like a c-source that will compile. I've already added over 2 dozen error messages to the compiler, but i know there's bound to be scripting problems that will not generate the correct error, but will give an exception. Once the project goes into beta, i expect you n00bs & pro-coders to find me the bugs in the system, and have fun with it.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #14 on: March 11, 2006, 06:06:04 AM »
For those of you that want to test the program: go ahead: http://www.eddy-b.com/AI-Scripter
Please post if you find a bug that hasn't been posted yet.

[EDIT]  yesterday (march 12th) i added some more properties to the editor. it's syntax highlighter should work properly now.
[EDIT2] removed INI download. The new zip has the default INI included.
« Last Edit: March 14, 2006, 04:16:42 PM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Jgamer

  • Full Member
  • ***
  • Posts: 159
Ai Scripting
« Reply #15 on: March 13, 2006, 11:13:33 AM »
Hum... Look, Eddy, I don't have much to say yet but as of now I have two things:

First: I suggest that you start right now with a 'syntax manual' showing what exactly each command does. It's vital

Second: I still think that Beacon Common is better than Common Beacon, but that must be only me

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #16 on: March 13, 2006, 01:15:23 PM »
Quote
Hum... Look, Eddy, I don't have much to say yet but as of now I have two things:

First: I suggest that you start right now with a 'syntax manual' showing what exactly each command does. It's vital

I'm planning to, Jgamer. I've already created a quickhelp file: you will find this along with the downloaded zip: it's a 1-liner help, that shows when you focus on a scripting error and press F1.
Quote
Second: I still think that Beacon Common is better than Common Beacon, but that must be only me
It's only a minor adjustment.. i'll add both, like i did with the comments

And for those that like having options: i've added 3 possible ways to enter a Boolean:
YES/NO, TRUE/FALSE or 1/0 (the numbers one/zero, that is).

Also, i've included a fully customizable version of the syntax-highlighter. It includes enabling/disabling of linenumbers, right 'edge' line, and extended home-key (the way MSVC uses it), as well as complete user-defineable highlighting schema. It does not (yet) include search-capabilities, but it will in the future, as soon as i've worked out something that satisfies me.


My first concern now, is to have it compile into a real C++ source/header combi, that i can feed into the C++ compiler. After that i can have it compile the entire script into a dll in one go, so the only thing a scripter would have to do is press <Compile> to have a working OP2 mission.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #17 on: March 17, 2006, 03:04:14 PM »
I've started the documentation Jgamer was talking about. It can be found on the wiki. It includes the syntax documentation, as well as some explaining of the errors it can produce.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Ai Scripting
« Reply #18 on: March 20, 2006, 06:17:19 PM »
If its not too late for further suggestions...
the parameter lists of some functions are long and probably hard to remember. Why not change it to somethin like
Code: [Select]
UNIT agridome AT 15,32
or probably
Code: [Select]
create UNIT=structurefactory LOCATION=15,32 CARGO=Agridome,CommandCenter,residence

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #19 on: March 21, 2006, 04:23:42 AM »
Quote
If its not too late for further suggestions...
the parameter lists of some functions are long and probably hard to remember. Why not change it to somethin like
Code: [Select]
UNIT agridome AT 15,32
consider it done
Quote
or probably
Code: [Select]
create UNIT=structurefactory LOCATION=15,32 CARGO=Agridome,CommandCenter,residence
hmm.. i have to think about this.
The goal is to make the script simple. A simple 'AT' doesn't add much confusion, but creates unncessary long lines.  is there anyone who will second the motion ? :P
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai Scripting
« Reply #20 on: March 21, 2006, 07:40:16 AM »
The second form makes more sense, from a programming point of view.

However, if you want it to be really human readable, why not encode the key=value pairs into the sentence?

for example:
Code: [Select]
Create unit CargoTruck at 20,30 with cargo CommonMetals with rotation 0 with lights on.

Create player 1 with 2000 common with 1000 rare with 10 scientists with 10 workers with 10 kids with 1 satellite.

Or perhaps something a bit like
Code: [Select]
Create player 1 with common=2000, rare=1000, scientists=10, workers=10, kids=10, satellites=1.

Even allow the period at the end if the user wants. I think that would make the scripting language the most no-nonsense to someone who hasn't touched a programming language at all.

Oh and as for making a script language parser in its entirety, have you looked at the programs flex and bison (you might have used similar tools lex and yacc in the 80s)?

Offline Jgamer

  • Full Member
  • ***
  • Posts: 159
Ai Scripting
« Reply #21 on: March 21, 2006, 10:11:27 AM »
Actually, and AT or CARGO might even be useful to avoid confusion, but we can't oveexceed ourselves too much.
Small and probably useless suggestion but... Ever considered using a system similar to Mysql for the sentences? Where the ; decided where the sentece ends and if there is a return it simply keeps adding what's beyond it to the command line?

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai Scripting
« Reply #22 on: March 21, 2006, 06:39:09 PM »
That makes sense for us coders but could probably confuse new people, who will forget to put the end-of-line character (or worse, not know what it's for).

Perhaps have a line continuation character, like the C preprocessor has:

Code: [Select]
#define MyIncrediblyLongMacro somethinghere \
a = b; \
a++; \
b--;

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Scripting
« Reply #23 on: March 22, 2006, 05:04:31 AM »
You want it to be even more confusing ??

WHY do you want to split up those commands ? most command lines have less then 40 chars, so far only a UNIT sf command, filled up with 6 kits is longer then that!

I agree with hacker's remark about the EOL-markers: the perfect EOL marker is a simple <CR/LF> combination (eg, the ENTER key).

This script language must be simple and easy to understand, but also be short and fast to "code", without having to type in extra, ignored, words
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Ai Scripting
« Reply #24 on: March 22, 2006, 02:15:43 PM »
Mcshay told me that you spelled volcano wrong in this.
Quote
[18:40] <Mcshay> is it volcano or vulcano?
[18:40] <Mcshay> the proper spelling that is
[18:40] <Sirbomber> Volcano.
[18:41] <Mcshay> eddy uses VULCANO in his scripter
« Last Edit: March 22, 2006, 02:15:56 PM by Sirbomber »
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials