Skip to main content
GameDev.net gamedev.net
🔒 Locked

Battle System Solution

Started by Zajoman Jun 27, 2008 at 11:23 AM 47 replies 7.9k views
Original Post
Zajoman
Zajoman
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?
Alpha_ProgDes
Alpha_ProgDes
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?
Beginner in Game Development?  Read here. And read here.  
Zajoman
Zajoman
Quote:
Original post by Alpha_ProgDes
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?


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

Maverick Programmer
Maverick Programmer
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
Holy crap, you can read!
Zajoman
Zajoman
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?
Maverick Programmer
Maverick Programmer
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
Holy crap, you can read!
Zajoman
Zajoman
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.
Maverick Programmer
Maverick Programmer
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
Holy crap, you can read!
Zajoman
Zajoman
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]
Zajoman
Zajoman
No, because adding one skeleton of strength 1 (which the dragon has a bonus against) makes the golem army weaker. Paradox. :)
Maverick Programmer
Maverick Programmer
How does it make it weaker? The method wasn't based on size ( unless that is another major afflicting variable ) it was based to see which one would win. So a dragon versus 100 skeletons, you'd think a huge fire-breathing dragons can crush the dead, but ( according to our method ) the skeletons would most likely have the winning advantage due to stats and number. So as a mighty Zajoman once said:
Quote:

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

;p

But, how does it make it weaker? ( I'm now officially determined to get this algorithm of ours to work! I'll be here all day if need be )
Holy crap, you can read!
Zajoman
Zajoman
Quote:
But, how does it make it weaker? ( I'm now officially determined to get this algorithm of ours to work! I'll be here all day if need be )


Hehe :)) That's great. Wait a second, we are trying little variants of your approach and in one of them adding one skeleton to the golem made it weaker. Just wait a second, I'm figuring out another approach based on yours.

Maverick Programmer
Maverick Programmer
My one-on-one method was for a rare chance of one-on-one battles.

For one-on-x ( x is any number hight than 1 )
battles, I'd treat it as a typical army vs army battle ( using the first method I created )

Let me see if it works:

1 vs 4:

{ win, lose, lose, win } 25%, 0%, 0%, 25%
50%/4 = 12.2%

Now for the opposing creatures turn to calculate:

{ win } 100%
{ lose } 0%
{ lose} 0%
{ lose} 0%

0 + 0 + 0 + 100 = 100/4 = 25%

So (from 1 to 4)
that would be 12.2% to 25% or 12:15 ( or 4:5 )
but (from 4 to 1)
that would be 25% to 12.2% or 15:12 ( or 5:4 )

Note this makes perfect sense for the larger group to win, but it seems close for the single army! However, this also depends on how strong this single army is. If it's an all powerful monster:

1 vs 4:

{ win, win, win, win } 25%, 25%, 25%, 25%
100%/4 = 25.0%

Now for the opposing creatures turn to calculate:

{win} 100% //This thing is tough to have some advantage over the opposing creature
{lose} 0%
{lose} 0%
{lose} 0%

100%/4 = 25%

So it would be equal: 25:25 or 1:1
And this is fair for a single army.

[hr]
For the dragon and the golem/skeleton team:

dragon hp: 17, attack 7

Golem hp: 20, attack 8 /
Skeleton hp: 5, attack 1


dragon { lose, win } 50%, 0%
50/2 = 25%

Golem { win } 100%
skeleton { lose } 0%
100/2 = 50%

So dragon Vs Golem team-> 25:50 ( or 5:10 or 1:2 )
Golem team wins.

I like the army vs army method for one-on-x. I hope it works out for you too!
Holy crap, you can read!
CoMaNdore
CoMaNdore
Could you not add another variable into the equation called initative.

Each unit will have an unique number ( called initative from now on ). That will represent
in what order each unit will "fire".

Say you have 100 archers with initative 4 vs 10 dragons with initative 9

Its obvius that the dragons should win, but still the archers get to fire first.
(since the lower initiative the earlier they "fire").
They take out 2 dragons.

Now the 8 dragons left get to fire, they kill 120 archers.

This prosses is repeted until A - you run out of achers, B - you run out of dragson C - somebody flees or a simular action.

This is how my "armybased" mud worked back in the days at least :)
Me
Zajoman
Zajoman
Okay, so we have an army:
Golem (5)
Skeleton (1)

vs

Dragon (5)

Now, according to your proposal:
Golem vs Dragon
win = 100
100 / 1 = 100

Skeleton vs Dragon
lose = 0
0 / 1 = 0

(100 + 0) / 2 = 50 (attacker's final score)


Dragon vs Golem and Skeleton
lose win = 0 + 50
50 / 2 = 25

25 / 1 = 25 (defender's final score)


So we have a ratio of 50:25 (2:1, 66% chance to win) for the golem army, which is about right. But what happens, if we add another skeleton? See:
Golem vs Dragon
win = 100
100 / 1 = 100

Skeleton vs Dragon
lose = 0
0 / 1 = 0

Skeleton vs Dragon
lose = 0
0 / 1 = 0

(100 + 0 + 0) / 3 = 33 (att's final score)

Dragon vs Golem and Skeleton and Skeleton
lose win win = 0 + 33 + 33
66 / 3 = 22

22 / 1 = 22 (def's final score)


So the ratio is now 33:22 which is 60% for the golem army to win.

See? The chance dropped from 66% to 60%.
Maverick Programmer
Maverick Programmer
@CoMaNdore:
This is to determine ( before/at beginning of battle ) the chance ( represented as ratio ) of the armies winning. opposing:defending -> 1:2 means the opposing army has less chance of winning and the defending has the chance over the opposing. I don't think this determines anything at all except for statistics. This method rules out "who goes first" for the the opposing team of 1:2 could still win even though stats say it might not. It's just figures such as the weatherman may say there's a good chance of snow, but it doesn't. ( and I hate that ;p )
Holy crap, you can read!
Zajoman
Zajoman
Quote:
Original post by PCN
@CoMaNdore:
This is to determine ( before/at beginning of battle ) the chance ( represented as ratio ) of the armies winning. opposing:defending -> 1:2 means the opposing army has less chance of winning and the defending has the chance over the opposing. I don't think this determines anything at all except for statistics. This method rules out "who goes first" for the the opposing team of 1:2 could still win even though stats say it might not. It's just figures such as the weatherman may say there's a good chance of snow, but it doesn't. ( and I hate that ;p )


What is wrong with this? Attacking:Defending 1:2 means that the attacking army has 33% chance of winning the battle. That means, of course, that the attacker may still win. You're against randomness or what?

Zajoman
Zajoman
PCN, sorry, I misunderstood your last post. My apologies. I take it back.
Maverick Programmer
Maverick Programmer
Dragon vs Golem and Skeleton and Skeleton

dragon { lose, win, win } 0%, 33%, 33%
66%/3 == 22%

golem { win } 100%
skeleton { lose } 0%
skeleton { lose } 0%

100%/3 = 33.3%

22:33

Hmmm, let's try with more skeletons to support this:

dragon { lose, win, win, win } 0%, 25%, 25%, 25%
75%/4 == 18.75%

golem { win } 100%
skeleton { lose } 0%
skeleton { lose } 0%
skeleton { lose } 0%

100%/4 = 25.0%

19:25

More, skeletons:

dragon { lose, win, win, win, win } 0%, 20%, 20%, 20%, 20%
80%/5 == 16.0%

golem { win } 100%
skeleton { lose } 0%
skeleton { lose } 0%
skeleton { lose } 0%
skeleton { lose } 0%

100%/5 = 20.0%

16:20

I still looks like the Golem team will still win.


Holy crap, you can read!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.