Re: Artificial Intelligence
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.
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?
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:
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).
Re: Artificial Intelligence
I understand what you mean si, I shall try my hand at that, thank you :)
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:
If computer.villagers < ideal_villagers Then
CreateVillager
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.
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 :D
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.
Re: Artificial Intelligence
Ooh that sounds confusing, but extremely useful, so i'll give that a good go, thanks :D
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.