Damage Program for many Batteries

5 posts ยท Jan 13 1999 to Jan 15 1999

From: Alan and Carmel Brain <aebrain@w...>

Date: Wed, 13 Jan 1999 19:30:04 +1000

Subject: Re: Damage Program for many Batteries

> Charles Choukalos wrote:

> randomize timer

OK....

Here's how to do it with a programming language that was purpose-built
for military simulations (and the real stuff too for that matter).

I've deliberately used the same "bulletproofing" and somewhat verbose coding
style that I'd use in real life. Trust me, it saves time in the long run. Now
you can see why Military systems a) Cost so farnarckling much and b) Are much
more reliable than production COTS stuff, even before beta testing.

The program may not be bug free BTW, I don't have FB1 to hand, so forget how
to handle Class II shields...

-- Package of Utilities to do damage Calculations for Full Thrust 3
-- Author  : A.E.Brain
-- Created : 19990113
-- History : Initial version
-- Notes   : Only Hits done in this version

package Full_Thrust_Damage_Calculation is

  Max_Number_Of_Dice : constant := 10_000;
  -- Max number of dice it makes sense to roll vs one target

  subtype Number_Of_Dice_Type is integer range 1..Max_Number_Of_Dice;
  -- Range of sensible values for number of dice to roll

  Minimum_Shield : constant := 0;
  Maximum_Shield : constant := 3;
  -- note it should be 2 for FT3...

  subtype ShieldType is integer range Minimum_Shield..Maximum_Shield;

  -- Function to determine number of hits from X dice
  function Hits ( Number_Of_Dice    : Number_Of_Dice_Type := 1;
                  ReRoll_6s         : Boolean             := True;
                  Effective_Shields : Shield_Type         := 0

) return integer;

  -- other functions, for say PDAFs vs Missiles etc go here

  Probable_MaxRolls_Error : exception;
  -- Probably an overflow error, ie the maximum number of dice is too
big

end Full_Thrust_Damage_Calculation;

with Mathematical_Functions;

-- Package of Utilities to do damage Calculations for Full Thrust 3
-- Author  : A.E.Brain
-- Created : 19990113
-- History : Initial version
-- Notes   : Only Hits done in this version

package body Full_Thrust_Damage_Calculation is

  Min_value_of_Die : constant := 1;
  Max_value_of_Die : constant := 6;

  subtype DieRoll_Type is integer
    range Min_value_of_Die..Max_value_of_Die;
  -- FT3 only uses D6s. This is hidden from the user.

  function Do_A_Single_Die
    (  ReRoll_6s         : Boolean             := True;
       Effective_Shields : Shield_Type         := 0
) return integer is

  -- Note: All inputs have default values

    DieRoll       : DieRoll_Type;         -- The number rolled
    RoundUp       : constant      := 0.5; -- Needed to round values up
    ReturnedValue : integer       := 0;   -- The final total, initially
0

  begin

    Mathematical_Functions.Random.Initialise;
    -- YMMV on this one, it depends on the exact specification
    -- of Mathematical Functions. Sometimes a seed is needed.

DieRoll:= integer
     ( ( Mathematical_Functions.Random.Get *  MaxValue_of_Die ) +
       RoundUp
);

case DieRoll is

when 1..3 => null;

when 4 =>
                   if Effective_Shields = 0 then
                     Returned_Value := 1;
end if; when 5 =>
                   if Effective_Shields = 0 or
                      Effective_Shields = 1 then
                     Returned_Value = 1;

      when 6    => Returned_Value := 2;
                   if ReRoll_6s then
                     Returned_Value := Returned_Value +
                       Hits ( Number_Of_Dice => Number_of_Dice,
                              Effective_Shields => 0,
                              ReRoll_6s => True
); end if;
                   -- NOTE!!! Re-rolls ignore shields!

end case;

    return Returned_Value;

  exception

    when others => raise Probable_MaxRolls_Error;

  end Do_A_Single_Die;

  -- Function to determine number of hits from X dice
  function Hits ( Number_Of_Dice    : Number_Of_Dice_Type := 1;
                  ReRoll_6s         : Boolean             := True;
                  Effective_Shields : Shield_Type         := 0
) return integer is

Total: integer:= 0;

  begin

    for i in 1..Number_Of_Dice loop

      Total := Total + Hits ( ReRoll_6s => ReRoll_6s,
                              Effective_Shields => Effective_Shields
); end loop;

return Total;

  exception

when others =>
      raise Probable_MaxRolls_Error;

end Hits;

with Full_Thrust_Damage_Calculation;
with TEXT_IO;

-- Program to do 3000 Hits in FT3
-- Author  : A.E.Brain
-- Created : 19990113
-- History : Initial version
-- Notes   : Hits only printed out in this version;

procedure Do_3000_Hits is

TotalDamage: integer:= 0;
  -- the Damage

  package Hits_IO is new TEXT_IO.INTEGER_IO(integer);
  -- create an auxiliary package to do all inputs and outputs on
integers

begin

  TotalDamage := Hits( Number_Of_Dice => 3000 );
  -- Note, if shielded, just over-ride the defaults

  Hits_IO.put( TotalDamage );

exception

  when Probable_MaxRolls_Error =>
    TEXT_IO.Put
("Something went wrong, I'm afraid. Number of dice too large?");

when others =>
    TEXT_IO.Put
("Probably Doze or Unix playing silly whatsits...");

end Do_3000_Hits;

If you've read this far, congratulations!

From: Tim Jones <Tim.Jones@S...>

Date: Wed, 13 Jan 1999 09:45:20 -0000

Subject: RE: Damage Program for many Batteries

You can get as good a result using probabilities, work out the average damage
and multiply up (as submitted earlier)

follow ups on the various programs to the computer list perhaps...

From: Chen-Song Qin <cqin@e...>

Date: Wed, 13 Jan 1999 15:44:59 -0700 (MST)

Subject: Re: Damage Program for many Batteries

> On Wed, 13 Jan 1999, Alan E & Carmel J Brain wrote:

> -- Package of Utilities to do damage Calculations for Full Thrust 3

The syntax is just like VHDL! I would've said that if I didn't know this was
software.

From: Thomas Anderson <thomas.anderson@u...>

Date: Thu, 14 Jan 1999 20:15:33 +0000 (GMT)

Subject: Re: Damage Program for many Batteries

ok, this is heading OT at hacker speed; let's see if we can get it back.

On Wed, 13 Jan 1999, Alan E & Carmel J Brain wrote (but not quite in this
order):
> Charles Choukalos wrote:

<snip>

> OK....

oh, Ada. run! run! a language cooked up by the DoD which is exceeded in
terror-causing ability only by PL/1, a language cooked up by long-time
DoD competitor IBM.

> Now you can see why Military systems

ada was used in the on-board computer on Ariane 501. Ariane 501 was
lost in flight because the on-board computer was unable to correctly
handle a sensor misconfiguration. Ada is not quite as rock-solid as it
sometimes claims to be. it's still better than C, though.

that was my attempt to bring this back on-topic - hey, it had an
exploding spacecraft in it!

<ka-SNIP!>

> If you've read this far, congratulations!

as gripping as the latest Peter F Hamilton!

> and you can get FREE compilers

those who are into programmatic self-discipline could also look at
Eiffel, for which there are also free compilers (www.eiffel.com).

Tom

From: Alan and Carmel Brain <aebrain@w...>

Date: Fri, 15 Jan 1999 23:15:44 +1000

Subject: Re: Damage Program for many Batteries

> Chen-Song Qin wrote:

Ada was invented in 1983. VHDL was derived from it, as was OOPSLA
(Object-Oriented Oracle Programming Support Language), and an IEEE
Structured Design Language (subset of Ada). An update occurred in 1995. Used
(to the exclusion of all other languages for avionics..) by Boeing, Airbus
Industrie, Antonov, etc etc and so is liable to be THE programming language
for spacecraft in the future, just as it is for aircraft today.

Also used in many modern Naval Combat Systems. So is sorta kinda on topic a
bit almost. In fact some packages that are in service with the
RAN already contain definitions for parsecs, AUs, light-seconds etc as
well as the more normal Nautical Mile(US), Nautical Mile(Admiralty), Radar
Mile, Kilometer, etc etc. The idea being that this software is
re-usable.