Log in

No account? Create an account
entries friends calendar profile Previous Previous Next Next
Perlish solutions to problems - Ed's journal
Perlish solutions to problems
Well, that problem I mentioned.
I cracked and went perl hacker on it.


use warnings;
use strict;

my $number_of_ships = 50;
my $damage_soaked = 5;
my $number_of_guns = 40;
#my $number_of_guns = 10;
my $gun_damage = 1;
#my $gun_damage = 4;
my $iterations = 0;
my $result_sum = 0;
my $total_loops = 1000;
my $first_round_kills =0;

my @ships;

for ( my $loopcount=0; $loopcount <$total_loops; $loopcount++)
  #create a 'fleet array' of ships
  for ( my $n = 1; $n <= $number_of_ships; $n++ )
    push @ships, $damage_soaked;

print "starting fleet ", join(":", @ships ), "\n";

#repeat till they're all GONE.
while ( $#ships >=0 )
  for ( my $gnum =1; $gnum <= $number_of_guns; $gnum++ )
    #randomly distribute gunnery damage (they all target select at once, so 
    #overkill is possible
    $ships[rand($#ships)] -= $gun_damage;

#  print $iterations, "Outcome ", join (":", @ships ), "\n";

  my @newshiplist;

  #now take the ship list. Delete anything that's on 0 or less, and then
  #assume that those that are damaged have warped out and repaired. 
  foreach my $aship ( @ships )
#    print "S:", $aship, "\n";
    if ($aship > 0) { push @newshiplist, $damage_soaked }
  @ships = @newshiplist;

  print $#newshiplist+1, " ships survive\n";
  if (( $#newshiplist+1 < $number_of_ships ) and ( $iterations == 1 )) 
    { $first_round_kills += $number_of_ships - $#newshiplist - 1}

print $iterations, " rounds to destroy ", $number_of_ships, " ships using ", $number_of_guns, " guns doing ", $gun_damage, " damage each.\n";

$result_sum += $iterations;

print "Average iterations to destroy = ", $result_sum / $total_loops, "\n";
print $first_round_kills, "first round kills\n";

10 x 4 point guns vs. 50 '5 point soak' ships (worst possible situation for them).
Fleet is reduced to 0 in an average of 36 'rounds'. (869 ships destroyed first round, out of 1000)

40 1 point guns, vs 50 '5 point soak' gives us an average of 195 rounds. (61 ships destroyed first round).

I think that's pretty conclusive, if not quite what I had expected. (And yes, I was assuming that ships can fully repair, since the 'model' involved a gun firing on a target for 30 seconds, and then 'switching', meaning it can retreat, and return when fully healed up. (there's ways to prevent them retreating, but I'm ignoring them because they also randomly target, and are applicable to both)

However I shall return to pondering the ponderableness of this problem, because I'm sure there's got to be a formula for it ;)
12 comments or Leave a comment
mrbear From: mrbear Date: November 9th, 2005 04:26 pm (UTC) (Link)
Nice. Now add tracking. :)
sobrique From: sobrique Date: November 9th, 2005 04:28 pm (UTC) (Link)
Tracking requires dealing with variable sizes dispositions and locations of ships.
That might have to wait for another day.
ehrine From: ehrine Date: November 9th, 2005 06:00 pm (UTC) (Link)
Tracking is not the only thing missing. It doesn't factor in signature resolution. A small gun has a sig resolution of 40 compared to a large guns 400. While this means a large gun should always hit a BS, a small gun has a much higher chance of getting a "Wrecking" shot and doing more damage. As a result, I suspect that those 40 1 point guns are possible doing more then 1 point of damage. If we can find out the formula for hit type we can factor that in, but...
sobrique From: sobrique Date: November 10th, 2005 09:26 am (UTC) (Link)
I'm not convinced. I have a feeling that 'wreckings' are a simple percentage chance (although they did amend the logic so if you'd miss, you didn't wreck, which does have implications).

sobrique From: sobrique Date: November 10th, 2005 10:29 am (UTC) (Link)
From a bit of faffing around with the tracking calculator, it would appear that radius/resolution is a direct multiplier on the 'transverse' of a target.

So a gun with a tracking equal to their angular velocity will hit 50% of the time if signature resolutions are equal. Half their signature radius and it drops to 6.25%. Exactly the same as if you'd doubled their transverse. Half their transverse and you get that 50% again.

Gun with a '500m/sec @ 50km tracking and 400m signature resolution' will hit 50% of the time against a target moving at 500m/sec with a 400m radius.
At 200m radius that drops to 6.25%. At 400m radius and 1000m/sec transverse it's also 6.25m/sec. At 800m radius and 1000m/sec transverse it's 50% again. Still don't know the formula mind, it seems to have disappeared off the ships and modules board.

What this means is against a BS at a 100m/sec transverse a large gun doesn't hit 100% (it's about 84% peak). But of course, a small gun does.

From: apostle13 Date: November 10th, 2005 12:51 pm (UTC) (Link)
OK, not knowing the many intricacies of this game has limited my analysis somewhat.
i) For me it is a one-sided simulation, since I have no data on if/how ships destroy guns.
ii) I have assumed a sequential approach to each gun barrage (to minimise the flaws inherent in adopting a random targeting strategy).
iii) I have not considered repairing, have used 100% hit accuracy across the board etc.
However, I re-ran the code in C on another platform and stand by the argument for smaller guns. Big ain't necessarily better.

Consider this slightly heuristic approach:
A big gun deals 4 points, and a small 1. If a ship needs 6 points to be removed, then 6 hits from a small gun or 2 hits from a big gun are required. Here's the important bit - on the second shot, the killing blow, only 2 points are needed but 4 are delivered - the big gun has essentially "wasted" 2 points of damage; when using small guns, *every* hit counts and no points are "wasted". This makes the analysis highly sensitive to multiples of 2 and 4 regarding ship damage, i.e. a ship needing 8 points to destroy makes all guns equally efficient, and in the 6 point example, small and medium guns would be equally efficient. Away from these multiples, small guns win out, although not by much against small fleets (10-40).

I have a 50 strong fleet going down (all ships destroyed) after about 11 big gun barrages, but only 10 small gun barrages (using 10 and 40 guns respectively).
However, the counter-balance is that the big guns will take down their first ship after only 1 or 2 barrages, whereas the small guns require about 3 to 5. This can have a great effect when morale is considered.

As an analogy, consider big guns to be the equivalent of heavy cavalry or shock troops, while the small guns are infantry. For shock value in an assault, cavalry are ideal, but when it comes to the battle overall, as things draw out, the steady pounding of the infantry is going to dominate.

From this more general approach, I would recommend the bulk of your artillery be small guns, supplemented by some big guns for shock value; a strategy for deploying medium guns probably depends on other factors, such as what sort of losses are likely to occur within your gun ranks (I know nothing about this regarding this game - adjust accordingly - personally, I would be tempted to suggest that these light cavalry equivalents are probably unnecessary).
So the tenets of traditional warfare for an open field battle should apply, since this seems to be a reasonably equivalent scenario - mostly infantry, some cavalry.
Alternatively, fort defence tactics can be analogised: a base of some heavy artillery, supplemented by more and more light artillery (increased in proportion to the size [in volume i.e. numbers] of the attacking force).

A caveat would be that if the attacking fleet has a high proportion of battleships (big ships), you might want more big guns to get that all important first target down in a short enough time, but with the lack of being able to implement any targeting strategy, this will be very difficult to gauge.
And just as you are calculating the optimum defence strategy, people will be calculating the optimum fleet composition to exploit it ;-)
When it comes to mobile ships versus emplaced guns, this can often be difficult to deal with! A home guard fleet nearby acting as a reserve might well be the best strategy. Like many things, image will usually be pretty important - fly a few battleships of the highest quality (your manowar) with lots of cruisers to beef up the numbers, so that you look suitably imposing in terms of both quality (ship of the line) and quantity (fleet size) to keep your enemies at bay. (This pretty much paraphrases the prior tactics - some heavy cavalry supplementing a bulk infantry).
From: apostle13 Date: November 10th, 2005 12:53 pm (UTC) (Link)


So there you go - an "outsider" perspective on your problem; to be honest, warfare is warfare - similar rules will apply for the most part regardless of the setting.
The trick then is to see where the game does deviate from these rules, and exploit those areas, but the scenario you are describing seems fairly "traditional" i.e. not too far removed from open field battles, assaults and sieges.
Forget the battlefield probabilities; if this is a multi-player game then battlefield psychology will likely be far more important!

<<< Trust me to discover that there is a limit on posting sizes - will waffling be an Olympic event when the games arrive in London, do you think?
mister_jack From: mister_jack Date: November 9th, 2005 04:31 pm (UTC) (Link)
Huh? Out of 50 ships, 869 are destroyed in the first round?
sobrique From: sobrique Date: November 9th, 2005 04:35 pm (UTC) (Link)
Out of 1000 iterations, with waves of 50 ships, 869 are lost in round 1. (ginve a probability of 87% of a round 1 kill, which is a lot more than I thought)
mister_jack From: mister_jack Date: November 9th, 2005 04:39 pm (UTC) (Link)
Ah, gotcha.
tomf_ From: tomf_ Date: November 9th, 2005 11:06 pm (UTC) (Link)
Which just proves, it's always better to have bigger guns.
velvet_nothing From: velvet_nothing Date: November 10th, 2005 11:57 am (UTC) (Link)
Or perhaps you're just otherwise lacking? ;O)
12 comments or Leave a comment