The AI-Not-Being-So-Stupid Update

Undercrewed

Grab your friends and build and fly your own customisable spaceship. With local and online co-op customise your spacecraft with a wide variety of components, you must work together to figure out the best way to survive your journey!

Greetings Captains! This isn’t my standard format for a news update, but I thought the last patch was interesting enough to write a short article about. So if you’re interested in a more ‘behind the scenes’ peek on how the AI works, then keep reading… I've always been really happy with the AI that your crew uses, so the question you might be asking yourself is “why does it sometimes do stupid things?”. [h1]How the AI Works[/h1] Let me tell you (with great excitement) about how the crew AI works... I often tell people “The AI learnt how to play the game” but what I mean by this is that it kept doing random tasks until it worked out the best strategy it could find, I put in the code for how the little bots should pathfind between rooms and how each room works, and I let it play the game for hundreds of hours randomly assigning rooms to the AI crew. It would record information about the situation it was in, what rooms it was using, and how well it coped with that situation. So now I have a database filled with loads of information that can answer questions like; Was better to use shields or guns when there were 3 enemies attacking and 2 crew were dead? Was it better to drive to the next point or should it be repairing rooms when the enemies were not doing much damage? Was it helpful to be on the shields when there was nothing to block? [img]{STEAM_CLAN_IMAGE}/32141760/f8c3184aa3c05a4507253697547c6f30c487860c.jpg[/img] [h2]What’s the problem?[/h2] The problem comes when the AI thinks it's doing the right thing but it doesn’t actually understand the situation. I’m going to list a bunch of examples below however this update has been all about me finding as many of these odd cases and program exceptions to fix them. Now, if you are not a programmer you should know that programmers hate it when they have some simple elegant code and have to go around adding a bunch of messy exceptions to deal with weird small little exceptions to the rules. In no particular order: [h2]Problem 1:[/h2] AI standing in a room while it waits to be given a task. While this doesn’t sound like a problem they might be unintentionally draining the spaceship of energy or using ammo. [h2]Solution:[/h2] When I first made the AI system it was always better for an AI to be in a room when it wasn’t needed than for it to leave and have to walk back, for example it was better that the crew manned the shields when there were no enemies because it just meant they were more prepared, but as I added more complex rooms they would use energy or other resources that the AI didn’t take into account before. The fix for this was just to make them stand elsewhere and wait when they don’t know what to do. In the future I might make this even more optimal by spreading out around the ship or maybe waiting outside a room they are likely to need soon. [img]{STEAM_CLAN_IMAGE}/32141760/9185d272ea684e44942030c727f06863e5358c68.gif[/img][img]{STEAM_CLAN_IMAGE}/32141760/ac4929bd78530a05d877a50f0078b3ccc2977583.gif[/img] [h2]Problem 2:[/h2] People get to build their spaceship in Undercrewed so how do I even know if they put shields on it? Are there guns that the AI can still use? The AI might be able to fly the ship but is there even anything to drive to? The AI is really close to make energy, but does the ship actually need more energy? [h2]Solution:[/h2] Before I let the AI system loose assigning tasks I check what tasks are even possible. I check a small number of things like; exclude rooms with someone already in, exclude rooms that don’t have enough energy to use, exclude rooms that are too far away from their target (lasers and tractor beams). However there were a bunch of other reasons a room couldn’t be used like if it had been EMPed [img]{STEAM_CLAN_IMAGE}/32141760/f229c5a2915a328b15e3b76e32f2f00aa5e339f0.jpg[/img] [h2]Problem 3:[/h2] The AI assigns itself to spawn holomedics but the player gets to the room first (so the AI thinks it should also be in this room (shooo I was in here first)). [h2]Solution:[/h2] When the AI was selecting from possible tasks this was the only time it would check if the room was free. So quite often an event would happen that caused both the AI and the human players to know they needed to use a room. You can see how this would happen quite frequently and since I can't mind read what the player is wanting to do I just get any AI bots to check if their room is occupied every few frames. [h2]Problem 4:[/h2] Sometimes there will be an event that requires all the crew to get into one room but rarely an AI member will just go about it's business burning in the radiation like nothing is happening. [h2]Solution:[/h2] This was caused because of the order tasks were handed to the AI, sometimes they will be told they need to go into the radiation room but later in the code they are actually told to go and get some ammo. I’ve now made the order tasks are assigned better. [img]{STEAM_CLAN_IMAGE}/32141760/e7b154975f0a3b73cc8ef049bee5122ac47b99dc.gif[/img] [h2]Problem 5:[/h2] The AI have the ability to be very accurate with their gun shots, they know how fast bullets travel and use this to predict where their target will be, so to stop the AI becoming super human marksmen I give them an arc that they are allowed to be in. However this arc was far too big so some smaller enemies/targets would still be in the arc and the AI would happily stand their thinking they are fulfilling their criteria while missing every shot. [h2]Solution:[/h2] AI will now try and stay within 2 degrees of their target rather than 6 degrees. This does make them a bit too good however it's better that the bots over-perform rather than under-perform. [h2]Problem 6:[/h2] When driving towards an objective the ship the AI could get into a cycle of rotating for 1 frame and then stops rotating for 1 frame and rotating for a frame etc. This is because it so accurately knows what angle it needs to fly at it only adjusts when it needs to, however this is very jarring for the player. [h2]Solution:[/h2] This is one example where I have made the AI less intelligent, when driving the AI now overshoots when turning. This means it will only update it's angle after turning about every 5 degrees. This makes far more smooth shapes but doesn’t reduce the reaction time of the pilot. I’m sure there are many things I still need to improve (and I’m also sure that some areas I have accidentally made worse) Very soon I will be deploying the [i]Achievements-And-Fixes-And-Bugs-Oh-My[/i] update onto the beta version of Undercrewed, as you can guess it's going to have the first set of Steam achievements (to help me gauge how easy and hard they are) and a whole bunch of bug fixes as well. As always you can see what I am working on every day on the Undercrewed [url=https://trello.com/b/pBixGPBN/undercrewed]Trello[/url]. Join the community on [url=https://discord.gg/zn8qQ3X]Discord[/url]. We also have a [url=https://www.facebook.com/undercrewed]Facebook[/url] and [url=https://twitter.com/undercrewed]Twitter[/url] if you want to get news about new patches and updates I do. Lots of love > David Strachan