Results 1 to 11 of 11

Thread: Artificial Intelligence

  1. #1

    Thread Starter
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    Artificial Intelligence

    Hello again

    In the past few weeks i've been designing and creating a text based, turn based war strategy game in VB, and it seems to be going well! However there is one problem I have... Artificial Intelligence.

    The game consists of four civilizations, you control one and the computer controls the other three. I could easily make them do random things, but that wouldn't go down too well, for example they might never create military units or civilians, or advance an era. So that's out of the question. I could make them follow a set path, but that would take FAR too long, and after one game you'd know what they do, so that's out of the question too.

    What I want them to do is random things, but SENSIBLE, random things. For example, when they have X amount of civilians and X amount of resources, advance an era, when they have X amount of infantry units, launch an attack. You see what i'm getting at?

    Obviously coding an entire AI for a game like this would be a hell of a lot of work, but i'm all for work where VB is concerned, I may not be superb at this but i'm always willing to have a bash and will learn all I can.

    To make matters worse there are difficulty levels in the game. Four of them ranging from Rookie to Suicidal (In suicidal mode the computer is to get two turns for every one turn you have, I have an idea how I can do this though).

    Anyone with any experience with AI please help me. I would be VERY greatful for any help on this. Although this started out as a pass-time activity which I found enjoyable, I really would like to use this for my college project, however doubt I can finish it within 30 weeks without sufficient knowledge If all fails, I do have a sub-project lined up

    Once again, ANY help will greatly be appreciated

    Cheers,
    Rob
    Slow Cheetah come before my forest!
    Looks like it's on today.
    Slow Cheetah come, it's so euphoric!
    No matter what they say.



    If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".

    If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.

  2. #2

  3. #3
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Re: Artificial Intelligence

    All you need if a whole bunch of If..then statements with all the right conditions to be checked for. Make a function/method with something like:

    Code:
    If infantrySize > attackSize Then
         'choose the enemy and move all the infantry to that location and attack
         'Also, set a boolean flag to show that they are attacking (this could be used for many other things)
    
    Else If civilianSize > (certain amount) And resources > (certain amount) Then
         'advance to the next era, like allow new buildings/infantry stuff like that
    
    'Also for each of the eras, you need to do the same but change the amounts depending on the eras
    Any other sensible things can be handled with If...then statements, you just have to make sure the right conditions are met. Then once you are done with all of this, call this method/fucntion in the game loop so that every loop, it gets called. Or you could set up a separate timer just for this, and on the certain interval, call the function.

  4. #4

    Thread Starter
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    Re: Artificial Intelligence

    Ahh I get what you mean. That will take a very long time to make but it does seem logical. Thanks, that was very helpful Just one more thing though, what can I do to make the difficulty level harder? Is there any special kind of code that will do anything, or is it just things like the computer require less resources to advance an era and to create stuff?
    Slow Cheetah come before my forest!
    Looks like it's on today.
    Slow Cheetah come, it's so euphoric!
    No matter what they say.



    If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".

    If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Artificial Intelligence

    I would say that you are thinking slightly the wrong way.. not a major deal, but it either make the coding more complex or it would make the AI 'cheat'.

    What I would recommend is not to make things easy for the 'harder' AI player, but instead to make what fartman_900 suggested as 'good' as you can, then reduce the chances of things being done by the AI player according to the difficulty level.


    One way to do this would be to subtract a "random" number from the totals, eg:
    VB Code:
    1. If infantrySize - Int(rnd(0) * YourMultiplier) > attackSize Then
    The value for YourMultiplier would be small for the 'harder' player (possibly 3), and larger for the 'easier' player (possibly 20).

    I don't know how often this code would be run in your program, so the numbers here are just guesses - if the code is being run several times per second, you will probably want to make them quite a bit bigger (perhaps 50 and 1000 instead of 3 and 20).

  6. #6

    Thread Starter
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    Re: Artificial Intelligence

    I understand what you mean si, I shall try my hand at that, thank you
    Slow Cheetah come before my forest!
    Looks like it's on today.
    Slow Cheetah come, it's so euphoric!
    No matter what they say.



    If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".

    If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.

  7. #7
    Lively Member
    Join Date
    Oct 2004
    Posts
    91

    Re: Artificial Intelligence

    The easiest way to do this (not the fastest) is to take it one step at a time. Set a goal - such as make teh computer create 5 villagers and then gather resourses until you advance an era. Also, make sure you keep all the commands possible (like create villagers) in subroutines, so your final code on the AI would be readable and would look something like:

    VB Code:
    1. If computer.villagers < ideal_villagers Then
    2.    CreateVillager
    3. End If

    Finally, don't forget to use rnd and Randomize. Without them, the computer would end up doing hte same thing every time. Somehow you will need to randomize - whether it is the ideal amount of villagers or the aggresivness of the computer. But like i said, take it one step at a time and see what happens.

    Hint for suicidal ranking: let the computer cheat a little. Start it off with twice as many resources or something, this is the way most games like this code their hardest computer.

  8. #8

    Thread Starter
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    Re: Artificial Intelligence

    Thanks Josh, your method is totally understandable. If I combine the use of everything here i'm sure I can make this work wonders
    Slow Cheetah come before my forest!
    Looks like it's on today.
    Slow Cheetah come, it's so euphoric!
    No matter what they say.



    If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".

    If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.

  9. #9
    Member Shadow503's Avatar
    Join Date
    Apr 2006
    Posts
    37

    Re: Artificial Intelligence

    Also, one thing many other games have is something like a rules.ini file. In there it controls the constant values for different AIs.

    For example for each military unit there would be a number referring to the prority of the unit. The AI would look at all the units available to it. Then it would see of all the units currently available to it for its era which ones had the highest values for priority. It would then only build say the top 3. Heck, this number could be customizable so some AIs would only use the top 3 while an AI with a more diverse military would use the top 10.
    EG:
    Consript 3
    Helicopter 8
    Bomber 10
    Fighter 9
    Marine 7

    You could also customize things like at what size of an army will they start to attack other players. You could include a modifier based on how many players/other AIs it is already at war with.
    EG.
    If (Relative Military Strength / Enemy Relative Military Strength) - Modifier * CurrentEnemies > intAggrestion level Then
    Declare War
    End If

    Doing things like this allows you to create different personalities instead of simple difficulty levels. You could make the AI fight conservatively or be very aggressive.

    But what ever you do make sure you don't let your AI cheat. Nothing will anger your users more than figuring out your AI cheats to win. A good AI is smart enought for it to be a challenge without cheating. It should follow every rule the players have to follow. This includes making it so the AI cannot act on information it doesn't know. There's nothing I hate more in games than being cloaked and having the enemy AI fire at me.
    Last edited by Shadow503; Jun 27th, 2006 at 08:46 PM.

  10. #10

    Thread Starter
    Lively Member ThE_EnGinE's Avatar
    Join Date
    Jun 2006
    Location
    Liverpool, UK
    Posts
    87

    Re: Artificial Intelligence

    Ooh that sounds confusing, but extremely useful, so i'll give that a good go, thanks
    Slow Cheetah come before my forest!
    Looks like it's on today.
    Slow Cheetah come, it's so euphoric!
    No matter what they say.



    If you have the answer to your question. Click "Thread Tools" and then "Mark Thread Resolved".

    If you find a post useful. Rate it by clicking "Rate This Post" on the left of the post.

  11. #11
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: Artificial Intelligence

    I know hardly anything when it comes to VB and im trying to make my own Text Based Sports Game and i need A.I aswell but what ill do is use alot of random numbers.
    each player has a work rate and ball winning value in a database then i add all the ballwinning, work rate together and give percentages to each player. then a randomise a number will select who wins the ball.
    would this work Random Number Generator.

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