This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-12-26 22:00:50

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

How To Make An AI?

please help!


http://i.imgur.com/I1DuR.png

Offline

 

#2 2007-12-26 22:04:33

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How To Make An AI?

Artificial intelligence can vary a lot depending on what it's used for. What exactly do you need the AI to do?

Last edited by archmage (2007-12-26 22:06:15)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2007-12-27 12:21:00

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Re: How To Make An AI?

i want it to be like a second player, such as shooting and moving according to the movements of the human player.


http://i.imgur.com/I1DuR.png

Offline

 

#4 2007-12-27 12:25:54

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How To Make An AI?

Some actions (like turning to face the human player or shooting at regular intervals) are trivial to program.  Others (like finding its way through a maze) are more difficult.  Still others (like choosing good moves in chess) are beyond the capability of scratch programming.  You have to be *very* specific about what you want your AI to do.  You can often fake intelligence in computer games, having very simple programs (sometimes with a bit of randomness) looking like challenging opponents.

Offline

 

#5 2008-01-08 15:44:14

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How To Make An AI?

Well I would reccomend archmages topic on how to make your cpu attack, And if he did not post it, look at the scripts of Merry Smashmas


http://i.imgur.com/WBkM2QQ.png

Offline

 

#6 2008-01-09 10:14:25

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How To Make An AI?

You'll need to divulge more about the game you want to build to get specific advice.  Are there obstacles the AI sprite must avoid?  Areas that it shouldn't go to?

One simple approach that you'll see a lot is "point toward" (player's sprite) and move.  This makes for a predictable enemy, but is easy to do and works well.  If you remember "Asteroids Deluxe", the enemy ships that resulted from hitting a "cluster" behaved that way.  Mixed in with the asteroids, and other enemies that were more or less "random", this was pretty cool, but if nothing else was going on it would have been boring.

The AI in "StealthFighter" http://scratch.mit.edu/projects/EdnaC/33613 (a game with two airplanes shooting missiles at each other), had to be more along the lines of "what would I do?" to look realistic.  If the enemy plane always turned toward you, it would be predictable and easy to "shoot down".  So the question becomes, "how do I make the enemy appear to act intelligently with as few rules as possible?"   If you examine what the "Stealth" plane does in one player mode, you'll find something like:

If the other plane is in front of me (within some range), turn toward it.
If the other plane is close and in front (within a narrower range), shoot at it.
If the other plane is right behind me (within some range of angles) and far away, turn toward it.
If the other plane is close and behind me, do something random to try to get away.
If the other plane shoots, do something random.
Otherwise, fly straight.

This isn't really "intelligent", and doesn't always result in the best strategy, but it looks like the other plane is being pretty smart, and "looks" is what counts.  ("Looks is what counts" is good advice in general when it comes to games, the "physics" doesn't need to be correct either, it just has to "look" right.)  So, to finally attempt an answer: When "designing" AI, think about how a human player might act in the various situations that might arise, and define rules accordingly.  You don't want "AI" that is unbeatable, and you don't want "AI" that is totally predictable, so a little bit of "Random" mixed in when the "situation" doesn't have a clear cut "rule" is a good idea too.

-MrEd

Offline

 

Board footer