# Battle System Solution

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings, guys. We have been working on a fight system for a turn-based strategy game and we haven't been able to find a working solution. We have tried quite a few approaches and prototypes, but none worked. Therefore I present the problem to you, fellow coders and designers, for maybe you will know of something old as time itself or come up with a bright idea. The system is pretty simple, at least from the player's viewpoint. You (the player) have two armies facing each other, consisting of one to eight units. You know the strength of every unit of your army and every unit of enemy army. You know which units do well against which particular enemy units and vice versa. Battle is calculated anonymously, you do not see its workings, only the result. Unit Each unit has the following properties relevant to battle: * Strength - a number from 1 to some limited value (perhaps around 15). This defines how well the unit does in battle. * Type - this defines how well the unit does versus particular unit types. Types are: ** Foot - goos vs pike. ** Pike - good vs mounted. ** Mounted - good vs foot. ** Giant - good vs flyer. ** Flyer - good vs foot and mounted. 'Good vs' means that the unit has a strength bonus when fighting the respective unit type. The bonus is the same for all combinations and is deduced from the unit strength. Battle There is nothing like accessibility of units one to another (like archers hiding behind infantry) or any unit positioning or terrain. It is just the unit's strength and bonus system that count. Now, we need a formula that calculates strengths of both armies resulting in a ratio (for instance, 15:12) which will be the chance of one army defeating the other. We do not need to calculate which units die in battle, just which army wins. For better imagination, let's define the armies. Let's have attackers consisting of a golem (strength: 5, type: giant) and a skeleton (1, foot), and defenders of a dragon (5, flyer). In this config, attackers should clearly win, as their golem is equally strong as the enemy dragon, but has a bonus against him, and they are two against one. Defenders have only one unit, the dragon, and he has a bonus against the skeleton, which should help him a bit, but not enough to flatten the powers of both armies. What do you think is the magic here, to get one final number for each army?

##### Share on other sites
Well it's hard because honestly, if i had a dragon and you had golems and skeletons, I'd still expect to win with the dragon. So aside from numbers, do you have any other attributes to determine win/lose ratio?

##### Share on other sites
Quote:
 Original post by Alpha_ProgDesWell it's hard because honestly, if i had a dragon and you had golems and skeletons, I'd still expect to win with the dragon. So aside from numbers, do you have any other attributes to determine win/lose ratio?

This is a mathematical problem, not a fantasy genre customs one.

##### Share on other sites
So you want to see how many enemies there are against each other, or the winning ratio depending on the stats of both armies?

If it's number two, I would check each monster to each opponent and get the average chance of winning, something like this:

You have 3 monster, opponent has 4

Monster one compares itself to the 4 opposing monsters. Winning chances are for each monster:
{ win, win, lose, win } which would end up looking like 25%, 25%, 0%, 25%
75/4 = 18.4% average chance

The go through the other monsters:
{ win, lose, lose, win } which would end up looking like 25%, 0%, 0%, 25%
50/4 = 12.2% average chance

{ lose, lose, lose, win } which would end up looking like 0%, 0%, 0%, 25%
25/4 = 6.1% average chance

So that average would be:

18.4 + 12.2 + 6.1 = 36.7%/3 = 12.23% average chance. Then do the same with the opposing creatures.

Say they end up with a round estimate of 18% with your 12%. So then the battle will be (from your army to theirs) 1:2 (1.5 rounded up to 2)

Heh, it might work. :p
If it's not a legit method, at least I hope to have gotten you on the right path.

~PCN

EDIT: Or even to add some specialness to the method, (such as getting bigger numbers like the 15:12), you could multiply it by 5 so the 1:2 would end up being 5:10 or with a random number like 8, so the 1:2 would be 8:16.
which is the same thing.

EDIT 2: Or even another idea, don't round-down the 18% to 12% ( how I got 1:2 ). Just keep it so you'll have (from your army to theirs) 12:18
which is closer to your ideal 15:12.

Okay, now I'm done. ;p

##### Share on other sites
Thank you very much, PCN. Yes, I meant number two. This looks interesting. One question: when deciding chances for a monster against an enemy monster, do you just compare their strengths (with bonuses) or you use random number to decide who wins?

##### Share on other sites
Not a random number. I would add up the stats ( with any stat bonuses from field or from opposing monster ) and compare the two both from health, endurance, all the way to attack and see who is greater ( this also eliminates the actual win. A dragon with health of 20 and strength of 6 compared to a troll with health of 10 and strength of 7; the dragon would have the obvious advantage, BUT that is with a assuming. Something could happen to later enhance the troll's attack or greatly reduce the dragon's health. )

So like I said:
Quote:
 I would add up the stats ( with any stat bonuses from field or from opposing monster ) and compare the two both from health, endurance, all the way to attack and see who is greater

Good luck!
;p

##### Share on other sites
There are only two parameters relevant to comparing units - strength and strength bonus vs type of unit.

But then if you have just one golem vs one dragon in the whole battle (1v1 battle) (in our system, golem is stronger than dragon), the ratio is 100:0 which isn't right.

##### Share on other sites
It makes sense, you're only calculating the chance of winning from two armies.

One army has 1 unit and so does the other.

The 1 unit apparently has more chance of winning and the dragon does not, therefore 100:0, but maybe in your method you need to make sure it never goes below 0, so make it return a 1 instead.

Are you wanting something else returning? As in something like: 32:20?
Maybe for one-on-ones you'd just compare the creature's total:

troll health: 20, attack 8 ( 20h+8a+0bonus = 28 )
dragon health: 17, attack 7 ( 17h+7a+0bonus = 24 )

Instead of the obvious 100:0, you'd receive 28:24 which goes down to 14:12, where you could stay if you wanted, or could bump down to 7:6.

I hoped I helped again. ;p

##### Share on other sites
You're indeed helping us. But 100:0 nor 100:1 are unacceptable. One golem vs one dragon must result in a ratio of 10:5 - 2:1. Because they both have the strength 5 and the golem has a bonus vs the dragon (which doubles his strength). And again, we have only strength, no hitpoints.

EDIT: Sorry, I screwed up the ratio.

[Edited by - Zajoman on June 27, 2008 2:17:19 PM]

##### Share on other sites
So are all of the problems then fixed?

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011726
• ### Who's Online (See full list)

There are no registered users currently online

×