Powers cost points:

Simulated 100000 sentient weapons.

Percent of weapons which gained each realm: 
Fire      :  93.176%
Cold      :  93.174%
Lightning :  93.303%
Poison    :  87.735%
Acid      :  79.510%
Air       :  47.440%
Earth     :  47.538%
Mind      :  17.450%
Shield    :  17.380%
Chaos     :  17.512%
Magic     :   5.361%
Antimagic :   5.401%

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

       Number of realms gained

Average value is 6.0498

   1:   0.003%
   2:   0.226%
   3:   2.046%
   4:   6.993%
   5:  19.510%
   6:  34.209%
   7:  28.929%
   8:   7.650%
   9:   0.432%
  10:   0.002%

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

       Final pval

Average value is 3.55161

   1:   5.556%
   2:  16.399%
   3:  24.660%
   4:  24.098%
   5:  29.287%

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

       to_h gained 

Average value is 40.43056

  21:   0.001%
  22:   0.003%
  23:   0.008%
  24:   0.026%
  25:   0.034%
  26:   0.071%
  27:   0.160%
  28:   0.300%
  29:   0.488%
  30:   0.716%
  31:   1.207%
  32:   1.853%
  33:   2.492%
  34:   3.553%
  35:   4.374%
  36:   5.528%
  37:   6.466%
  38:   7.340%
  39:   7.960%
  40:   8.326%
  41:   8.239%
  42:   7.645%
  43:   7.042%
  44:   6.369%
  45:   5.136%
  46:   4.221%
  47:   3.235%
  48:   2.430%
  49:   1.692%
  50:   1.153%
  51:   0.775%
  52:   0.469%
  53:   0.299%
  54:   0.189%
  55:   0.098%
  56:   0.046%
  57:   0.032%
  58:   0.015%
  59:   0.005%
  60:   0.003%
  61:   0.001%

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

       to_d gained 

Average value is 16.16985

   3:   0.002%
   4:   0.002%
   5:   0.012%
   6:   0.071%
   7:   0.186%
   8:   0.450%
   9:   1.120%
  10:   2.064%
  11:   3.591%
  12:   5.645%
  13:   7.958%
  14:   9.928%
  15:  11.519%
  16:  12.185%
  17:  11.477%
  18:  10.064%
  19:   8.166%
  20:   5.999%
  21:   4.005%
  22:   2.553%
  23:   1.505%
  24:   0.812%
  25:   0.376%
  26:   0.179%
  27:   0.085%
  28:   0.029%
  29:   0.011%
  30:   0.004%
  31:   0.002%

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

       Number of points acquired over 49 level gains

Average value is 32.84126

  18:   0.002%
  19:   0.003%
  20:   0.010%
  21:   0.037%
  22:   0.072%
  23:   0.161%
  24:   0.377%
  25:   0.752%
  26:   1.449%
  27:   2.604%
  28:   4.074%
  29:   6.108%
  30:   8.006%
  31:  10.037%
  32:  11.528%
  33:  11.993%
  34:  11.574%
  35:   9.923%
  36:   8.049%
  37:   5.723%
  38:   3.616%
  39:   2.133%
  40:   1.065%
  41:   0.459%
  42:   0.162%
  43:   0.064%
  44:   0.018%
  45:   0.001%

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

       Total number of points left unspent

Average value is 3.41564

   0:  11.650%
   1:  14.694%
   2:  15.420%
   3:  14.865%
   4:  13.043%
   5:   9.924%
   6:   7.491%
   7:   5.282%
   8:   3.743%
   9:   2.303%
  10:   0.921%
  11:   0.360%
  12:   0.173%
  13:   0.081%
  14:   0.025%
  15:   0.014%
  16:   0.006%
  17:   0.001%
  19:   0.002%
  20:   0.001%
  22:   0.001%

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

Weapons with only one of Fire, Cold or Lightning:   3.347%
Weapons with two of Fire, Cold or Lightning:  12.918%
Weapons with all of Fire, Cold and Lightning:  83.490%
Weapons with only one of Air or Earth:  46.060%
Weapons with both Air and Earth:  24.459%
Weapons with only one of Mind, Shield or Chaos:  39.891%
Weapons with two of Mind, Shield or Chaos:   6.011%
Weapons with all of Mind, Shield and Chaos:   0.143%
Weapons with only one of Magic or Antimagic:  10.576%
Weapons with both Magic and Antimagic:   0.093%

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

       Number of powers acquired

Average value is 13.00005

   3:   0.002%
   4:   0.037%
   5:   0.141%
   6:   0.440%
   7:   1.160%
   8:   2.530%
   9:   4.770%
  10:   8.047%
  11:  11.178%
  12:  13.734%
  13:  15.196%
  14:  14.096%
  15:  11.375%
  16:   8.353%
  17:   4.952%
  18:   2.578%
  19:   1.063%
  20:   0.287%
  21:   0.053%
  22:   0.007%
  23:   0.001%

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

       Number of power gain attempts which failed 

Average value is 3.65005

   0:   8.519%
   1:  14.229%
   2:  16.217%
   3:  15.756%
   4:  13.306%
   5:  10.162%
   6:   7.481%
   7:   5.326%
   8:   3.553%
   9:   2.253%
  10:   1.353%
  11:   0.779%
  12:   0.466%
  13:   0.288%
  14:   0.133%
  15:   0.081%
  16:   0.042%
  17:   0.034%
  18:   0.016%
  19:   0.003%
  20:   0.002%
  24:   0.001%

------------------------------------
Powers gained: 

Acid Brand            :  23.849%
Add to Blows          :   8.245%
Add to Charisma       :  28.674%
Add to Constitution   :   7.376%
Add to Dexterity      :   3.181%
Add to Infravision    :   7.727%
Add to Intelligence   :   2.774%
Add to Life           :   0.797%
Add to Light          :  41.916%
Add to Mana           :   0.921%
Add to Searching      :   2.699%
Add to Speed          :   8.349%
Add to Spellpower     :   0.902%
Add to Stealth        :   7.629%
Add to Strength       :   7.455%
Add to Tunnelling     :  26.804%
Add to Wisdom         :   7.785%
Anti-magic shell      :   0.779%
Antimagic field 1     :   0.779%
Antimagic field 2     :   0.771%
Blessed               :   7.813%
Chaos Brand           :   4.304%
Cloning Brand         :   0.924%
Cold Brand            :  40.626%
Drain Experience      :  28.712%
Earthquake Brand      :  28.709%
Electric Aura         :  42.066%
Electricity Brand     :  41.959%
Fire Aura             :  42.187%
Fire Brand            :  42.020%
Flight                :   0.902%
Free Action           :   8.181%
Hold Life             :   4.047%
Invisibility          :  41.686%
Levitation            :   7.594%
No Teleportation      :   0.809%
Poison Brand          :  29.194%
Precognition          :   0.906%
Random Teleportation  :  41.918%
Reflection            :   3.901%
Regeneration          :  13.108%
Resist Acid           :  23.555%
Resist Blindness      :   7.785%
Resist Chaos          :   4.412%
Resist Cold           :  40.699%
Resist Confusion      :   2.764%
Resist Dark           :   7.685%
Resist Disenchantment :   4.456%
Resist Electricity    :  41.971%
Resist Fear           :   9.864%
Resist Fire           :  42.008%
Resist Light          :   7.775%
Resist Nexus          :   3.146%
Resist Poison         :  28.685%
Resist Shards         :   7.521%
Resist Sound          :   3.146%
See Invisible         :   8.235%
Sense Animals         :   2.725%
Sense Demons          :   2.775%
Sense Giants          :  32.400%
Sense Good            :   7.587%
Sense Orcs            :   2.744%
Sense Spiders         :   2.753%
Sense Trolls          :  32.293%
Sense Uniques         :   2.768%
Slay Animal Brand     :  37.467%
Slay Demon Brand      :  40.706%
Slay Dragon Brand     :  40.717%
Slay Evil Brand       :  42.059%
Slay Giant Brand      :   7.499%
Slay Troll Brand      :   7.535%
Slay Undead Brand     :  41.775%
Slow Digestion        :  40.916%
Sustain Charisma      :  28.631%
Sustain Constitution  :   7.445%
Sustain Dexterity     :   3.199%
Sustain Intelligence  :   2.820%
Sustain Strength      :   7.497%
Sustain Wisdom        :   7.564%
Telepathy             :   3.524%
Vampiric Brand        :  29.064%
Wraithform            :   0.857%



The modified Perl script:

#!/usr/bin/perl -w

use strict;

my $amount = 100 * 1000;

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

my %realms =
  (
   "Fire"      => 1,
   "Cold"      => 1,
   "Lightning" => 1,
   "Poison"    => 2,
   "Acid"      => 3,
   "Air"       => 5,
   "Earth"     => 5,
   "Mind"      => 7,
   "Shield"    => 7,
   "Chaos"     => 7,
   "Magic"     => 10,
   "Antimagic" => 10
  );


my %powers =
  (
   "Fire"      => {
                   "Add to Light" => 1,
                   "Slay Undead Brand" => 1,
                   "Fire Brand" => 1,
                   "Resist Fire" => 1,
                   "Fire Aura" => 1
                  },
   "Cold"      => {
                   "Cold Brand" => 1,
                   "Slay Dragon Brand" => 1,
                   "Slay Demon Brand" => 1,
                   "Resist Cold" => 1,
                   "Invisibility" => 1,
                   "Slow Digestion" => 1

                  },
   "Lightning" => {
                   "Electricity Brand" => 1,
                   "Slay Evil Brand" => 1,
                   "Resist Electricity" => 1,
                   "Electric Aura" => 1,
                   "Random Teleportation" => 1

                  },
   "Poison"    => {
                   "Add to Charisma" => 1,
                   "Sustain Charisma" => 1,
                   "Poison Brand" => 1,
                   "Vampiric Brand" => 1,
                   "Slay Animal Brand" => 1,
                   "Resist Poison" => 1,
                   "Drain Experience" => 1,
                   "Sense Trolls" => 1,
                   "Sense Giants" => 1
                  },
   "Acid"      => {
                   "Add to Tunnelling" => 1,
                   "Acid Brand" => 1,
                   "Slay Animal Brand" => 1,
                   "Earthquake Brand" => 1,
                   "Resist Acid" => 1

                  },
   "Air"       => {
                   "Add to Wisdom" => 1,
                   "Add to Stealth" => 1,
                   "Add to Infravision" => 1,
                   "Add to Speed" => 1,
                   "Sustain Wisdom" => 1,
                   "Resist Light" => 1,
                   "Resist Dark" => 1,
                   "Resist Blindness" => 1,
                   "Levitation" => 1,
                   "See Invisible" => 1,
                   "Blessed" => 1,
                   "Sense Good" => 1
                  },
   "Earth"     => {
                   "Add to Strength" => 1,
                   "Add to Constitution" => 1,
                   "Add to Tunnelling" => 1,
                   "Add to Blows" => 1,
                   "Sustain Strength" => 1,
                   "Sustain Constitution" => 1,
                   "Slay Troll Brand" => 1,
                   "Slay Giant Brand" => 1,
                   "Earthquake Brand" => 1,
                   "Resist Fear" => 1,
                   "Resist Shards" => 1,
                   "Free Action" => 1,
                   "Regeneration" => 1,
                   "Sense Trolls" => 1,
                   "Sense Giants" => 1
                  },
   "Mind"      => {
                   "Add to Intelligence" => 1,
                   "Add to Searching" => 1,
                   "Sustain Intelligence" => 1,
                   "Resist Confusion" => 1,
                   "Resist Fear" => 1,
                   "Sense Orcs" => 1,
                   "Sense Trolls" => 1,
                   "Sense Giants" => 1,
                   "Sense Animals" => 1,
                   "Sense Uniques" => 1,
                   "Sense Spiders" => 1,
                   "Sense Demons" => 1
                  },
   "Shield"    => {
                   "Add to Dexterity" => 1,
                   "Sustain Dexterity" => 1,
                   "Resist Sound" => 1,
                   "Resist Nexus" => 1,
                   "Invisibility" => 1,
                   "Reflection" => 1,
                   "Hold Life" => 1,
                   "Regeneration" => 1

                  },
   "Chaos"     => {
                   "Chaos Brand" => 1,
                   "Earthquake Brand" => 1,
                   "Resist Chaos" => 1,
                   "Resist Disenchantment" => 1,
                   "Regeneration" => 1,
                   "Telepathy" => 1
                  },
   "Magic"     => {
                   "Add to Mana" => 1,
                   "Add to Spellpower" => 1,
                   "Cloning Brand" => 1,
                   "Resist Chaos" => 1,
                   "Resist Disenchantment" => 1,
                   "Wraithform" => 1,
                   "Precognition" => 1,
                   "Flight" => 1

                  },
   "Antimagic" => {

                   "Add to Blows" => 1,
                   "Add to Speed" => 1,
                   "Add to Life" => 1,
                   "Vampiric Brand" => 1,
                   "Chaos Brand" => 1,
                   "Reflection" => 1,
                   "Free Action" => 1,
                   "Hold Life" => 1,
                   "No Teleportation" => 1,
                   "See Invisible" => 1,
                   "Anti-magic shell" => 1,
                   "Antimagic field 1" => 1,
                   "Antimagic field 2" => 1
                  }
  );

my @realm_order =
  (
   "Fire",
   "Cold",
   "Lightning",
   "Poison",
   "Acid",
   "Air",
   "Earth",
   "Mind",
   "Shield",
   "Chaos",
   "Magic",
   "Antimagic"
  );


sub one_weapon {
    my $i;

    my $weap = {realms => [], points => 0, total_points => 0,
                pval => 0, to_h => 0, to_d => 0, powers => [],
                powers_avail => {}, failed_power_gains => 0};
    my $chance;

    for ($i = 1; $i < 50; $i++) {
        $chance = int(rand(100));

        if ($chance < 33) {
            if (rand(100) < 50) {
                $weap->{to_h}++;
            }
            else {
                $weap->{to_h} += 2;
            }
            $weap->{to_d}++;
            $weap->{points}++;
            $weap->{total_points}++;
        }
        elsif ($chance < 66) {
            $weap->{points}++;
            $weap->{total_points}++;
            $weap->{to_h}++;

            $chance = int(rand(100));

            if ($chance < 40 || $weap->{points} >= 10) {
                gain_realm($weap);
            } # gain realm
        } # gain point
        else {
            if (int(rand(34)) == 0) {
                $weap->{points}++;
                $weap->{total_points}++;
            }

            if (@{$weap->{realms}} == 0) {
                gain_realm($weap);
            }

            gain_power($weap);

            if ($weap->{pval} < 5) {
                if ($weap->{pval} == 0) {
                    $weap->{pval} = 1;
                } # if ($weap->{pval} == 0)
                else {
                     while (rand(100) < (20 - ($weap->{pval} * 2))) {
                        $weap->{pval}++;
                    }

                    if ($weap->{pval} >= 5) {
                        $weap->{pval} = 5;
                        $weap->{pval_maxed} = $i + 1;
                    }
                } # $weap->{pval} > 0
            } # if ($weap->{pval} < 5)
        }
    } # gain levels

    delete($weap->{powers_avail});

    return $weap;
} # one_weapon()

sub gain_realm {
    my($weap) = @_;

    my %available = %realms;
    my($i, $realm);

    for ($i = 0; $i < @{$weap->{realms}}; $i++) {
        $realm = $weap->{realms}->[$i];

        # Already have that realm?
        delete($available{$realm});
    }

    # Get rid of too-expensive realms
    foreach $realm (keys %available) {
        if ($available{$realm} > $weap->{points}) {
            delete($available{$realm});
        }
    }

    return if keys(%available) == 0;

    my @avail_arr = keys(%available);

    $realm = $avail_arr[int(rand(@avail_arr))];

    push(@{$weap->{realms}}, $realm);

    $weap->{points} -= $realms{$realm};

    # Add to list of available powers
    my %new_powers = %{$powers{$realm}};
    my $power;

    foreach $power (keys(%new_powers)) {
        $weap->{avail_powers}->{$power} = 1;
    }

    # But don't re-add to the available list powers we already have
    foreach $power (@{$weap->{powers}}) {
        delete($weap->{avail_powers}->{$power});
    }
} # gain_realm()

sub gain_power {
    my($weap) = @_;

    my @avail = keys(%{$weap->{avail_powers}});

    if (@avail == 0) {
        $weap->{failed_power_gains}++;
        return;
    }

    if ($weap->{points} == 0) {
        $weap->{failed_power_gains}++;
        return;
    }

    my $power = $avail[int(rand(@avail))];

    push(@{$weap->{powers}}, $power);

    delete($weap->{avail_powers}->{$power});

    $weap->{points}--;
} # gain_realm()

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

sub print_amount {
    my $weapons = shift(@_);
    my $func    = shift(@_);

    my($i, @levels, $num);
    my $total = 0;

    for ($i = 0; $i < $amount; $i++) {
        $num = &$func($weapons->[$i], @_);

        $total += $num;

        $levels[$num]++;
    }

    print "Average value is ", $total / $amount, "\n\n";

    for ($i = 0; $i < scalar(@levels); $i++) {
        my $val = $levels[$i];

        next if (!$val || $val == 0);

        printf("%4i: %3i.%03i%%\n", $i, $val * 100 / $amount,
               ($val * 100 * 1000 / $amount) % 1000);
    }
    print "\n------------------------------------\n";
}

sub print_pct {
    my $weapons = shift(@_);
    my $func    = shift(@_);

    my($i, $num);

    $num = 0;
    for ($i = 0; $i < $amount; $i++) {
        $num++ if &$func($weapons->[$i], @_);
    }

    printf("%3i.%03i%%", $num * 100 / $amount,
           ($num * 100 * 1000 / $amount) % 1000);
}

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

# Main

my $i;
my @weapons;

for ($i = 0; $i < $amount; $i++) {
    push(@weapons, one_weapon());
    my $weap = $weapons[$i];
}


print "Simulated $amount sentient weapons.\n\n";

print "Percent of weapons which gained each realm: \n";

my %realms_gained;
my $realm;

for ($i = 0; $i < $amount; $i++) {
    my $weap = $weapons[$i];

    my $realm;

    foreach $realm (@{$weap->{realms}}) {
        $realms_gained{$realm}++;
    }
}

foreach $realm (@realm_order) {
    my $gained = $realms_gained{$realm} || 0;
    printf("%-10s: %3i.%03i%%\n", $realm, $gained * 100 / $amount,
          ($gained * 100 * 1000 / $amount) % 1000);
}

print "\n------------------------------------\n";

#########

sub num_realms {
    my($weap) = @_;

    return scalar(@{$weap->{realms}});
}

print "\n       Number of realms gained\n\n";

print_amount(\@weapons, \&num_realms);

#########

sub final_pval {
    my($weap) = @_;

    return $weap->{pval};
}

print "\n       Final pval\n\n";

print_amount(\@weapons, \&final_pval);

#########

sub to_h_gained {
    my($weap) = @_;

    return $weap->{to_h};
}

print "\n       to_h gained \n\n";

print_amount(\@weapons, \&to_h_gained);

#########

sub to_d_gained {
    my($weap) = @_;

    return $weap->{to_d};
}

print "\n       to_d gained \n\n";

print_amount(\@weapons, \&to_d_gained);


#########

sub num_total_points {
    my($weap) = @_;

    return scalar($weap->{total_points});
}

print "\n       Number of points acquired over 49 level gains\n\n";

print_amount(\@weapons, \&num_total_points);

#########

sub num_points_left {
    my($weap) = @_;

    return scalar($weap->{points});
}

print "\n       Total number of points left unspent\n\n";

print_amount(\@weapons, \&num_points_left);

#########

print "\n";

sub realm_combos {
    my($weap, $realms, $amnt) = @_;

    my %realm_hash;
    my $realm;
    my $num = 0;

    foreach $realm (@{$realms}) {
        $realm_hash{$realm} = 1;
    }

    foreach $realm (@{$weap->{realms}}) {
        $num++ if ($realm_hash{$realm});
    }

    return ($num == $amnt);
}

print "Weapons with only one of Fire, Cold or Lightning: ";
print_pct(\@weapons, \&realm_combos, ["Fire", "Cold", "Lightning"], 1);
print "\n";

print "Weapons with two of Fire, Cold or Lightning: ";
print_pct(\@weapons, \&realm_combos, ["Fire", "Cold", "Lightning"], 2);
print "\n";

print "Weapons with all of Fire, Cold and Lightning: ";
print_pct(\@weapons, \&realm_combos, ["Fire", "Cold", "Lightning"], 3);
print "\n";

print "Weapons with only one of Air or Earth: ";
print_pct(\@weapons, \&realm_combos, ["Air", "Earth"], 1);
print "\n";

print "Weapons with both Air and Earth: ";
print_pct(\@weapons, \&realm_combos, ["Air", "Earth"], 2);
print "\n";

print "Weapons with only one of Mind, Shield or Chaos: ";
print_pct(\@weapons, \&realm_combos, ["Mind", "Shield", "Chaos"], 1);
print "\n";

print "Weapons with two of Mind, Shield or Chaos: ";
print_pct(\@weapons, \&realm_combos, ["Mind", "Shield", "Chaos"], 2);
print "\n";

print "Weapons with all of Mind, Shield and Chaos: ";
print_pct(\@weapons, \&realm_combos, ["Mind", "Shield", "Chaos"], 3);
print "\n";

print "Weapons with only one of Magic or Antimagic: ";
print_pct(\@weapons, \&realm_combos, ["Magic", "Antimagic"], 1);
print "\n";

print "Weapons with both Magic and Antimagic: ";
print_pct(\@weapons, \&realm_combos, ["Magic", "Antimagic"], 2);
print "\n";

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

# Now do powers

print "\n##########################################\n";

sub num_powers {
    my($weap) = @_;

    return scalar(@{$weap->{powers}});
}

print "\n       Number of powers acquired\n\n";

print_amount(\@weapons, \&num_powers);

###

sub failed_power_gains {
    my($weap) = @_;

    return $weap->{failed_power_gains};
}

print "\n       Number of power gain attempts which failed \n\n";

print_amount(\@weapons, \&failed_power_gains);

###

my %power_count = ();
my $power;

for ($i = 0; $i < $amount; $i++) {
    my $weap = $weapons[$i];

    foreach $power (@{$weap->{powers}}) {
        $power_count{$power}++;
    }
}

print "Powers gained: \n\n";

foreach $power (sort(keys(%power_count))) {
    my $val = $power_count{$power};
    printf("%-22s: %3i.%03i%%\n", $power, $val * 100 / $amount,
               ($val * 100 * 1000 / $amount) % 1000);
}

Spoilers/Sentient Weapons/Statistics/Experiment: powers cost points (last edited 2006-03-10 21:09:33 by KhymChanur)