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?'


In reply to Is this a good way to implement a Battleship game? by wickedxter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.