Intro to Crew AI

INTRO TO CREW AI

Are your crew sitting on their butts all battle while your opponent’s crew are running around putting out fires? Get your crew to work using AI! 

Your minions are ready for their orders!

AI is how you control what your crew does, and is the only way to control your crew on defense. Build a CMD room as soon as possible and program that AI!

A few notes:
You can remove the CMD room when you’re not actively editing your AI, everything will still function.
If you manually move a crew during battle, all AI for that crew will cease. You’ll have to double-tap them to trigger their ability, and move them for the rest of the battle if you want them to move. 

Definitions

Pixel starships has its own way to “program” crew. Understanding this is the key to designing your own AI, and to getting your crew to actually do something complicated.  

command is a whole line in the AI 
condition is the first half of the command, the part that is evaluated 
action is the second half of the command, the part that is executed 

True – a condition is true when the condition is true. For example, if the condition is “target room has enemy” and the crew is currently targeting a room with an enemy, then the command is true.
Valid – an action is valid when the action can be completed. If the action is “target enemy lasers” then it is only valid if there is at least one laser room on the opponent’s ship that has HP. 

Crew have two groups of actions, unlike rooms: 

Special power – the crew can be told to use their ability. Each ability can only be used once per battle. 

Targeting – targeting a room makes the crew walk to that room. A targeting action is not valid if there is no path to the room. No targeting commands allow you to pick specific rooms, only room types. For example you can’t differentiate between a SHL and SB, or ION and EMP. Crew will always go to the closest room of the targeted type that has room for them.

You can’t control what your crew do once they reach the targeted room; they will always do the following actions in order:
— Fight enemy crew present in the room
— Put out fires
— Repair the room
— Boost the room using their appropriate room stat for that room (weapon, pilot, science, or engine)

Every frame (so 40 times a second) the game engine loops through all the commands, from the top to the bottom, and takes the first true and valid command FROM EACH GROUP. Once a true and valid command for a group is found, all other commands below that in the same group are ignored. For simplicity, I like to put my groups of commands together, but you don’t have to – the functionality is the same. 

Got it?

Let’s do an example

Here is a simple example for our Xin, who is starting in our hangar: 

1) None – use special power
2) Your laser HP less than 100 – target condition room 
3) None – target your hangar 

In the first frame of the game, the valid and true commands for ability and targeting are chosen. For ability, it’s of course command 1 – so Xin will use his rush ability where he is standing, in the hangar (see rush ai for more details). The hangar’s reload will decrease by Xin’s ability stat. For targeting, command two is not true since our lasers have not been damaged yet. The first true and valid targeting command is three, which is already satisfied so Xin will stay in the hangar. 

Later in the game, let’s say one of our lasers takes damage. Command two will be true. If there is space for Xin to move to that room and he has a path to get there, he will go. (If all crew have the same ai and try to go to the damaged room at the same time, the crew with highest seniority, who you’ve had for the longest, will go). Let’s say he moves there and repairs the room, and right as he finishes, another laser AND your hangar are both damaged. Will he go to the laser or hangar? He will go repair the other laser because command two is a higher priority. He will only go back to the hangar once there are no damaged lasers. 

Second example: 

1) None – use special power 
2) Your ship HP less than 50, target your laser 
3) None – target your hangar 

Let’s say we don’t want Xin to leave the hangar  until halfway through the battle, so that he can help boost the hangar with his pilot stat after he uses rush. We want him to help repair lasers once our laser crew is dead. We code the ai above. One of our lasers is damaged early in the battle when our ship has full HP, but Xin stay in the hangar. Success! Then our ship falls below 50% HP, and a laser is damaged simultaneously. Does Xin go to repair it? Maybe… He will go to a random laser, since we didn’t specify target condition room (meaning target the room that is making the condition true). If Xin is standing in a health laser but every other laser is destroyed, he still won’t go repair them because condition two is still satisfied. A way to accomplish what we want is: 

1) None – use special power 
2) Your ship HP greater than 50 – target your hangar 
3) Your laser HP less than 100% – target condition room 

Coding AI is a puzzle to use the right conditions and actions in the right order. If you can’t figure out why your crew are behaving the way they are, walk through your commands top to bottom and check what is true and valid. If it seems like crew are just not obeying your commands, check your crew seniority! If you have older crew who are told to go to a room, they will “reserve” their spot in the room while they walk there and other crew cannot use that spot. This comes up most often when boarding. If you have four crew targeting the teleport, only three will be able to go until one dies.

Continue reading about AI on the More AI page.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top