Table of Contents
September 2014 blog archive
This page contains all the blog posts from september 2014. To read the most recent blog posts, click here.
28/09 - AI optimizations
I was expecting that the AI for the abilities from the CA ships would have been complete by now, but halfway through the actis i decided to try something that could improve the AI.
Many actis, actions and even play abilities all go through similar steps when simulating what the results of these abilities would be on the board. I've combined such abilities as much as possible, resulting in three groups : those that only simulate a combat phase of the AI vs the opponent, those that simulate a combat phase, immediately followed a sim of the opponents entire phase, and then there are those that run both sims again, but interpret the results on the board seperately for both sims. There are a few minor variations as well, but in general, this is what the AI ends up do when it comes across abilities that affect ships in any way.
While this setup manages to combine multiple similar abilities, each ability often adds its own specific things that the AI must look for. Example : an acti ability that deals X damage to an opposing ship, but causes the ship with this ability to skip its attack phase and an ability that deals X damage to an opposing ship, but causes the ship with this ability to lose HP. Both these abilities for the most part use the same code to see the impact on the opponent's half of the board, but when it comes to how the ability affects the AI and its ships, there's a difference. Even though i've only added about 20% or so of the abilities that were in HDx, the AI for such abilities is already becoming rather complex thanks to all these small differences.
The changes that i'm working on will force all such abilities to go through the same general setup, which automatically takes care of secondary effects as well. Basically the AI will go through several simulations, an compare these amongst each other as well as with the actual board, and apply scores to the differences it detects.
The AI will go through 3 simulations :
1. initiation : the ability of which the AI wants to calculate the impact gets simulated. This process is slightly different for action, activatable and play abilities. At the same time, the AI starts another sim where nothing happens, basically making that second sim a copy of the actual board.
2. combat phase : on both sims, created in step 1, the AI simulates a combat phase of itself versus the opponent. The AI also creates two more sims, which are identical to the sims in step 1.
3. fullturn sim : on both sims that received a combat simulation, the AI now simulates the entire turn of the opponent (draw, upkeep, combat). On the two other sims which were copies of the sim in step 1, the AI runs a combat phase, making those sims effectively a copy of the sims in step 2.
After each step, the AI will check a number of things :
1. have ships been destroyed, lost HP or stats?
2. has a base been destroyed or damaged?
3. have structures been destroyed?
In each step there are 4 sims, and these are compared so that the AI can answer the questions above. Sim 1 is where the ability was triggered, sim 2 is identical, except that the ability didn't trigger. Sim 3 is the same as sim 1, but it's one step behind. Sim 4 is the same as sim 2, but it's also one step behind.
Example : if, after the combat phase (step 2), a certain opposing ship is no longer present in sim 1, but it's still present in sim 2, then the AI concludes that the ability that was triggered in sim 1 is the primary cause of that ship being destroyed. But, since it's possible that this already died immediately after the ability was triggered (i.e. in step 1), the AI also looks at sims 3 and 4 (which are basically identical to the sims from step 1). If both those sims still have the ship, then it's not only certain that the ability is the cause of this ship getting destroyed, but also that this only occurs after the combat phase, and not immediately.
Knowing what the result is of an ability is obviously important for the AI, so that it can figure out what to play first. Knowing when that happens, matters as well. The 3 steps with sims above are after all, not 100% correct - they are predictions of a possible future. In going from step 1 to step 2, the AI assumes that it will not play/activate any other cards after having played/activated the one it's currently simulating. In going from step 2 to step 3, the AI assumes that the opponent is also not going to play/activate any cards during their main phase. The AI makes these assumptions since it can't predict the future. I've set the AI up in such a way that it can deal with the fact that there are inaccuracies like this.
When the result of an ability is that an opposing ship dies, the AI will give this ability a score that's primarily based on the overall strength and importance of the destroyed ship. If, upon activating that ability, the ship dies instantly, then the simulation is very accurate, and the score the ability receives will be 100% of the score based on the ship. If the AI detects that the ship dies, but it only does so after the AI has completed its combat phase, it will only give this ability 50% of the score of the ship. Finally, if the ship dies only after the opponent has completed their combat phase (ie, more than a full turn into the future), the ability will only receive 25% of the score of the ship.
If the AI has two abilities that can destroy the same ship, but one ability is sure to do so instantly, while the other can only cause the ship to die indirectly, the first ability will thus have more score, and the AI will prefer it over the other one.
Some abilities already had such detailed setups as the one above, but most did not, since generally they weren't needed. A sim for an ability that can only have an effect far into the future (f.i. disable target ship) will generally receive less detailed sims compared to an ability that can have a direct effect (f.i. destroy target ship). The plan is to make all abilities go through the same, detailed setup described above.
There are some advantages to this :
* more abilities can share code. Basically all abilities that affect ships in any way will use the above setup. On the other hand, abilities that have no real impact on the board and the cards on it (f.i. draw a card, drain energy), won't use that setup and will stick with much simpler setups (as is already the case).
* abilities of different classes can share code. This wasn't possible with the original setup, but now actis, actions and possibly even play abilities can all share the same block of code.
* vastly increased accuracy. Thanks to the 3 seperate simulations, and the fact that the AI remembers the simulations of the previous steps, the AI is capable of detecting changes on the board more accurately, and can also detect when these changes occured. On top of that, secondary effects can be more easily taken into account as well (triggers and auras, example below).
* adding in new abilities will take less time. Possibly the biggest advantage of all. For the CA card set i estimated it would take a month to get all the cards in. There are still 7 sets of cards to go. The more cards that are in the game, the more overlap there is, and abilities on future cards might already be in the game, but even so, it would take a lot of time to add in all the HDx cards. With this new system, i can probably lower the amount of time i need to spend on adding in new cards and abilities by 1/4th.
There is a drawback as well :
The AI now needs 4 simulations to make all of this happen. Technically the game can handle any number of sims, but it's likely going to have an impact on how fast the AI is. In games versus one AI this might not be a problem, but once 4-player games are in, an AI can face up to 3 opponents, and thus it must calculate the effect of its cards and their abilities against all of the targets these opponents might have. It's hard to predict how this will affect things at this point however.
This system is currently being tested, which meant i first had to adjust all HU actis and actions so that they could use the new setup. Once this is done, i can continue adding in the remaining AI abilities, and make them compatible with the new system right away.
Finally, an example of secondary effects. With the CA card 'dark deflector' (DD), the game received its first trigger aura. These are abilities that generate an effect when something else happens. In case of DD, whenever this ship is damaged by an opposing source, this aura increases the strength of this ship's auto ability, which deals damage to the opposing base.
Imagine a board where the player has one ship, this DD, and the AI has is considering using a cruise missile it on it (12 damage). The ship is full HP, so the only things the cruise missile does, is lower that HP by 12. This loss of HP is instant, and thus rated at the full amount, at a ratio of 1 point per damage dealt. Thus this ability gets a score of 12 for this particular target.
Under the old system, the AI would run a combat sim on top of this so it can see if the damage of the cruise missile combined with the damage of an attacker in front of this ship would be enough to kill it. Under the new system, the same happens, but then there's an extra step on top of this : the full turn sim of the opponent against the AI.
After step 1 in the new system, the AI has access to 4 sims : one where the ability triggered, (DD has suffered 12 damage), one where the ability didn't trigger (DD at full HP), and two sims which are copies of the board (DD in both cases at full HP). The AI notices that there's a difference of 12 damage to opposing ships in the first 2 sims, which is in the AI's favor, hence the 12 points of score. In step 2, the AI runs a combat sim on sims 1 and 2. The original sim 1 and 2 basically get copied to sims 3 and 4, this is how the AI keeps track of what the board looked like in the previous step. For this example we'll assume that the AI had no ships, so sims 1 and 3 look the same and so do sims 2 and 4. But in both cases, there's still that difference of 12 damage between 1 and 2 and also between 3 and 4. This time the AI awards no additional score for this difference, since the difference is the same for both sets of sims, this is how the AI can tell whether or not this damage occured in this step, or in the previous step. It happened in the previous step, and has thus already received a score and no longer needs to be scored again. Then comes step 3, the step that didn't exist in the original version of the AI for this ability, and here there will be a new difference. Step 3 is the full turn simulation of the opponent, on top of sims 1 and 2. At the same time, sims 3 and 4 receive a combat sim, so basically 3 and 4 are now identical to 1 and 2 in step 2. The AI will now notice that in sim 1, it has one less base Hp than in sim 2, and this is because the aura on DD triggered as the result of the cruise missile that was played on it, allowing DD to do more damage to the opposing base (i.e. the AI's base) during its owner's turn. Damage to base gets scored as one point per damage dealt in this example, but since the damage was done to the AI, this becomes a negative score. But since this also happens far into the future, this score is modified with 0.25, thus the final penalty would be -0.25 points.
At the end of these sims, the score for the cruise missile is thus 11.75 points. If the player had two identical ships, one the DD, and one a DD without the trigger, the AI would give 12 points to the ship without the trigger.
The difference between 12 and 11.75 is very small, but if, in the example above, the AI only had 2 base HP left, the simulation would point out that launching a cruise missile against the DD would destroy the base at the start of the next turn. In that case, the cruise missile would have receive a much larger negative penalty, up to the point where the AI is going to decide that it will not use it, as it's simply too dangerous.
This example shows another advantage of the new setup. The original cruise missile AI didn't take into account the DD trigger, since the DD card and its abilities simply didn't exist in the game yet when i wrote that AI. Now that DD is added, i would technically be forced to go back and look at all damage dealing abilities and make sure they take into account this trigger. That's a lot of work, and it would have to be repeated if i add another trigger in the future that goes off when a card receives damage. In this new system, triggers like these are automatically taken into account. Should i ever come up with a trigger that this system can't handle, well, then i only need to upgrade this one large block of code, instead going through all abilities individually.
This was a big problem in HDs and HDx. I managed to improve the situation a lot thanks to an AI that uses simulations, but due to the sheer amount of abilities (approx 500), i'm still going to end up with a lot of code, no matter how i try to combine it. This new system is a huge improvement on top of that.
21/09 - CA card set
Meanwhile, work has begun on the CA cardset. With the HU cardset, i added in cards a few at a time, but this time i'm seeing if the entire process is faster if i add in all ships at once, then all structures, then the actions.
There's a lot involved in adding cards and their abilities, so this entire process will take some time. The plan is that when all content is in, the game can go into beta, but with 8 card sets still to go, its clear that this will take a while. On top of the card sets there are still additional game modes, deckmods, environments (and more) that need to be added.
There are a few changes in these cards (thus far) compared to their HDx versions :
Anti Screen : This ship retaliates for the amount of damage it receives. In HDx this was a special ability, but for HD3 it's simply the retaliate passive that, instead of returning a fixed amount of damage, returns the amount that was last received.
Antimatter Engineer : The play ability has been adjusted slightly, instead of drawing a card if the top card in deck was a structure, the draw now happens if the owner has more cards in scrap than in deck.
Dark Deflector : This ship had a retaliate ability that targeted the base. In HD3, this ship has an auto ability that lets it deal damage to base, but everytime this ship is damaged, the amount of damage the auto ability does, goes up by 1. The ability that makes this all happen is a trigger aura. It's the first ability of this kind in HD3, but plenty more are planned and might one day be added to new or existing cards.
Energy Shield : The cloak has been replaced by a 'shield 3' passive.
From next week onwards, the AI code for all the abilities on the CA ship cards will be added.
14/09 - HD3 flagship overhaul
HDx had some 500 abilities. Once the entire HDx card set has been added to HD3, the number of abilities will be slightly lower, as some have been combined, but there will still be a large number of them. Plenty of new abilities are planned that also need to be added on top of this. This is good news for the diversity of both the cards players can collect and the AI opponents they'll encounter. It's not so good news for the flagship editing screen.
The flagship has 8 slots for abilities. Except for the limit of 1 activatable ability, all other slots can be any ability class. Thus, when adding an ability to the flagship, players first have to choose the ability class (passive, automatic, activated, etc). Once the class is chosen, players can scroll through all the abilities this class has. And there are two problems with that. First, the number of abilities in this list can get large (actis for instance can easily get 100+ abilities). Second, the abilities are listed by an unique number. If you know what ability has which number, this is no problem, but if you don't, then you'll likely have to scroll through most of the list to find the one ability you're after. Abilities receive their unique number as they're added to the game, so there's no other logic behind these numbers.
There are three things i'd like to do that will address these problems :
1. Limit the number of abilities that are available for the flagship in each class. This will be looked at on a per-class basis. A class with only a few abilities in it, isn't going to get affected. But a class like actis will have to be looked at. Primarily i will remove abilities that are very similar to abilities that will remain in the list. That way, the number of different flagship builds that are possible won't be affected too much.
2. Ability classes will be split up further in a number of subclasses. All damage dealing abilities will go in one subclass, all repair abilities in another, and so on. So instead of browsing through for instance 80+ acti abilities, you first select the general type of acti you want (f.i. damage), then browse perhaps 10 different abilities.
3. The numbers of each class of abilities that can be put on the flagship will be limited. This is in part also a balance requirement, as the alpha testers have already found a number of overpowered ship setups. More fine-tuned balancing (such as per-ability scoring) will be done later, once the bulk of the abilities are in. The number of slots remains fixed at 8 abilities, but each slot can only accept a certain ability class. There will be room for 2 passives and 2 autos, and 1 played, aura, acti and exit ability.
These changes took less time to implement than expected, so i released a seperate alpha update where the new flagship editor can be tested.
07/09 - new HD3 alpha update
Last week's update had two major elements : new input options for the combat screen, and a temporary savegame.
The input options have been discussed in the previous blog post. First there's a selector which tells players which card is currently selected, active, or targeted. Arrow keys can then be used to scroll between cards, regardless of whether the card popup is active or not. The enter key can either bring up a card popup, or activate the default operation for the card whose popup is currently showing.
A quickplay mode has been added, which is active while the ctrl key is held down. It allows to play or activate cards without having to bring up their popups first. There's also a quickplay button which makes this mode permanent, so that the ctrl key doesn't need to be held down.
The savegame for now only stores the decks, the flagship and flagship presets. The main purpose of this savegame is to make alpha testing a bit easier, by making it so that testers don't have to recreate their decks and flagship setups everytime they launch the game. This savefile is temporary however, and updates that change decks or flagships might result in these savegames being reset.
Once the game gets closer to a beta release, i'll implement the final savegame format. From that point onwards, should there be updates that affect the savegame, the game will have ways to make sure that savegames from older (beta) versions can still be read.
The next update will likely be a major one, though i might split the upcoming content over two updates, depending on how long it might take to implement it, or in case new and critical bugs are discovered.
Two big elements are planned : the flagship editor overhaul, and the CA card set. The flagship changes will likely be implemented first as i expect these to take less time than adding in a full racial card set, but also because doing the cards first would mean that the flagship updates will only take more work.