3 hours ago, Lactose said:
One solution is to have Side A always win.
This is actually a great way to solve the math.
In short SideA - SideB so if the end answer is larger than 0, side A wins. Lower than 0 Side B winds and 0 = draw.
Doing it this way can reduce the need for IF statement by feeding the numerical result into functions.
I would recommend Rock,Paper, scissors to start with; except call it Soldiers, Calvary and Archers.
It's easier for me to draw than explain:
The AI here can be summarized as this:
1.) The largest group with the most counter types attack.
So when Team A had 2 horses and 2 soldiers, the horses attacked because they had more targets.
2.) Game stops when there is no counter targets left for either team. This simulates a retreat when a small army is attacked by a larger one.
The system above gives advantage to first attackers, to counter this you can use this attack pattern. TeamA -> TeamB + TeamB ->Team A + Team A -> Team B + Team B.
In short the first attacker gets one attack, then for the rest of the battle everyone gets 2 attacks. This prevents the problem where team A could use it's horses before they died.
There is a million ways to make this system your own. You could even include formation calculations.
As you can see from everyone's responses, it's all math.
Rock, paper, scissors is a good place to start and allows for easy expansion.