Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Computer/enemy AI
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hackmaster




PostPosted: Fri Dec 08, 2006 8:46 pm   Post subject: Computer/enemy AI

Hey Guys...

I've got this RPG i'm working on... which you would know if you've read my other recent posts... But i'll re-iterate.

I am using classes for the Items and spells and such, and am having no trouble there. what's really got me hung up is enemy AI.

I have some really small experience with AI. I made a pong for class...(it's kind of the right of passage, now-a-days... it wasn't even a mid-term or a final) and I had various levels of difficulty. All I did was made a procedure that got the ball 100% of the time, and one that missed 100% of the time.
I just did a randint(var, 1, 100) to see which one it would call. something like this:

code:


var hitMiss: int

loop

randint(hitMiss, 1, 100)

if hitMiss =< 25 then

     Hit

else

     Miss

end if



that would be easy, medium would be less than or equal to 50, hard would be to 75, and super hard would be 95.

needless to say, it's not a great system. and now, if we talk about enemies in an rpg (which we are), you, at the higher levels, have to determine not only wheather they will attack or defend, but wheater they will use a spell, or just a plain attack, and if it's a spell, what spell... it just goes on and on. I'm sure that there is a better way then spinning like 5 loops with randints specific to the enemy.

this is made easier by objects (everything is) because I could just specify the percent it will succeed in the initializing proc, but is that the only way? anyone with AI experience, I would love your help with this. Thanks!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Dec 08, 2006 9:54 pm   Post subject: (No subject)

Heh, I think the AI will depend greatly upon the battle system you decide on.

I would advise trying to do it without random choices as much as possible. Try to make a formula to decide what to do, and only go to random when two options are equally probable.
ericfourfour




PostPosted: Sat Dec 09, 2006 11:15 pm   Post subject: (No subject)

You did mention objects so here is an idea...

I find that polymorphism really helps with AI. What I usually do is have a player class. The player has a deferred procedure called chooseAction (or something similar). Then I have a real player class and an artificial player class. The real player class then has a body procedure called chooseAction which lets the user choose the attack. The artificial player class has a body procedure called chooseAction which decides what action to use based on a series of conditions.

It would look a lot like this:
code:
class Player
    deferred proc chooseAction ()
end Player

class RealPlayer
    inherit Player

    body proc chooseAction
        put "Pick an action"
        ...
    end chooseAction
end RealPlayer

class ArtificialPlayer
    inherit Player

    body proc chooseAction
        if ...
    end chooseAction
end ArtificialPlayer


This way you could easily implement ai into your program. You could also derive more ArtificialPlayers if you want different ai.
Hackmaster




PostPosted: Sun Dec 10, 2006 9:35 am   Post subject: (No subject)

Yes, Eric, I agree with you.

Objects are the way to go here... but using just straight if statements in that situation can lead to problems... and a really, really big if statement tree. That is my defacto way to do it, I just posted this to see if someone knew a better way.

by the way, since you know about objects and such, tell me your opininon of my stat system:

everyone has certain stats, both computer and player. then, whenever someone would do something to change the other's (or their own) stats, they call a certain function within the other. I've made lots of statprocs, like this:

code:


class PlayerCharacter

import blah
export blah

%% stuff

proc change_HP(change : int)

HP := HP + change

end change_HP

end Player_Character



basically, I feed it a negative value if the enemy just attacked me, and a
positive one if I have just healed myself. this prcedure has a replica for all the stats, so I can make stat lowering/raising skills and such. what do you think?
ericfourfour




PostPosted: Sun Dec 10, 2006 1:27 pm   Post subject: (No subject)

What I like to do is have a stats class. Within that class you could keep all of the stat changing procedures. If ever you need more specialized stats you could just derive another class.

However, when dealing with HP (health) I usually have two separate functions. One called increaseHealth and one called decreaseHealth. The increaseHealth returns true when maximum health is reached while decreaseHealth returns true when minimum health is reached.

How it would look:
code:
class Stats
    export increaseHealth, decreaseHealth

    fcn increaseHealth (amount : int) : boolean
        health += amount
        if health > maxHealth then
            health := maxHealth
        end if
        result health = maxHealth
    end increaseHealth

    fcn decreaseHealth (amount : int) : boolean
        health -= amount
        if health < 0 then
            health := 0
        end if
        result health = 0
    end decreaseHealth

end Stats
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: