### Author Topic: Help for my AI  (Read 3602 times)

0 Members and 1 Guest are viewing this topic.

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #30 on: February 08, 2011, 07:13:03 PM »
I can't after all, cause of this little code:
Code: [Select]
if GetAsteroid(asteroids).owner == caiid then
GetAsteroid(asteroids):SetGraceTime(99999)
elseif GetAsteroid(asteroids).owner ~= caiid and GetAsteroid(asteroids).owner ~= 1 then
GetAsteroid(asteroids):SetGraceTime(0)
end

Which should work, but my AI is breaking the rules(planting flowers and sending seedling to places it shouldn't!) which indicates the normal AI is still somewhere in it's heart controlling it's brain like a virus(kinda wierd explanation, but that seems to be it...).

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 904
• Eufloria: Yes
##### Re: Help for my AI
« Reply #31 on: February 08, 2011, 08:27:28 PM »
Just stick Globals.AI.GraceTimer=(9999999) at the top of your LevelSetup. That should turn it completely off for all Empires.

If you want the default AI on for some empires (in the example below, it turns the default AI on for empires 2 and 3), then put this code in your LevelSetup
Code: [Select]
function LevelSetup()
-- roids and stuff created here

for i = 0, math.huge do
if GetAsteroid(i) == nil then
highroidID = i - 1
break
end
end

for i = 0,highroidID do
if GetAsteroid(i).owner == 2 or GetAsteroid(i).owner == 3 then
GetAsteroid(i):SetGraceTime(0)
else
GetAsteroid(i):SetGraceTime(9999999)
end
end

And this OUTSIDE of any other function. Just after LevelLogic is a good place, but I don't think it would have an effect whereever you put it.
Code: [Select]
OnAsteroidTaken(id, owner)
if GetAsteroid(id).owner == 2 or GetAsteroid(i).owner == 3 then
GetAsteroid(i):SetGraceTime(0)
else
GetAsteroid(i):SetGraceTime(99999)
end
end

Basically, that's a mashup of a few snippets I've learnt from Annikk and also a few I built myself. The LevelSetup block checks a potentially infinite list of asteroids, and as soon as it hits the end of the list, saves the highest ID of the asteroids. Then, it goes through the new, shorter list of asteroids and sets the GraceTimer to 0 (turns the default AI on) for that asteroid's owner - otherwise, it turns it off.

The second bit is called every time an asteroid is captured, and does the same thing as the second FOR loop in LevelSetup.

I think it works, but I haven't tested it.

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #32 on: February 08, 2011, 08:42:31 PM »
The AI works as expected, but the priority levels get incredibly high... I don't think it will damage the gameplay though

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #33 on: February 08, 2011, 08:44:43 PM »
Pilchard: I want all to be in one function, which it allready is, but sadly the code isn't working properly "GetAsteroid(roidnumber):SetGraceTime(float)" to be excact

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #34 on: February 08, 2011, 08:55:39 PM »
Got a picture form a little gameplay with(or against) my AI, ofcourse I didn't do much as I got amazed by my AI's behaviour

WARNING: The next picture is not predicting the future(not?)...

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Help for my AI
« Reply #35 on: February 08, 2011, 10:59:58 PM »
lol :>

Awesome dude!  Great job on this :>

It's so satisfying when you finally get something like this working.  It really is a great feeling.  :>
« Last Edit: February 08, 2011, 11:18:43 PM by annikk.exe »

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #36 on: February 09, 2011, 06:35:29 AM »
You know that AI ended up taking all the 50 roids (cept for mine, cause it can't attack properly yet...) and it ended up having 1300 seedlings flying around in a circle xD

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #37 on: February 09, 2011, 02:24:05 PM »
Ehhm... I have a question:

What is wrong with this code?

Code: [Select]
*CODES FTW*
elseif GetAsteroid(asteroids):AvailableStructureSpace() == true and attacked[asteroids] == false then
if GetAsteroid(asteroids).owner == caiid or GetAsteroid(asteroids).owner == 0 then
attacked[asteroids] = false
needtrees[asteroids] = true
needscouting[asteroids] = false
gatheringpoint[asteroids] = false
end
elseif *MORE CODE*
D:

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: Help for my AI
« Reply #38 on: February 09, 2011, 02:39:32 PM »
Code: [Select]
elseif GetAsteroid(asteroids):AvailableStructureSpace() == true and attacked[asteroids] == false then
Here is how I would recommend phrasing that:

Code: [Select]
elseif GetAsteroid(asteroids):GetNumTrees() < GetAsteroid(asteroids).TreeCap and attacked[asteroids] == false then

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #39 on: February 09, 2011, 05:30:02 PM »
fixed it

It will just rule any map now, but it lags with many roids D:

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Coloniser AI Engine (CUSTOM AI)
« Reply #40 on: February 09, 2011, 06:41:52 PM »

#### Bonobo

• Achiever
• Old Oak
• Thank You
• -Given: 79
• Posts: 630
• Was born, still alive.
• Eufloria: Yes
##### Re: Coloniser AI Engine (CUSTOM AI)
« Reply #41 on: February 09, 2011, 08:05:10 PM »
Tho it’s too late now … I’d recomment creating a new thread rather than perusing the first post of an existing thread for such … seeing that you also changed the text of the opening post.

Why? Because it disrupts the thread and may make (then good) replies to your initial text look silly, but certainly somewhat un-understandable. Also it may be harder for all interested pppl to find things … also discussion of your new code is harder for ppl starting to read this thread later.

Or do I err — and coders don’t care about such things? ;-)

Peace, Tom
(no coder ((yet) (but (as you can see,) (in my previous life) I have learnt some (very little) LISP (, among other languages)))) (You knew that LISP does NOT mean “Lots of Irritating Single Parentheses?) (OK, no new lines & indents, just for some fun)
« Last Edit: February 09, 2011, 08:59:39 PM by Bonobo »
Do you play Go? (aka iGo aka Baduk aka Weiqi)

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #42 on: February 09, 2011, 08:46:17 PM »
You're right, changed it back now

#### Bonobo

• Achiever
• Old Oak
• Thank You
• -Given: 79
• Posts: 630
• Was born, still alive.
• Eufloria: Yes
##### Re: Help for my AI
« Reply #43 on: February 09, 2011, 08:59:59 PM »
cool, thx
Do you play Go? (aka iGo aka Baduk aka Weiqi)

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
##### Re: Help for my AI
« Reply #44 on: February 10, 2011, 06:22:42 PM »
God, still having a problem with correcting the priorities x.x

Like this it should be:

303 -> 302 -> 301 -> 300 <- 301 etc...

But it acts more like this(1000 means idle, and it should set toa number right after ):

300 <- 301 <- 1000 <- 1000 -> 201 -> 200

WHY?!