Is this a good way of going by this?
The code snipplet is part of a game for calulating battles, it goes ship by ship each searching (randomly) targets of the other side and caluating if the ship has more then one weapon. If this doesnt explain enough just ask and i'll go through and break the code down.
It's kinda long.
## Battleship
if($d_batt){
for my $x (1..$d_batt){
my $rand_ss = int rand(4);
if($rand_ss eq 1 && $a_crv ne 0){
#weak target
my $weak = int rand 2;
if($weak eq 0 || $weak eq 2){
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $y = int rand $a_crv;
$y++ if $y eq 0;
push(@{$data->{shots}{defender}},"$y|crv|batt");
$data->fleet_d("defender","attacker");
}
}else {
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $weakest = $data->damaged("crv",$config->{armor}{cr
+v},"attacker");
my ($num,$class) = split(/\|/,$weakest);
push(@{$data->{shots}{defender}},"$num|$class|batt");
$data->fleet_d("defender","attacker");
}
}
}elsif ($rand_ss eq 2 && $a_des ne 0){
#next if $data->{shots}{$y};
#weak target
my $weak = int rand 2;
if($weak eq 0 || $weak eq 2){
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $y = int rand $a_des;
$y++ if $y eq 0;
push(@{$data->{shots}{defender}},"$y|des|batt");
$data->fleet_d("defender","attacker");
}
}else {
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $weakest = $data->damaged("des",$config->{armor}{de
+s},"attacker");
my ($num,$class) = split(/\|/,$weakest);
push(@{$data->{shots}{defender}},"$num|$class|batt");
$data->fleet_d("defender","attacker");
}
}
}elsif($rand_ss eq 3 && $a_corvette ne 0){
#next if $data->{shots}{$y};
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $y = int rand $a_corvette;
$y++ if $y eq 0;
push(@{$data->{shots}{defender}},"$y|corvette|batt");
$data->fleet_d("defender","attacker");
}
}else {
for (1..16){
my $w_s = int rand(100);
next if $w_s gt $config->{percent_hit}{batt};
my $r_shipD = $data->random_ship("attacker","defender");
my ($num, $ship) = split(/\|/,$r_shipD);
push(@{$data->{shots}{defender}},"$num|$ship|batt");
$data->fleet_d("defender","attacker");
}
}
}
READMORE added by Arunbear
2006-04-02 Retitled by planetscape, as per Monastery guidelines
Original title: 'This a good way?'