How to make a 5 to 5 unit battle in a 2D game

Hello
How to make a 5 to 5 unit battle in a 2D game like in afk arena or idle heroes?
There you place the heroes in positions and artificial intelligence begins a fight against another artificial intelligence.
Maybe there are already examples with source codes for studying fights 5 vs 5?

I want to make a game similar to dota underlords or auto chess, but with my characters

You really should start from very basics. Check Getting Started sub forum.