Domination Game

Status: Logged Out

Forum » View

Calculations

krang

Saturday 14th October 2006, 18:34 GMT
Ok, for those mathematically minded people who like to number crunch, here are the calculations used in the game to determine success and battalion counts for each of the actions.

Please note they will probably change, so these are correct as of 14th October 2006.



##########################################
##########################################

Reinforcements:
------------------------------------------
$max = 5 + floor($territoryCount / 2);
if ($max > 10) {
   $max = 10;
}

$max += $startTerritoryReinBonus;

$reinReceived = rand(2, $max);
------------------------------------------

##########################################
##########################################

Attack:
------------------------------------------
$prob = ceil(($actionBattalions / $actionToBattalions) * 200); // Half of 400

if ($prob > 360) $prob = 360;
$prob += ($actionFromAttackBonus * 4);
$prob -= ($actionToDefendBonus * 4);
if ($prob < 1) $prob = 0;

$success = ($prob > rand(0, 400));
------------------------------------------


Attack winning survivors:
------------------------------------------
$survivors = rand(floor($actionBattalions / 3), $actionBattalions);
if ($survivors < 1) {
   $survivors = 1;
}
------------------------------------------


Attack losing survivors:
------------------------------------------
$attackingSurvivors = rand(0, ceil($actionBattalions / 4));

$min = $actionToBattalions - ($actionBattalions * 3);
$max = $actionToBattalions;

$defendingSurvivors = rand($min, $max);
if ($defendingSurvivors < 1) {
   $defendingSurvivors = 1;
}
------------------------------------------

##########################################
##########################################

Conquer:
------------------------------------------
$prob = $actionBattalions * 5;
if ($prob > 90) $prob = 90;
$prob += $actionFromConquerBonus;

$success = ($prob > rand(0, 100));
------------------------------------------


Conquer survivors:
------------------------------------------
if ($success) {
   $survivors = rand(floor($actionBattalions / 2), $actionBattalions);
} else {
   $survivors = rand(0, ceil($actionBattalions / 4));
}

if ($survivors == 0) {
   $success = false;
}
------------------------------------------

##########################################
##########################################

krang

Saturday 14th October 2006, 18:40 GMT
Also, for those wondering how the score is calculated when you win a game, this should hopefully clear up any confusion.

NOTE: thanks to "tiki" and his obsession with the square root function who came up with this one.

------------------------------------------

$score = (1000 + (128 * sqrt(2 * sqrt(2 * sqrt(($delayAction * $delayAction) + ($delayAction * $delayReinforcements))))));

$score = round(($totalTerritories * $score) / (32 * $membersPlaying));

$score = ($score >= 0 ? $score : 0);

$score = $score + 1000;

------------------------------------------

krang

Tuesday 17th October 2006, 18:42 GMT
Just got an email from "wy_mentat" suggesting that the conquer calculation included the number of battalions you start with in a game (the more start battalions, the harder it is to conquer) and/or it could include the current number of territories owned (the more territories you own, the harder it becomes to conquer).

When adding them together, the calculation will become something like:

------------------------------------------
$prob = (($startBattalions / 4) + ($territoryCount / 2) + 5);
$prob = $actionBattalions / ($prob * 100);
if ($prob > 90) $prob = 90;
$prob += $actionFromConquerBonus;

$success = ($prob > rand(0, 100));
------------------------------------------

I know "tiki" was cooking something up on this as well (I think it involved the square root function)... but I have forgotten the outcome (sorry tiki).

Has anyone got comments or suggestions?

tiki

Friday 20th October 2006, 5:28 GMT
Just to let you know, I've been experimenting with algorithms.

I've come up with an equation that sets 1=1.
((xy^x)/x)^(1/x) or something like that so far.

The advantage over the current linear equation becomes apparent from a ratio of starting battalions... It's in progress.

tiki

Monday 23rd October 2006, 17:24 GMT
Would you be afraid of a reduced success rate, by any chance? It could make the curve slightly more noticable, as if I keep with the 5% conquer success line it is not as apparent.

krang

Monday 23rd October 2006, 18:49 GMT
I would personally like to keep the conquer action fairly easy, but do what you want, then lets see what the other members think... at the end of the day, everyone will be using the new calculation, so it should remain "fair".

tiki

Tuesday 24th October 2006, 18:14 GMT
Here's DemoAlgorithm No. 1:

z=(ln(((x*e)^(x))/x)^-1)*(2/(y))+(x/y)
x_Max=y-1
x_Min=1

x=Battalions Sent
y=Starting Battalions
z=Chance Of Success /1

I hope you understand what I intend by all of this.

By the way, you should have a message to log in if you attempt to post after your session has expired, instead of blankly bringing you back to the thread without a post having been made.

tiki

Tuesday 24th October 2006, 20:33 GMT
Yoinks. The extremes kill that one.

Here's DemoAlgorithm No. 1.5
z=2((arctan(x-(y/2))+1)+((1/x)^(-1/2)))/y

This one is not done, by the way.

tiki

Wednesday 25th October 2006, 23:38 GMT
Ok, I'm done.
I mean truly done. I don't think it could get any better.

Here's DemoAlgorithm No. 2.0
z=(((arctan((32x/(y+32))-2pi)+(pi/2))/pi)-sqrt(1/x)+1)/2

x=Sent Battalions
y=Starting Battalions
z=Success Rate (out of 1)

tiki

Friday 27th October 2006, 1:40 GMT
Got Violence?

Here's my attack-defend algorithm.
I think it's quite beautiful...
Simple, sweet, and eerily accurate.

z=x/sqrt(x^2+y^2.25)

x=Attacking Battalions Strength (after adjustment)
y=Defending Battalions Strength (after adjustment)
z=Attacker's Success Rate (out of 1)

Attack/Defend Bonus Adjustments. Normal max is 125%:
x=ABattalions+(ABattalions*ABonus/16)
y=DBattalions+(DBattalions*DBonus/16)

And here's an adjustment for the last algorithm I posted.
It's for the conquering/scouting bonus. Normal max is 150%:
x=SBattalions+(SBattalions*SBonus/8)

So, Krang, do you want me to make a pathetic effort at transforming these to code?

wy_mentat

Friday 27th October 2006, 20:37 GMT
Game is unbalanced. It's too easy to attack, and win country against overwhelming battalions. I havent got time to calculate/test current attacking code. But I think there's something wrong. for example: It's easy to take enemy 25 defending units down, when I attack with 10 units, and send them to attack singly. By this way enemy will take casuality from 2 to 6 (even more) on every attack. And some of my 10 units arrives back to attacking country - More bonus?
Unfair?
It's getting really annoying, to keep hundreds of units in defense, against 20 or something battalions.

I think there should be some simple rules to balance the situation. Something like that? Any

thoughts?

x - attacking battalions
y - defending battalions

(1) attacker chance to win country (attack):
if (x*2 < y) $prob = 0;

(2) defender max loss should always equal x (in case of winning battle)

(3) attacker chance to get any survivors after loosing (attack) battle:
if (x*4 < y) $prob = 0;

tiki

Friday 27th October 2006, 23:50 GMT
Hmmm...

When it comes to the chance of success, you should plug in a few numbers into my equation and see what you come up with. I believe it to be quite accurate, and you should know that in reality, even if X is less than half of Y, it should still have a chance to win.

If ten battalions attack twenty, in my equation, there's just under 1/3 chance of victory.

And there's also an interesting trend in my equation: If one hundred battalions attack two hundred, there is under 1/4 victory probability. More battalions are harder to defeat, even if you have more battalions as well.

It can handle the largest numbers without a fixed limitation, too.

tiki

Friday 27th October 2006, 23:51 GMT
I agree with you somewhat on point 2, but not entirely. I will put forth losses equations soon, and will take into factor the amount sent by the attackers. Limited to 1-1 maximum ratio for losses, I think not... a single brave battalion could kill twice its worth.

Zero chance, I think not (yet again). I try to avoid thinking in absolutes. My equation allows 1 group of 15 battalions a better chance than 15 groups of 1...giving reasons to send more.

wy_mentat

Saturday 28th October 2006, 16:20 GMT
In real world, there is 'never' considered to attack a twice larger army. Defending army always has bonus (due to defending structures, or omething like that). Because of that in real world attacker unit must be 3 (least 2) times bigger. Though Its might be possible to win with smaller army, but attacking unit will not stay viable, due to big losses.

tiki

Sunday 29th October 2006, 23:52 GMT
There needn't be a consideration for the target's size, though. Only that they defend appropriately.

Ambushes, distractions, and small raids to keep pressure up are common without intent to take the territory. The chances of success are so tiny that you may never encounter a success in your battles of an outnumbered force, but it's still there as chance.

tiki

Monday 30th October 2006, 0:29 GMT
Kyehehe, algo no. 3 is ready.
We need reinforcements!

z=round(ln(x)+sqrt(x)+(x/16)-(1/16)+randInt(1,4)+randInt(0,RBonus)+sqrt(y))

x=Territories Owned
y=Starting Battalions
z=Battalions Gained

tiki

Monday 30th October 2006, 20:51 GMT
The death of a single battalion is a tragedy. The death of a thousand is a statistic. Here's the alpha for combat losses.

z=irand(0:round(((x^2)/(x+y))+1))
w=y-irand(0:round(1.5(x-z))

x=Loser's Initial Battalions
y=Winner's Initial Battalions
z=Loser's Resultant Battalions (0 for defenders)
w=Winner's Resultant Battalions

tiki

Monday 30th October 2006, 20:55 GMT
(Mentat, if you will notice I have taken a lesson from your suggestion #2. The maximum defender's loss is equal to 1.5 the attacker's losses.)

wy_mentat

Tuesday 31st October 2006, 8:44 GMT
Nice code, but I like it more this way:

x=attacker's Initial Battalions
y=defenders's Initial Battalions
z=attacker's Resultant Battalions
w=defenders's Resultant Battalions (0 for defenders, if loosing battle)

z=irand(0:round(((x^2)/(x+y))+1))
w2=irand(0:round(1.5*((y^2)/(x+y))+1))
if w>y, then w=y, othervise w=w

and lets add winning/loosing conditions:

IF Z<W 'defender wins'; W=W
IF Z>W 'attacker wins'; W=0

otherwords, if 1000 units attacks 250 defending units,
then attacker 'max' resultant battalions are 801
and defender max resultant battalions are 76,
in which case is about 90,5% probability, that attacker wins.

IF x=1000 y=500
then max(y) is 668 and max(z) 251,
62,4% attacker wins

IF x=1000 y=1000
then max(y) is 501 and max(z) 751,
33,3% attacker wins

IF x=500 y=1000
then max(y) is 168 and max(z) 1000,
16,8% attacker wins

IF x=250 y=1000
then max(y) is 51 and max(z) 1000,
5,1% attacker wins

nice and simple

wy_mentat

Tuesday 31st October 2006, 8:45 GMT
sry, mistake

IF x=1000 y=500
then max(z) is 668 and max(w) 251,
62,4% attacker wins

IF x=1000 y=1000
then max(z) is 501 and max(w) 751,
33,3% attacker wins

IF x=500 y=1000
then max(z) is 168 and max(w) 1000,
16,8% attacker wins

IF x=250 y=1000
then max(z) is 51 and max(w) 1000,
5,1% attacker wins

wy_mentat

Tuesday 31st October 2006, 12:53 GMT
sry, another mistake

IF x=1000 y=250
then max(z) is 801 and max(w) 76,
91,3% attacker wins

IF x=1000 y=500
then max(z) is 668 and max(w) 251,
72,7% attacker wins

IF x=1000 y=1000
then max(z) is 501 and max(w) 751,
40.0% attacker wins

IF x=500 y=1000
then max(z) is 168 and max(w) 1000,
14,4% attacker wins

IF x=250 y=1000
then max(z) is 51 and max(w) 1000,
4,9% attacker wins

tiki

Tuesday 31st October 2006, 17:49 GMT
Kraaaaaang, what's the name for starting battalions?
I'm using $startBattalions for a guess.

W. Y. Mentat, as reasonable as your method computes, it stands on the grounds of limitation. It seems logical for surviving battalions to determine a victory, however the generals are the ones who decide when to retreat and when to advance. A superior force may well retreat from a smaller one if the smaller force strikes victory in the first engagements. And after those first engagements the attacker may be undersupplied. But I do agree with the link between the blood of both sides... that's the only solid limitation of chance that I shall accept when I put forth my proposed code for the administration revision and testing. Your code is indeed quite intelligent for prediction, but other factors have the tiny potential of screwing the prediction up.

tiki

Tuesday 31st October 2006, 18:13 GMT
Kraaaaaang, what version of PHP are you using?

krang

Tuesday 31st October 2006, 19:52 GMT
Hi tiki and wy_mentat,

Thank you for taking your time to consider improvements to these calculations, however I am starting to worry about the complexity... if possible, I would like the ability for members to-do the calculations in their heads (something that might not be possible with the 'square root' function).

Although I do understand that just using simple maths might be too restrictive.

Anyway, tiki, the $startBattalions does not exist at the moment, but I should be able to create one... at the end of the day this is a variable just like how 'wy_mentat' is using x, y, z, etc.

As to the PHP version, its currently 4.4.4, but I am getting ready to upgrade to 5 (delays not because of compatibility problems, just lack of time on my part)... although I do prefer to keep the scripts capable of running on 4.1 systems (just in case I need to move over to shared hosting).

wy_mentat

Wednesday 1st November 2006, 7:39 GMT
Well I leave that code thing.
I Think, my last suggestion isn't good either.
Problem for example, if one unit attacks one defending unit, both survives, nothing happens.

btw, I'm still convinced, that defending should be a lot easier, than attacking. Of course, it shouldn't be so easy, that game will freeze. It's hard.

So Krang, Tiki. Keep up, make code work better.

tiki

Thursday 2nd November 2006, 1:10 GMT
I've submitted some blocks of code for revision...

A successful defence should yield (2/3 of the time) fewer losses than the attacker experiences, randomly from 0 to 1.5 times the losses experienced by the attacker. Good-Defence territories weaken an enemy's attacking strength, and Good-Offence territories enhance it. Good-Defence territories also lose fewer battalions if they have successfully defended.

Conquer levels have two optimal peaks if you wish to absolutely conquer them, but a good guess for the higher hump is take 1/4 the starting battalions and add ten. That number should be decently high enough to conquer with a good majority of the time. Good-Scouting territories advance the strength up to 150% the original sent battalions' strength.

And you may actually receive more reinforcements with higher starting battalion counts, as your population is more motivated to participate in the epic war.

tiki

Thursday 2nd November 2006, 1:34 GMT
(By the way, it's sortof a secret amongst the eldest players that every territory has unique strengths.)

In an earlier version of Domination, these strengths were listed in a long table for the public to see in the Game Info section. Only the World map existed at that time. There are still four acting categories of bonuses, usually ranging from 0-4 in intensity.

Reinforcements - Gives chance of more battalions per search
Strong Example: Irkutsk
Weak Example: Kamchatka

Scouting - Increases successful conquering probability
(I don't remember any numbers. Currently hardly noticable.)

Offensive - Increases success probability of attacks sent from it
Strong Example: Germany
Weak Example: Poland

Defensive - Increases successful defense probability
Strong Example: Dustbowl
Weak Example: Badlands

krang

Thursday 28th December 2006, 23:56 GMT
OK, the changes have been finally approved... new calculations are in place. If you go to the "Game Info" page,  there is a "View calculations" link that shows the calculations currently in use.

NOTE: The calculations are shown using the raw PHP code that is actually used in the game! This allows you to see that there is no "funny business", nor will it create rumours that standing on one leg when searching for reinforcements will help you (otherwise you would see the "one leg" check in the code).

Also of note, on the calculations page is the territory bonuses, for those who wonder about why each territory is slightly different (my dibs are on "Iceland" for a starting territory).

Finally, a big thank you to tiki... he came up with the new calculations now in use, and continued to pester me over the past several months to get them uploaded - after doing allot of testing.

tiki

Friday 29th December 2006, 1:03 GMT
I prefer Yakutsk.