• Dear forum visitor,

    It looks as though you have not registered for a forum account, or are not signed in. In order to participate in current discussions or create new threads, you will need to register for a forum account by clicking on the link below.

    Click here to register for a forum account!

    If you already have a forum account, you can simply click on the 'Log in' button at the top right of your forum screen.

    Your Elvenar Team

Count of scoutable provinces in a said ring ?

Shyama1

Active Member
Hi all,

Is there among us any smart mathematician/statistician who knows how to determine the count of scoutable provinces in a said ring ?

By "scoutable province" I mean provinces that are not cities. And "ring" means distance from my city.

In exemple: how many scoutable provinces are there in ring 16 (or if you prefer: how many scoutable provinces are 16 provinces away from my city ?)

Any help on the matter would be greatly appreciated ;)

Shyama1
 

Pheryll

Set Designer
It is fairly easy. Each ring increases by 6 from the previous ring. These 6 are either all city squares or all province squares.

Ring 1: 6 provinces, 0 cities
Ring 2: 6 provinces, 6 cities
Ring 3: 12 provinces, 6 cities
Ring 4: 18 provinces, 6 cities
Ring 5: 18 provinces, 12 cities
Ring 6: 24 provinces, 12 cities
Ring 7: 30 provinces, 12 cities
Ring 8: 30 provinces, 18 cities
Ring 9: 36 provinces, 18 cities
Ring 10: 42 provinces, 18 cities
Ring 11: 42 provinces, 24 cities
... and so on

So 16 rings would come out to 546 provinces.
 

Shyama1

Active Member
I coded a simple function that calculates the number of provinces and cities of each ring, as well as the total provinces and total cities, for a said number of rings.

I'm sharing it as it may be useful to some players who like to dig in game mechanisms, and automate some calculations, as I do ;)

Here is the code:
PHP:
<?
/*
    buildrings.php
    counts number of cities and provinces of each ring
    requires number of rings to process as parameter #1
    returns rings array
*/

define("BR","\r\n");

function buildrings ($ringsnum) {
    $rings=array();
    $cities=0;
    $provinces=0;
    $tcities=0;
    $tprovinces=0;
    for ($i=1; $i<=$ringsnum; $i++) {
        $test=$i+1;
        if ($test % 3 === 0) $cities+=6; else $provinces+=6;
        $rings[$i]=array('cities'=>$cities,'provinces'=>$provinces);  
        $tcities+=$cities;
        $tprovinces+=$provinces;
    }
    // we store total cities and provinces in $rings[0]
    $rings[0]=array('tcities'=>$tcities,'tprovinces'=>$tprovinces);  
    return $rings;  
}

// === test function ===
$ringsnum=$argv[1];
$rings=buildrings($ringsnum);

echo BR;
print_r($rings);
echo BR.'Rings: '.$ringsnum.BR.'Total Cities: '.$rings[0]['tcities'].BR.'Total Provinces: '.$rings[0]['tprovinces'].BR;

?>


And here is the function output for 16 rings (note that $rings[0] contains the total cities and provinces for the 16 rings)
Code:
D:\Games\Elvenar\_Scripts_\Tournaments>php buildrings.php 16

Array
(
    [1] => Array
        (
            [cities] => 0
            [provinces] => 6
        )

    [2] => Array
        (
            [cities] => 6
            [provinces] => 6
        )

    [3] => Array
        (
            [cities] => 6
            [provinces] => 12
        )

    [4] => Array
        (
            [cities] => 6
            [provinces] => 18
        )

    [5] => Array
        (
            [cities] => 12
            [provinces] => 18
        )

    [6] => Array
        (
            [cities] => 12
            [provinces] => 24
        )

    [7] => Array
        (
            [cities] => 12
            [provinces] => 30
        )

    [8] => Array
        (
            [cities] => 18
            [provinces] => 30
        )

    [9] => Array
        (
            [cities] => 18
            [provinces] => 36
        )

    [10] => Array
        (
            [cities] => 18
            [provinces] => 42
        )

    [11] => Array
        (
            [cities] => 24
            [provinces] => 42
        )

    [12] => Array
        (
            [cities] => 24
            [provinces] => 48
        )

    [13] => Array
        (
            [cities] => 24
            [provinces] => 54
        )

    [14] => Array
        (
            [cities] => 30
            [provinces] => 54
        )

    [15] => Array
        (
            [cities] => 30
            [provinces] => 60
        )

    [16] => Array
        (
            [cities] => 30
            [provinces] => 66
        )

    [0] => Array
        (
            [tcities] => 270
            [tprovinces] => 546
        )

)

Rings: 16
Total Cities: 270
Total Provinces: 546

D:\Games\Elvenar\_Scripts_\Tournaments>


Many thanks again Pheryll, without your clear explanation this wouldn't have been possible...

I know it will be of very limited use, but if it helps one person only, then I will be happy !
Have a great sunday all :)
 

Shyama1

Active Member
Step 2

Using the buildrings() function described in the above post, I coded another function, provinces(), that calculates the number of provinces completed by a player from their World Map Progress.

From this total provinces, we can calculate the average number of provinces/tourney, which can be useful.

But, while the total provinces is rather accurate, keep in mind the provinces/tourney is an average, provinces are never evenly spread between different tourneys, there can be variations of 5~15%.

Here is the code:
PHP:
<?
/*
    provinces.php
    Computes Total Number of Provinces and Average Provinces/Tourney
    based on a player World Map Progression      
    Takes the player's World Map Progression and the rings layout as input parameters
    Returns the total number of provinces and current ring the player reached              
*/

define("BR","\r\n");

function buildrings ($numrings) {
    $rings=array();
    $cities=0;
    $provinces=0;
    $tcities=0;
    $tprovinces=0;
    for ($i=1; $i<=$numrings; $i++) {
        $test=$i+1;
        if ($test % 3 === 0) $cities+=6; else $provinces+=6;
        $rings[$i]=array('cities'=>$cities,'provinces'=>$provinces);  
        $tcities+=$cities;
        $tprovinces+=$provinces;
    }
    // we store total cities and provinces in rings[0]
    $rings[0]=array('cities'=>$tcities,'provinces'=>$tprovinces);  
    return $rings;  
}

function provinces ($wmp,$prings) {
    $score=0;
    $provinces=0;
    $result=array();
    $ring=1;
    $done=false;  
    while (!$done) {
        $score+=$ring*8;
        $provinces++;
        $prings[$ring]--;
        if ($prings[$ring] == 0) $ring++;
        if ($score+$ring*8 >= $wmp) $done=true;  
    }
    $result['provinces']=$provinces;
    $result['ring']=$ring;
    return $result;
}  

// === test functions ===

$numrings=30;
$rings=buildrings($numrings);
$prings=array();
for ($i=1; $i<=$numrings; $i++) $prings[$i]=$rings[$i]['provinces'];
$wmp=$argv[1];
$result=provinces($wmp,$prings);
$tprov=$result['provinces'];
$aprov=number_format($tprov/9,1);
$curring=$result['ring'];
echo BR.'Total provinces: '.$tprov.BR.'Average provinces/tourney: '.$aprov.BR.'Current Ring: '.$curring.BR;

?>


And here is the function output for my World Map Progress:
Code:
D:\Games\Elvenar\_Scripts_\Tournaments>php provinces.php 48336

Total provinces: 548
Average provinces/tourney: 60.9
Current Ring: 17

D:\Games\Elvenar\_Scripts_\Tournaments>


I just started working on Step 3, but this part will require lot more work...
 
Last edited:

Deborah M

Oh Wise One
Wow! That sounds like a lot of work. I haven't kept it up recently but I have a simple spreadsheet with rings of different light colors. Letter o = scouted & letter x = neighbors to visit. Then simple =countif formula for x's & o's. I just set columns to 4 to match rows. It worked well for me back before they made that GREAT improvement showing very easy, easy, medium, hard & very hard. Of course you can also see # scouted in the research tree.
 

Shyama1

Active Member
Wow! That sounds like a lot of work. I haven't kept it up recently but I have a simple spreadsheet with rings of different light colors. ....

So far it was very quick work (10~15 lines of code for each function, posting them took more time than coding them) :cool:

The purpose here is to know any other player's count of completed provinces ... and thus how many provinces they can do at max in a tourney.

Next step is gonna be more work indeed ...
 
Last edited:

Deleted User - 3932582

Guest
I coded a simple function that calculates the number of provinces and cities of each ring
You can calculate these numbers directly if needed (in pseudocode, you can pick your preferred language).

So if N is a ring number, then just for this ring:

Code:
nCities = 6*round(N/3)
nProvinces = 6*N - nCities

And for all rings up to an including N:

Code:
nCities = 6*round(N*(N+1)/6)
nProvinces = 3*N*(N+1) - nCities
 

Deleted User - 3932582

Guest
And while we're at that, the second problem also has a pretty accurate analytical approximation. So again, N is a ring number - except we don't require it to be integer. With that, WPS can be calculated like this:

Code:
WPS = 32/3*N^3 + 16*N^2 + 16/3*N

If WPS is a given, then we can solve for N. It requires solving this cubic equation either analytically or iteratively.

So if WPS is 48336, then N is 16.0531. Then

Code:
currentRing = roundup(N) = 17
nProvinces = 2*N*(N+1) = 548
nProvincesPerRelic = nProvinces / 9 = 60.8

I'd say this is pretty accurate ;)
 

Shyama1

Active Member
You can calculate these numbers directly if needed (in pseudocode, you can pick your preferred language).

So if N is a ring number, then just for this ring:

Code:
nCities = 6*round(N/3)
nProvinces = 6*N - nCities

And for all rings up to an including N:

Code:
nCities = 6*round(N*(N+1)/6)
nProvinces = 3*N*(N+1) - nCities

That's smart :) thanks for sharing
But the provinces() function needs values for all rings, so it required a loop on rings anyway...
 

Shyama1

Active Member
And while we're at that, the second problem also has a pretty accurate analytical approximation. So again, N is a ring number - except we don't require it to be integer. With that, WPS can be calculated like this:

Code:
WPS = 32/3*N^3 + 16*N^2 + 16/3*N

If WPS is a given, then we can solve for N. It requires solving this cubic equation either analytically or iteratively.

So if WPS is 48336, then N is 16.0531. Then

Code:
currentRing = roundup(N) = 17
nProvinces = 2*N*(N+1) = 548
nProvincesPerRelic = nProvinces / 9 = 60.8

I'd say this is pretty accurate ;)

Interesting indeed ! How do you solved the cubic equation ?

There are many different ways of coding that will give the correct result. It mostly depends on the coder way of thinking I guess.
 

Deleted User - 3932582

Guest
Interesting indeed ! How do you solved the cubic equation ?
You can look up general formula for cubic equations on Wikipedia:
https://en.wikipedia.org/wiki/Cubic_function#General_formula

But in this particular case we can make a few more simplifying assumptions, and come up with something pretty simple (slightly less accurate due to dropping a term that is only meaningful for extremely low WPS:

Code:
N = 0.45428*WPS^(1/3)-0.5

WPS^(1/3) means cube root of WPS. Then you can use N in the formulas above.
 

Deborah M

Oh Wise One
One problem. A lot of us old timers don't do code. Having lived in the world of Accounting & spreadsheets for 40+ years, spreadsheets rule :p I've lived in spreadsheets since Lotus 123 came out on Unix :eek: I've even got spreadsheets for a whole lot of things in this game. Retired but old habits die hard. Anything coding beyond simple macros goes right over my head :oops:

This reminded me. Just for giggles I looked to see if I still had a copy of Lotus 123. Yup :rolleyes: Right there with my son's copy of the first 3D game (intro only) and a Voodoo 3 video card. Wow! LOL!
 
Last edited:

Deleted User - 3932582

Guest
One problem. A lot of us old timers don't do code. Having lived in the world of Accounting & spreadsheets for 40+ years, spreadsheets rule :p I've lived in spreadsheets since Lotus 123 came out on Unix :eek: I've even got spreadsheets for a whole lot of things in this game. Retired but old habits die hard. Anything coding beyond simple macros goes right over my head :oops:
Then you can use the formulas that I posted above. They would easily work in Excel directly.
 

Shyama1

Active Member
You can look up general formula for cubic equations on Wikipedia:
https://en.wikipedia.org/wiki/Cubic_function#General_formula

But in this particular case we can make a few more simplifying assumptions, and come up with something pretty simple (slightly less accurate due to dropping a term that is only meaningful for extremely low WPS:

Code:
N = 0.45428*WPS^(1/3)-0.5

WPS^(1/3) means cube root of WPS. Then you can use N in the formulas above.

This is very instructive, and I'm glad you shared this cause I learned something new :)

but honestly your analytical way looks so abstract to me :confused:... I tend to code what I call the "natural way" which is what I would do if I had to do things manually. It sticks to something concrete, to the reality.

I'm also curious to see which way is faster for the computer, so I'm gonna code buildrings() your way and compare the time it takes to calculate 1000 rings with both methods... I'll let you know ;)


One problem. A lot of us old timers don't do code. Having lived in the world of Accounting & spreadsheets for 40+ years, spreadsheets rule :p I've lived in spreadsheets since Lotus 123 came out on Unix :eek: I've even got spreadsheets for a whole lot of things in this game. Retired but old habits die hard. Anything coding beyond simple macros goes right over my head :oops:

This reminded me. Just for giggles I looked to see if I still had a copy of Lotus 123. Yup :rolleyes: Right there with my son's copy of the first 3D game (intro only) and a Voodoo 3 video card. Wow! LOL!

I've been coding for the past 35 years... this is part of my job. I started coding before the 1st PC was released, working on what they called "micro-computers" in the 80's, and was the size of a washing machine and consuming 5 kW :eek:. Like the Micro-VAX II from Digital, running VAX/VMS OS.

I also have plenty of useful spredsheets for Elvenar, they are of great help, but some projects require coding (especially those using a database) and this is where I like using the so powerful PHP in command-line mode under windows. Once a project is completed I sometimes turn it into a web app if appropriate.
 

SunsetDanar

Well-Known Member
I was a computer science major in my early college years (Late 60's, 0-1 if then days) but gave it up for another major. I'm a spreadsheet guy. You can find danged near anything, on any subject or anything reasonably related to what you're seeking on a spreadsheet. I've had enough math to understand that the hex shapes can offer up some interesting options for coding but the plus six, plus six that Pheryll offers makes this thread obsolete.
 

Deleted User - 3932582

Guest
but honestly your analytical way looks so abstract to me :confused:..
Of course it looks abstract, I skipped all the derivation and just wrote the final answer ;)

As much as I like brute force approaches (usually easy to implement, pretty readable), they have their limitations. Analytical solutions/approximation do not always exist, but when they do, they offer ability to do certain things that is difficult/impossible to do in pure functional implementations. For instance, it is obvious that number of provinces grows as square of number of rings, while WPS grows as cube. This is not something that is easily observable from functional implementation.

Analytical solutions are easy to differentiate, which is very useful in many instances, etc. These are also easy to implement in a spreadsheet ;)

Speed of execution in this particular case is not a material concern - while there would be differences, for the number of rings that can realistically be achieved (a few dozens at most) time to calculate by either method would for all practical purposes be zero. Unless you're running zillions of those calculations for whatever reason.
 
Top