Jump to content
  • Advertisement
Sign in to follow this  
Orymus3

AI in a 4X Game Combat (see prototype video)

This topic is 2090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings fellow developers!
I'm currently in the process of building a 4X game, and I'd be in need of input in regards to the Combat Playback module.
 
Context
This module is named Combat Playback, because there is no user input during combat sequences. They are generated when a turn is processed on the backend-side, and returned to the player. The Combat Playback simply displays the outcome.
When I refer to Combat Playback in this post, I am referring to both the 'frontend display' and the 'backend logic' of the outcome.
 
Reference
Here's a Video that I've posted on youtube. It shows the progress that's been made towards building the Combat Playback prototype. Most of the rest of the game is already well underway, but the Combat Playback is, but an embryo at this stage.
 

[media]http:

[/media]
 

Design Questions
There's a number of questions that I'd like to raise here, and please don't feel limited by them to provide feedback (so long as you understand that this is early work, without any form of polish, and with a lot of missing assets).
 
As you can see in the fight, ships will automatically acquire a target. For the moment being, this target is always the 'nearest enemy ship'. This was made both because it's my first stab at this, but also because I don't want the AI to be something players rage about. If the 'wrong AI' kicks in, I feel players will get mad.
 
[hr]
Question # 1 - Should there be more AI types?
Specifically, should I have ships target the 'weakest', or retain their target until it is dead?
[hr]
Question # 2 - How should I choose which AI to bind to which ship?
Assuming there should be more than one AI type, how should I dictate which AI does what?
Here's a few options I've got right now:
 
A - Contextual: the ship tries to evaluate what should be done, and assigns
itself a 'role' in this battle.
Pros: This could lead to 'intelligent' decision-making
Cons: This could easily lead to verrrrryy dumb decision-making, and would require a lot more effort
 
B - Ship-centric: When choosing what ship to build in the game, it also states its 'AI pattern' (aka how the ship behaves)
Pros: Clean, easy, and recognizable by the player.
Cons: Very limitating, and some player choices could be considered 'bad' (not seeing that a ship attacks only the nearest ship and equipping long-range weaponry could lead to sad cornercases).
[hr] 
Question # 3 - How should the AI respond to 'being in firing range'
The prototype also assumes specific AIs for movement and attack. The basic AI right now is to move until one weapon is in range of the closest enemy, and fire (idle).
Each ship will be equipped with possibly more than one weapon, each with varying ranges.
I'm wondering how each ship should behave assuming that.
A few 'sketches' of what I thought could work well:

  • As long as a ship is not within range / is not the current target of any other ship, it will stop moving as soon as at least 1 weapon is in firing range. The idea here is that it allows 'artillery-type' ships to take full advantage of their attack range without moving closer and endanger themselves.
  • As soon as a ship is the target of another ship and in being fired at, it seeks to move as close as its 'shortest ranged' weapon. The idea is to have it perform its optimal amount of damage.
  • Once all of its weapons are in firing range, it assumes a 'circular orbit' around the target. The idea is to avoid fire from 'other' enemies that might want to acquire it as well and minimize the chances of 2v1s. It's also a good way to avoid what can be seen in the video: ships stopping to move for no apparent reason, which doesn't look very exciting.

[hr]
That's it for now. I'll add more if anything pops-up smile.png
 
Thanks!

Edited by Orymus3

Share this post


Link to post
Share on other sites
Advertisement

Is the end result of the combat decided using a simulation/calculations during the combat playback, or is the end result already defined before the replay begins?

Edited by mipmap

Share this post


Link to post
Share on other sites

I'm a big fan of auto ressolved combat (especially for 4x games). And I say that you are sweating over it way, way too much.

 

First, don't think in terms of AI but in terms of an algorithm. Combat mechanics doesn't really need an AI (OK, it does, but your mindset should work as if it didn't :D).

 

About annoyance due to poor AI (the key point). It's true poor AI is annyoying, BUT (and that's a big but with capital letters), it's annoying only if the AI is an option to replace players manual action (like pathfinding) or if it hinders the decision made by the player. In a situation when there are ships auto firing and auto moving and auto everything it's not annoying even if these are stupid. Because you don't "lose" anything. That's how the game is, the ships (admirals) are stupid and fire at each other in a stupid way. You can't affect it, it does not affect you in any "unfair" way (unlike if you send troops and they decide to go via middle of the swamps ignoring a road nearby, which would foil your plans as a player, since you expected something completely different). There is no connection between combat AI and player's options, therefore the player can't be annoyed.

 

 

How I would do it.

First I would just do random attacks, or something very simple like iterating through all enemies and fire at one with the highest chance to hit.

Next I would do moving at the "optimum firing range" (trivial to determine based on weapons available).

Next I would probably divide ships into 2 categories, standard and long range and make them behave differently (but only if the optimum firing range mechanic was not enough), mainly the long range ones should try to keep the distance.

 

Also, a controversial view, I would say that it's even BETTER if the AI is not perfect for auto combat. Like, would you want half of the ships blow up at the very beginning of the combat due to concentrated fire (since that's the optimal decision)? It's more "cinematic" if they exchange blows over time and let them blow "later".

 

Overall, the video you shown seems completely sufficient to me, I would keep it as it is.

Share this post


Link to post
Share on other sites

Is the end result of the combat decided using a simulation/calculations during the combat playback, or is the end result already defined before the replay begins?

 

The end-result is calculated backend-side as the turn is processed. Therefore, when the fight 'begins playback', the outcome is already determines. You could skip the playback if you want, but I'm hoping to use it as a means for players to learn more about what went wrong/right.

 


About annoyance due to poor AI (the key point). It's true poor AI is annyoying, BUT (and that's a big but with capital letters), it's annoying only if the AI is an option to replace players manual action (like pathfinding) or if it hinders the decision made by the player. In a situation when there are ships auto firing and auto moving and auto everything it's not annoying even if these are stupid. Because you don't "lose" anything. That's how the game is, the ships (admirals) are stupid and fire at each other in a stupid way. You can't affect it, it does not affect you in any "unfair" way (unlike if you send troops and they decide to go via middle of the swamps ignoring a road nearby, which would foil your plans as a player, since you expected something completely different). There is no connection between combat AI and player's options, therefore the player can't be annoyed.

 

So, in essence, the current implementation would be satisfactory pending these:

 


First I would just do random attacks, or something very simple like iterating through all enemies and fire at one with the highest chance to hit.

So instead of firing at the closest, try to fire at the weakest enemy that's currently in range? That'd work too.

 


Next I would do moving at the "optimum firing range" (trivial to determine based on weapons available).

What is the optimum range?

Let's assume I have a missile launcher with range 1000, a laser with range 500 and a cannon with range 300. Would I move all the way to ==300 distance from enemy?

 


Next I would probably divide ships into 2 categories, standard and long range and make them behave differently (but only if the optimum firing range mechanic was not enough), mainly the long range ones should try to keep the distance.

How exactly?

 


Also, a controversial view, I would say that it's even BETTER if the AI is not perfect for auto combat. Like, would you want half of the ships blow up at the very beginning of the combat due to concentrated fire (since that's the optimal decision)? It's more "cinematic" if they exchange blows over time and let them blow "later".

I tend to agree. This is one of the reasons I wanted ships to assume 'orbits'. The key idea here is that it would force ships to reconsider the AI: as ships continue moving, the target selection AI keeps re-evaluating and switching targets. Say, I'm a tanker, taking on another tanker head-on, but some skirmisher that is orbiting another ship just comes in range, I would probably divert my attention for a sec just to get an easy kill and reduce the overall firepower of my opponent.

 


Overall, the video you shown seems completely sufficient to me, I would keep it as it is.

So, you're ok with ships 'standing idle' facing one another? To me that feels very... dull to watch?

 

Thanks for the input.

Share this post


Link to post
Share on other sites

If the battle should be a "inspector" for the player to see what went right/wrong, the animations together with the explosions should reflect the calculations you are using to determine victory directly. I think you should also add "floating" labels with numbers and such, life meters and other things - so that the players can inspect the stats. That would add the view-value to the "scene". Making the ships move around and other tricks will just be confusing since it would give the player cues that movement matters without being under player control. 

Edited by mipmap

Share this post


Link to post
Share on other sites

One way to improve this fleet vs fleet combat could be by having an AI "player" at a higher level than the individual ships; a fleet commander that directs the targetting.

 

The way to win is to destroy the enemy's ability to wage war as quickly as possible. So the AI player allocates ships to targets in a manner that eliminates the most enemy firepower in the shortest amount of time.

 

AI "Personality" would be how much risk of failure the commander is willing to gamble, when estimating firepower to destroy enemy assets. For example, AI fleet commander George might be willing to be wrong one time in five. But AI commander Ricktor insists on being wrong only one time in twenty. So Ricktor's estimate of necessary firepower to do the job is going to be much higher than George. Ricktor will frequently allocate lots of overkill, wasting some damage potential. But George will allocate lots of underkill, and fail to kill ships as quickly as possible.

 

An alternative to the Fleet Commander solution is to use a system of contracts. First unit sees a target to kill, estimates the firepower necessary, and puts up a 'contract' to kill the target. Next unit checks the contracts list, and makes a bid, offering his firepower and time-to-target. Same thing with all units.

On the next pass, the first unit sorts the bidders according to ability, and selects the top guys who can make it happen. He then messages them that they have been selected for the job (making it a binding contract), and marks the contract closed.

On each pass, units check first if they are in a contract, then if the contract needs to be re-evaluated (like if a team member can't make it), and then either work on executing their contract, bidding on another contract, or making a new one.

Edited by AngleWyrm

Share this post


Link to post
Share on other sites

Yeah, overall I find it all satisfactory. Regardless how exatly you implement it. What really matters is the representation, if I am able to determine what's wrong with my fleet setup when watching the battle. The rest is irrelevant (to me as a player).

 

Have you played Endless Space?

 

Optimum range - won't you have preset classes of ships with certain main guns? I assumed it would be compatible with your other topics? In such case the optimal range would be trivial (predefined).

But if you want to do it the hard way (allowing the player to put any weapon on any ship class) I would just compare all range scenarios vs all range scenarios of the currently targetted enemy (the range at which you get the best firepower compared to enemy is the optimal one)..

Share this post


Link to post
Share on other sites

If the battle should be a "inspector" for the player to see what went right/wrong, the animations together with the explosions should reflect the calculations you are using to determine victory directly. I think you should also add "floating" labels with numbers and such, life meters and other things - so that the players can inspect the stats. That would add the view-value to the "scene". Making the ships move around and other tricks will just be confusing since it would give the player cues that movement matters without being under player control. 

 

We were indeed planning on adding these feedbacks ('hp' bar on top of each ship, etc.).

By reflecting the calculations, do you mean I should put damage numbers on top of every hit (a bit ala jRPGs?)

 

Regarding movement, I can 'make it matter' to the backend computation of a fight. I have some stats at the ready that I can use to leverage that:

Currently the ship's direction updates to the direction it needs to take, but I could make it rotate slowly. Thus, more manoeuvrable ships would have an easier time getting into position. Though the player has 'no control' over that, they'd quickly understand the value of manoeuvrability, and that very expensive and heavy warships that have a hard time manoeuvering can't win you every fight. Thus, the playback wouldn't be showing unnecessary data.

Yet, I believe I see your point: orbiting just for the sake of it is a goodie I don't need. The clear direction of this combat playback was to avoid the 'wow-factor' and focus on strategy. Putting more 'wow' stuff would feel like making battle chess for no apparent reason.

 


One way to improve this fleet vs fleet combat could be by having an AI "player" at a higher level than the individual ships; a fleet commander that directs the targetting.



The way to win is to destroy the enemy's ability to wage war as quickly as possible. So the AI player allocates ships to targets in a manner that eliminates the most enemy firepower in the shortest amount of time.



AI "Personality" would be how much risk of failure the commander is willing to gamble, when estimating firepower to destroy enemy assets. For example, AI fleet commander George might be willing to be wrong one time in five. But AI commander Ricktor insists on being wrong only one time in twenty. So Ricktor's estimate of necessary firepower to do the job is going to be much higher than George. Ricktor will frequently allocate lots of overkill, wasting some damage potential. But George will allocate lots of underkill, and fail to kill ships as quickly as possible.

 

That sounded like a great idea, but I feel its a bit out of scope. It wouldn't 'fit' well in my game if I allowed the player to choose their AI general, and it would be even less appealing if it was automatically determined, say, based on the species they are playing, especially if it turns out that one general is simply inferior than another in some situations and the player has realized that. Great idea nonetheless, in a different implementation.

 


An alternative to the Fleet Commander solution is to use a system of contracts. First unit sees a target to kill, estimates the firepower necessary, and puts up a 'contract' to kill the target. Next unit checks the contracts list, and makes a bid, offering his firepower and time-to-target. Same thing with all units.

On the next pass, the first unit sorts the bidders according to ability, and selects the top guys who can make it happen. He then messages them that they have been selected for the job (making it a binding contract), and marks the contract closed.

On each pass, units check first if they are in a contract, then if the contract needs to be re-evaluated (like if a team member can't make it), and then either work on executing their contract, bidding on another contract, or making a new one.

 

Interesting, but I'm assuming that all ships are subject to come in range of an enemy. What would be more important: fulfilling a contract, or creating a new one?

What if the issuing ship has moved in range of a distant ship, and that the ship that needs to take on that contract is at the other end of the battlefield, and needs to 'move through' a bunch of enemies to get there. Would it still fulfill its contract while briefly moving through enemies? It feels like an inefficient way to wage war?

 


Have you played Endless Space?

On my Steam Wishlist for a while. I've got a number of concerns with what I've seen, so I'm not very eager to play it, though, for research purposes, I imagine I won't really have a choice :)

 


Optimum range - won't you have preset classes of ships with certain main guns? I assumed it would be compatible with your other topics? In such case the optimal range would be trivial (predefined).

But if you want to do it the hard way (allowing the player to put any weapon on any ship class) I would just compare all range scenarios vs all range scenarios of the currently targetted enemy (the range at which you get the best firepower compared to enemy is the optimal one)..

Simple, yet effective. I wasn't sure I wanted ships to factor their target's capabilities. This is giving a lot of information that you may not have in these scenarios. It feels like when Warf/Data scans an enemy ship from an unknown species, with material from unknown origin, but is able to say with certainty that their 'armament is of equal strength to the enterprise'.  But I'll give it some thought, as this won't be exposed to the player.

 

Thanks all!

Share this post


Link to post
Share on other sites


Acharis, on 12 Oct 2013 - 11:35 PM, said:


Have you played Endless Space?

On my Steam Wishlist for a while. I've got a number of concerns with what I've seen, so I'm not very eager to play it, though, for research purposes, I imagine I won't really have a choice smile.png
Nah, just watch a youtube video about battle. There are not that many uniques stuff in that game (other than battle, planetary resources in Civ5 style, invasion mechanic).

 

* there is a fleet weight limit of 12-15 (the only real purpose is to make the combat sequence look good with fewer ship, I guess :D)

* the battle is made of 3 phases (long, medium, short range)

* each phase you can "play" a tactical card (I usually played the same one, that part could as well not exist to me :))

* each phase you could retreat (that was important)

 

And that's it...

Share this post


Link to post
Share on other sites
Because of the way my game is engineered I can't have phases. However I have a timer. Any ship that survives the timer gets to act on their turn as normal (escape). Then fight resumes on the next turn if its still relevant.
That part has yet to be implemented however...

So in a way my system is similar... a bit. But I dont like introducing gamey mechanics (cards).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!