How can you program a videogame bot that is just good enough as your opponent?

138 views

I’m playing Rocket League and thinking how can the bots not kick your ass everytime they’re there, while at the same time not be completely lame.

In: 6

It really depends on the game. Let’s look at chess for a basic example.

When it’s the AI’s turn in chess, it can have ~100 different moves it can do. It can look at various moves and give the resulting board state a score. That score can be an algorithm that looks at things like how many pieces (with each piece having a value). It can factor in things like which pieces are threatened, which pieces are threatened but retaliation, etc.

There are two places you can easily tune your AI. The first thing you can do is have it look more than 1 move ahead. Rather than look at just your own move, look at what your opponent can do on the subsequent move, and then use that to calculate scores.

Another thing you can do is adjust that scoring algorithm. Your basic scoring algorithm might just try and take as many pieces as possible, but a more advanced one might be looking at how much it’s giving up to take those pieces. An even more advanced one is looking at how well you’re protecting your pieces to make sure your opponent doesn’t have a cheap take on their side.

As for adjusting on the fly, you basically have to have another algorithm that’s looking at the bot’s odds of winning, and if it’s not doing well enough, to ramp up the difficulty. If it’s doing too well, it can lower the difficulty.

With a game like Rocket League, you don’t necessarily have as clean as a board state as Chess, but you can look at metrics like “how soon can I get to the ball”, “how soon can my teammates get to the ball”, “how soon can my opponents get to the ball”, “is the ball on their side or ours?”, and use that for determining what actions they’ll perform.

In addition, they can also change the polling frequency of the AI. In a game like chess, it has to make a decision every turn. With a game like Rocket League, you can have it reevaluate its plan every 5s, 2s, 1s, 0.5s. This can also naturally introduce imperfect shots, since it’s trying to make a shot based on slightly old data.

Hey! It’s cross-platform bow right?? Wanna add me?

The most common method is to use the strengths of computers (target recognition, reaction time, angle computation, etc.), and then apply a bit of randomness or latency to the decisions or results. Doing it this way, you can amplify the handicap based on the difficulty settings (if the game has them).

A better method is to monitor how well the player or players are doing, and then adjust the accuracy on the fly to keep them barely winning. A simple example would be racing games. Once you teach the AI to successfully navigate the track, it is easy to tweak the controls or the car’s properties so that the AI can stay right on the player’s tail, and occasionally pass them to keep it exciting.