Another week and a little further down the rabbit hole of systems development. This week I again ran into the necessity of taking a step back to make sure that I design and set up game systems the right way, rather than plugging in dummy functionality and causing rework later on. As a result, coding took a backburner to some research and systems design. The good news is that I was able to establish the initial design for several key upcoming systems in the game and start work on the coding. I'll cover some of them briefly and then talk about the game's AI system.
In preparation for the 0.1.0 release, some rudimentary systems need to be in place, to be expanded in more detail for subsequent releases. Among them are ship generation, travel mechanics, and a location system (basically the galaxy map). I'll be talking about each of these in depth in future updates, but here's a brief overview:
In light of the expanded scope of this release, I've updated the roadmap and feature comparison pages to better reflect what's being worked on for 0.1.0. The new features are necessary and, while they may delay 0.1.0 a little, they will help future releases immensely.
In the Junction Gate Alpha, my first attempt at any sort of computer AI ever, the computer players can be somewhat finicky. They mostly work as intended, but they aren't very smart or adaptive. The code itself is basically a set of rules encoded into a series of if/else statements. There's no "system"; the AI for each game entity is unique and there is no code reuse. It's messy and making changes or maintenance to the code isn't fun.
As I began making preparations for implementing the AI for the trade ships, I realized I needed a more robust, flexible, and maintainable AI system. Some of the different entities that will require AI in the game include: traders, ship captains, CEOs, colony governors, faction leaders, and pirates. I needed a system for all of those types of NPCs, so I started my research.
The type of system I settled on is called a Utility AI system. Rather than a rigid if/else structure of conditions and rules, the Utility AI system compiles a list of possible actions an NPC can perform, scores each action with a numerical score, and then selects an appropriate action. The score for each can change based on the current situation and can be individualized to each NPC based on their unique characteristics. The action selected can be the action with the best score, a random selection from the top options, or a weighted random selection. Introducing randomness into the decision-making process add variety and makes the NPCs less predictable.
One of the first applications of this new system in Junction Gate will be the trade ship NPCs, so let's use them as an example. Let's say a trade ship arrives at a colony with a hold full of cargo. Upon arriving, the trade ship captain has several available options:
The Utility AI system retrieves the colony's data, the ship's data, and the captain's data and passes them to each action function to be evaluated and scored. Once the scores return, they might look something like this:
The system might eliminate Option 4 at this time because the score doesn't meet the arbitrary (in this example) minimum threshold of 20. If we simply go with the best score, Option 1 would be the choice. However, the system could also choose randomly or take a weighted random selection from Options 1-3. For the sake of illustration, let's say that the trade ship captain chooses Option 1. After completion, it's again decision time. Now that the situation has changed, the scores are recalculated and now look like this:
With new information, the scores have changed and the trade captain's priorities have now shifted. Selling goods has been zeroed out, so it's off the board. Leaving moved up, but the score is still under the threshold. Now buying goods seems like the best option, so the captain does that.
Trading is now off the table, but leaving has finally passed the minimum score threshold. However, being a prudent captain, he fills up his fuel tanks because you never know what might happen.
Now that the captain has decided to leave, the Utility AI looks at the available destinations and assigns each of them a score. Some factors going into the score might include distance, profitability, and threat level. Once the location has been decided, off the ship goes to start the whole process over again once it arrives.
As you might be able to see, the Utility AI system opens up a whole new world of possibilities for the game. Some of them could include NPCs with different personalities, varying aversions to risk, and the ability to become more experienced and choose better options over time. I have a lot of ideas for this system, but it will take some time to build and a lot of balancing and experimentation to work them out, so stay tuned.
If you're interested in learning more about Utility Theory for Artificial Intelligence in games, here are some of the resources that I found:
The above videos weren't embeddable here, but I'd really recommend them if you want to learn more on the subject, especially the first video.
This coming week is my wife's and my 9th wedding anniversary, so work on the game will be a little lighter than usual. However, I anticipate continuing to work on the systems mentioned above. I hope to have some of the AI system worked out by next week, perhaps enough to have trade ships traveling from one location to another. It might take a little longer than just this week, but once that is in place, I'll be able to return to working on the trading UI. Have a great week!Tweet comments powered by Disqus