SRL Archive - Research & Development Lounge

Simple AI


Imagine

2012-05-27 22:14:36

So I was bored and I decided to experiment, it's still in it's early stages at the moment, but it's a concept for simple, repeatable, actions. For now it can only decide between three different options. The number 6000, for now, is arbitrary, I just used it because it is divisible by a buncha stuff. I set the default as 3 options, you can edit it depending on how many options you have. Unfortunately, you can't have the script dynamically change it (or so I've heard).



Integers : Array of Integer;

procedure Choice(NumberOfChoices, Tries : Integer; Setup: Boolean);
var
LengthA, LengthB, LengthC, i, a, Placeholder, Percentage : Integer;
begin
if Setup then
begin
for i := 0 to NumberOfChoices do
Integers[i] := ((6000 * (i + 1))/NumberOfChoices)
end;

for i := 0 to NumberOfChoices do
IntegersT[i] := Integers[i];

LengthA := Integers[0] - 0;
LengthB := Integers[1] - Integers[0];
LengthC := Integers[2] - Integers[1];

for a := 0 to tries do
begin
case Random(Integers[NumberOfChoices]) of

0 .. Integers[0] : begin
if DoActionOne then // Pseudocode
begin
LengthA := LengthA * 1.5; //1.5 is arbitrary
Placeholder := 6000 - (LengthA);
Percentage := Placeholder/(LengthB + LengthC);
Integers[0] := 0 + (LengthA);
Integers[1] := Integers[0] + (Percentage * LengthB);
Integers[2] := Integers[1] + (Percentage * LengthC);
Break;
end else
Integers[0] := 0;
Placeholder := LengthB + LengthC;
Percentage := 6000/Placeholder;
Integers[1] := Percentage * LengthB;
Integers[2] := Percentage * LengthC;
end;

Integers[0] .. Integers[1] : begin
if DoActionTwo then // Pseudocode
begin
LengthB := LengthB*1.5;
Placeholder := 6000 - LengthB;
Percentage := Placeholder(LengthA + LengthC);
Integers[0] := LengthA * Percentage;
Integers[1] := LengthB + Integers[0];
Integers[2] := Integers[1] * (Percentage * LengthC);
Break;
end else
Placeholder := LengthA + LengthC;
Percentage := 6000/Placeholder;
Integers[0] := LengthA * Percentage;
Integers[1] := Integers[0] + 1;
Integers[2] := Integers[1] + (Percentage * LengthC)
end;
Integers[1] .. Integers[2] : begin
if DoActionThree then // Pseudocode
begin
LengthC := LengthC*1.5;
Placeholder := 6000 - LengthC;
Percentage := Placeholder(LengthA + LengthB);
Integers[0] := LengthA * Percentage;
Integers[1] := (LengthB * Percentage) + Integers[0];
Integers[2] := Integers[1] * (LengthC);
Break;
end else
Placeholder := LengthA + LengthB;
Percentage := 6000/Placeholder;
Integers[0] := LengthA * Percentage;
Integers[1] := Integers[0] + (Percentage* LengthB);
Integers[2] := Integers[1] + 1;
end;
end;
end;
end;

To call this function in a loop, you'd ideally call it once with the Setup as true, then for the remaining times in the loop, or until you relocated or something, you'd call it with the Setup as false.

Brandon

2012-05-27 22:17:16

I don't see any artificial intelligence there :S

Imagine

2012-05-27 22:41:33

From: Brandon
I don't see any artificial intelligence there :S




I'm saying like it'll edit the probability of doing certain things during runtime, so if something is successful, it'll be more likely to do it again the next time.
But as I said, it's very basic :P


EDIT: Ohh, I just saw your post time. I was still editing the post/finishing up the code when you posted :P, I wasn't nearly done.

Imagine

2012-05-31 15:14:18

Hmm, still have to work on what happens if the action is false, I'll do that momentarily.

Imagine

2012-06-04 19:05:09

Bump, updated it!

Imagine

2012-06-06 19:26:02

Nobody? :/

mezzo

2012-06-07 14:08:21

isn't it easier to start by building a simple state machine ?

Imagine

2012-06-07 21:07:19

What do you mean by a simple state machine?

superuser

2012-06-09 08:22:22

Finite state machine or even simple genetic algorithm is more effective and robust than this.

Imagine

2012-06-09 18:16:03

What do you guys mean by that?

Imagine

2012-06-09 22:22:45

And also, could you provide an example for a simple one, written in Pascalscript?