V
V
Victor P.2021-01-16 15:07:59
Algorithms
Victor P., 2021-01-16 15:07:59

What patterns to use for game bots?

Good afternoon, dear Tostorians.
I turn to you for advice on how to write game bots in order to have the cleanest possible code. I want to write in js, but this is not the point. The game StarCraft 2, although it doesn’t matter, the writing process is no different from any browser game, for example
What are the features of game bot building: the global context of the game - open data is stored there, for example, available resources, a list of your buildings, workers and warriors. In addition to the context, there is also an infinite loop.
The main problem is that every time the compiler enters this infinite loop, it has to redefine the current stage of the game. To do this, I add a global variable for the current step and in a switch / case loop with a bunch of branches.
And if there can be two strategies at the same time, then the global list of active steps with the isActive flags.
It all looks extremely sad and I would like to figure out for academic purposes how to write such things correctly. Just tips and pieces of code are accepted)
Thank you for your attention

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-01-16
@res2001

Array/hash table with functions that implement switch branches, select the desired function from the array/hash by variable and call it. The whole switch will spread over different functions.
Not strong in JS, so no code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question