send feedback
On Sunday I published an update to Mayhem Manager. Here’s what I did, how I did it, and what I’ll do next.
(For an explanation on Mayhem Manager, read my initial blog post about it from January. To play it, go to my arcade.)
What I did
Equipment overhaul
Equipment now have a greater variety of abilities, and the code has been modified so it’s easier for me to add new interesting abilities in the future.
Fighter abilities
About half of the fighters that are generated will have their own special abilities.
AI improvements
The management AI is now much more competent, to the point that I don’t win the championship every single season I play against the AI. It’s less prone to sitting on huge piles of money or assembling huge teams with no equipment, and it is better at applying equipment more synergistically.
How I did it
(This section is technical.)
Equipment overhaul
Before this update, I was storing all equipment in the game as JSON objects. The idea was that it would allow players to add custom equipment in the settings and immediately play with it. I thought this would speed up testing, but it turned out that it was faster to test things by adding them to the regular equipment file anyway. And the userbase is nonexistent so obviously no one else cared.
In particular: I previously defined each equipment as a JSON object with a set of abilities, which were composed of triggers and effects. The fight simulation code then had to detect when each trigger occurred, and it had to execute the set of effects that should result. This whole system was very general, which is nice, but each new ability meant a new type of effect, which meant multiple updates to type definitions, a new clause in the fight simulation, and a way for the fighter AI to evaluate the effect. The AI in particular was becoming a mess, and I rarely added new unique effects because it meant rewriting much of that mess.
Now each equipment is defined as an object with functions that execute its effects and functions that tell the fighter AI how to use it. It allows me to write helper code to reduce boilerplate, and it concentrates an equipment’s logic in a single, isolated place, rather than combining all equipment logic into a few increasingly complex functions.
Fighter abilities
Fighters were previously just a pile of stats, which was pretty boring. So I added abilities to fighters. Fighter abilities are defined, essentially, as invisible equipment that are equipped at the start of every fight. Pretty simple!
AI improvements
(In particular, I’m referring to the management AI, the AI for choosing which fighters and equipment to acquire and for picking which fighter should wear which equipment.) The old AI wasn’t compatible with the equipment overhaul, so I had to rewrite it anyway. And one of my major goals with the game is to make the AI good. In most sports management games, the AI is bad enough that the game gets trivial in singleplayer once you’ve learned a decent strategy. I want to make the AI good enough that it’s a challenge to win even if you’re good. And this update was a major step toward that.
There are three main components to the management AI:
- Evaluation of a fighter’s strength.
- An algorithm to find optimal equipment assignments to maximize the sum of your fighters’ strength.
- Evaluation of how much acquiring an equipment or fighter improves the team (based on optimal equipment assignment).
Parts 2 and 3 remain mostly the same; part 1 got a total overhaul. The previous algorithm used the equipment JSON objects to evaluate a fighter’s strength; this approach was complicated and didn’t measure fighter strength very accurately. I figured a rules-based algorithm like that would require a lot of work to make good (and would require me to redo a lot of work when I add new equipment). So I switched to using statistical methods to estimate a fighter’s strength.
To do this, I simulated 100,000 matches between randomly generated fighters with randomly selected equipment. I stored the results as a row of numbers for each fighter: a number from -1 to 1 based on who won and how close it was; five numbers from 0-10 representing the fighter’s five stats; a 1 for each equipment / ability the fighter had; and a 0 for each equipment / ability the fighter didn’t have. Teams can have different numbers of fighters, so all 0s represents the lack of an additional fighter, which lets me quantify the baseline value of a fighter.
The most powerful technique would probably be a simple neural network, but I’m avoiding it for now because it’s computationally expensive and it’s not very easy to interpret the outputs. (I’d like to use the outputs to help me make game balance decisions.) And I tried XGBoost, but a decision tree approach meant the AI would completely ignore some equipment unless I had quite a lot of decision trees. So ultimately I settled on linear regression.
To get the system working initially, I used a simple linear regression with no extra features. This was ok but it meant the AI completely ignored synergy. So I added interaction terms and it was a big improvement. I’m a little concerned about the number of features, but I don’t see any signs of overfitting.1 As I add more equipment and abilities, the number of features will grow quadratically, so I might have to prune less important features at some point. I tried to use LASSO regression for this, but it was taking way too long to compute. A more rudimentary approach would probably be fine, but it’s not needed yet.
What I’ll do next
I’m not sure I’ll work on Mayhem Manager very much in the near future. But here’s what’s on the docket for when I do work on it.
Add more equipment and abilities
There are only 5 fighter abilities and around 20 unique equipment right now. I would like to eventually reach more like 30 fighter abilities and 100 unique equipment. But getting to that many is a long way off.
Merge draft and free agency
Although real sports leagues usually have a draft and free agency, I think in Mayhem Manager it would be better to reduce the waiting by combining them. I would probably remove the draft and make all new fighters enter the league through free agency.
Make fights more exciting to watch
One thing people keep suggesting is that I add sound effects. I usually disable sound effects when I play webgames, but I’ll probably add them anyway.
The other thing is to design “splashier” equipment with big effects and a big visual footprint. Beyond that, I’m not sure what the best option is; the animation in the game will always be pretty rudimentary.
Add a mobile UI
There’s no reason you couldn’t play this game on a phone. But I didn’t make a layout for mobile so you have to do some awkward scrolling and zooming. People use their phones a lot so I figure it’s a good thing to add.
General UI cleanup
A lot of things in this game could look nicer. I think the screen for assigning equipment to fighters could be a lot clearer; I think the bracket could look more like a bracket; I think the spacing of fighter stats could be more consistent. Probably some other stuff too.
Add a tutorial
I would like to be able to send people this game without having to explain it to them as they play.
-
In particular, there were no anomalously high or low coefficients, and the coefficients on the extreme ends were the ones you’d expect to be important. Not many features seemed to have no effect, but it’s not unreasonable to expect given the domain. ↩