dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Artificial intelligence

  1. #1
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Ok guy's, im creating a new game, its well into the devlopment and ive got to the point where i need to add Artificial Intelligence to the Enemy, obviously this will highly revolve around random actions, but i was wondering whether anyone has any ideas about programming ai for a game, ive done basic ai before its not hard to program its just the theory that is hard to come across!

    To be honest i havent seen any good ai, so i wonder if anyone has?!?

    Does anyone have any thoughts on this subject?!

    You may or may not be wondering what sort of game this is, basically its a cannon fodder sort of game, one tank which you control from a sort of top-view but with a bit of perspective, the tank is controlled using the arrow keys on your keyboard, the tanks gun turret is controlled using your keyboard, rotate left, rotate right, space bar fires, the tank can accelerate, decelerate and reverse, the tank can also rotate on the spot!

    There are numersous obstacles, weapons, tanks and levels, the aim of the game is to wipe out your enemies tank by firing and hiding and chasing it!

    As i said there are numerous terrains which affect the tank in different ways(speed & friction)

    This game i hope will eventually be multiplayer via xml sockets(need to do some testing), now the part that im working on next is the enemy tank, this needs to be controlled with ai, it needs to move around, needs to fire when it has the chance, hide and run away from its enemy(us)

    This is where i come to you for ideas, theories etc. etc.. etc.. also if you have any ideas for new add-ons to the game then that would be great!

    The graphics side of things are being done by CNO from here on flashkit and markp too!!

    Thanks people and i hope this turns into a valuable thread!
    Come-on Mad-Sci and FlashCat show me what ur made of, it would also be nice to see ahabs side of things with him being the maths guru?!


    Cheers


    [Edited by FlashGuru on 12-30-2000 at 11:26 AM]

  2. #2
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    Here's a whole website about AI in games.. might be useful:

    http://www.gameai.com/

    The way I'd do it is a big bunch of "if's" like:
    if the enemy tank is behind the player tank -> fire!
    if the enemy tank is seriously damaged -> hide more
    if the enemy has a weapon with greater range than the player tank -> stay out of range, and fire!
    etc. etc.


    Sounds like it's gonna be a great game! Any previews yet?

    Olorin


  3. #3
    Senior Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    133
    Most AI is based upon weight or value of an action.

    Example: Basic Chess AI weight.

    Should computer Rook (25 points) take players queen, or knight?

    - Queen is worth 30 points
    - Knight is worth 10 points

    - Queen is guarded, computer would lose Rook.
    - Queen is now worth 5 points (30-25=5)

    Knight has the highest value, so computer will take the players knight.

    Hope this makes sense. The basic idea is each computer controlled tank would take the action that is has the greatest value.

    Rocketsnail Games
    http://www.rocketsnail.com/
    Try our MULTI-PLAYER Chat

  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Hey thats a good tip rsnail;-) so if i add up all points for each move and choose the best one swweeeeet

    Any more ideas?!

  5. #5
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    Uhmmm, I'd still take the queen !

    Olorin

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    133
    True. I guess the queen should be worth 100, and the king millions.

  7. #7
    ... problems4me's Avatar
    Join Date
    Jul 2000
    Location
    UK
    Posts
    658

    Hey... I want it!

    This sounds like a great game... if it go's multiplayer will you let me put it on my site? - I havn't got a clue about the AI... Anyway I need some other flash games as well... Any Ideas?

    Kieran - - Mr. 'Senior Member'

  8. #8
    Hi Flashguru.

    I programmed Santa fighter which can be found on this board and on the game section of Flash kit.

    With the evil Santa I used random numbers as you suggest, decreasing the range to make the enemies tougher.

    I am now working on a war game where your opponents need to chase you and shoot at you. However if you shoot back I need them to try and run away, hide, take a different course of action e.tc.

    Random numbers is still the way to go as I believe in reality we all make quick decisions in an intense moment which can either be proven to be right or wrong.

    This in mind I have programmed the enemy so that If he see's you firing he will either run away or decide he has a chance and try and kill you. This could lead to subroutines where if he runs away he may decide to grenade you because you are firing too much or he may decide to hide.

    I don't have any other conclusive ideas for 'ai', as computing decisions are only ones already explored. The best thing to do is give the computer at least two options for every move. This gives him the ability to explore several possibilities through subroutines.

    Hope this helps.

    Happy new year.

    Chris Murray.

    my santa game is at this address:-

    http://www.murrayanimations.co.uk/santafighter.htm

  9. #9
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hey Guru whats up man ? Ok down to buisness:

    1. building the map: build the map from tiles and use a look up table for each tile. like:
    coords[x][y]="some char here"; use 2D array to define the table. some char could be= 0- walk ,1-obstacle cant pass,m-mud slow the speed, etc etc.

    2. AI:
    ````-the enemie shots at you when it sees ya - 2 ways to do this. calculate the distance betweent the enemie and the tank, or create an "aura" arround the enemie tank ( circle MC with alpha=0 running hitTest()) when your tank is whitin this circle rotate the enemy acordingly and shoot a bulet.

    ''''- chasing: now this is a bit trickyA+)is the best.

    all tiles on the map you put in an array called OPEN, the ones which are not accesible ( char value 1 cant pass like rocks and stuff. ) put in array CLOSED. when you pick a direction of move. get the position of the hero tank and look in the OPEN array for the tile wich is next to you. ( up,down,left and right ) and move the enemye tank one tile, put the previous tile in the Closed list so you wont go back. and all tiles should have a cost. for example if you have to choose to walk on the ground or mud you should choose the ground which will have lowest cost )

    ''''- avoiding the hero tank - line of sight. if I can see you, you can see me. is the most simple one. if you have different type of tanks you can run a type of radar to tell the enemy what type your tank is. for example the enemie tank is light tank, yours is heavy armored the enemie should run away from ya ( not too stupid to atack ) he he he. but it will atack with 2 or 3 lights from different sites.

    Ok man hope this helps.

    Mad_sci
    [Edited by Mad-Sci on 01-01-2001 at 10:12 PM]

  10. #10
    Senior Member
    Join Date
    Feb 2000
    Posts
    226
    Im working on something different at the moment but with a similar sort of idea.

    What I did so far is create one enemy mc (with all the ai actions). Then, each mc individually gets a certain percentage. So basically they all do the same thing but at different speed etc, this makes the game more dynamic without using a lot of different code.

    Then as the game continues this percentage is increasing aswell so it gets more difficult.

    raoul

  11. #11
    Member
    Join Date
    Feb 2000
    Posts
    62
    I had a discussion with Mad_Sci a while ago about the AI routine in our Othello game:

    http://www.edesign.uk.com/flash/othello.html

    ...and I've had lots of other people interested in the routine we used for this game. It basically uses the ideas that rsnail mentioned but we use several methods to evealuate the positions. Anyway, following our discussion I decided to add a small chapter about AI into our latest book, which you can now order from Amazon.com and Amazon.co.uk - you can read about (and order) the book from here:

    http://www.edesign.uk.com/book.html


    JR


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center