Advertisement

I have a very simple 4X (For testing purposes)...Building a better AI

Started by September 03, 2009 10:08 PM
1 comment, last by TechnoGoth 15 years, 2 months ago
Programming language: C# Programming level: Advanced, but raw beginner for AI. The game contains three types of game entities; Empires, Stars and Spaceships. Empires: A newly-created Empire will call the ICombat.Cheat() method on a star, setting its .Team variable to the Empire's .Team variable and setting the Star's .Value to 4.0. When the Empire updates, it will check its stars for a Progress value of 45 or higher. If one is found, it will call .BuildSpaceship() on the star. It will also check for Spaceships without a Target. If one is found, it will iterate through the stars and call the Spaceship's .CheckTimeToIntercept() versus the Star. It will then target the Spaceship at the Star it can reach the fastest. Stars: Stars are created with a Value of 3.0 and a Progress of Value * 5.0. Each update, the Star's Progress will be incremented by its Value, per second. If .BuildSpaceship() is called, it will build a spaceship and reduce its Progress by /1.5. The resulting Spaceship will have a (Combat) Strength equal to the Star's Progress / 2. If attacked, its Progress will be reduced by the attack's Strength, relative to its Progress. If the resulting Progress is less than the attack's Strength, the attack succeeds and the Star joins the team passed to the .ReceiveAttack() method. Spaceships: A Spaceship will attempt to intercept its target, if any. If it collides with its target, it will check its target's ITeam.Team value and, if it's not the same as the Spaceships, it will call it's target's ICombat.ReceiveAttack() method. If it does attack, win or loose, the Spaceship is destroyed. Spaceships use pure newtonian movement, including acceleration and deceleration. Hence, the Star it can reach the quickest is not always the closest. I've read tutorials on AI, but theoretical knowledge is not practical knowledge. What would be the first steps in developing an AI for this game? My amateur guess is that a task-driven AI would work, but I don't know how to build that - I mean, I get the general idea, but implementation? In essence, I'm having trouble translating 'concept' to 'code'. That, and I'm not sure which concept to go with. Thanks for any and all help.
My approach would be to divide the AI into different parts:

1. Navigation:
Starsytems and plantes are prefectly suited for a simple waypoint system. Create a waypoint system from stars and planets and write a A* pathfinding algorithm to move a object from A to B.

2. Decision making:
You have to build a decision making mechanism. A simple finit state machine for your empire or a behaviour tree would suite this task. A decision making algorithm will determine what to do next. I.e. it checks neighbour planets and decide which of them to conquer. Once a decision has been made, create a new task.

3. Task chains and blackboard:
Tasks will be added to a blackboard. Your entities (empires,spaceships) will check the blackboard for tasks they can execute (a spaceship can attack, a factory can build new ships etc.). You can build up task chains, where you have to finish first one task to continue with the next one. Example:
First task from decision making: "attack star X"
To attack a star you need a fleet: "attack star X"->"need fleet"
If no fleet is avaiable, build new one: "attack star X"->"need fleet"->"build fleet".

4. Task execution:
Once a starship or fleet get a task to do, you need to execute it. This can be done similar to 2. , create a finit state machine or a behaviour tree to execute your task goal.

This is just a overview, you need to look up how to implement certain concepts like A*,blackboard AI, behaviour tree, decision making. An AI is often build up from different conecpts. Search on books.google for Ai Wisdom, you will find a book about ai development.

--
Ashaman
Advertisement
There are different techniques you could use depending on what you want to achieve.

It sounds like the basic mechanics of your game
- Stars grow by 5 points a turn.
- Once a star reaches optimal size pump out a strength 22.5 ship every 3 turns.
- Send ship to attack nearest star or intercept closest enemy ship.
- All Ships involved are destroyed at the end of combat.

Which would mean you would reduce any planet strength by 7.5 per attack including rebuild between attacks and take 18 turns to take down a size 45 planet.

Assuming I’ve understood your mechanics correctly. Then you just need to do a search after a ship is built and set its target to either the nearest planet or ship.

Although that won’t be particularly interesting as equal sized stars will be locked in a permanent stale mate, unless another star enters the battle.

You could expand things by including co-ordinated attacks and adding a planning and fitness function to evaluate plans to determine the optimal combination of stars to send to attack a target.

You could further expend that by adding different “strategies” such nearest, weakest, strongest by changing the dominate factor in the evaluation function.


This topic is closed to new replies.

Advertisement