- or download this
#
# 5x5 map grid for each player
...
# Carrier = @
# Submarine = ~
# Ocean/Empty Space = .
- or download this
# Stats trackers
my @p1Attacks;
my @p2Attacks;
- or download this
# Ships - surely there is a better way to do this
my %p1cruiser = ( 'hp' => '2', 'size' => '3', 'ap' => '1', 'loc' => ''
+, 'sym' => '*', 'mc' => 0 );
...
my %p2subm = ( 'hp' => '1', 'size' => '2', 'ap' => '3', 'loc' => ''
+, 'sym' => '~', 'mc' => 0 );
my %p2ships = ( 'cru' => \%p2cruiser, 'car' => \%p2carrier, 'subm' =>
+\%p2subm );
- or download this
# Ships - surely there is a better way to do this
my %p1ships = (
...
car => { hp => 3, size => 5, ap => 2, loc => '', sym => '@', mc =
+> 0 },
subm => { hp => 1, size => 2, ap => 3, loc => '', sym => '~', mc =
+> 0 },
);
- or download this
# Get in use tiles for ship hashes
foreach my $ship ( keys %p1ships ) {
...
}
}
- or download this
# Get in use tiles for ship hashes
foreach my $ship ( keys %p1ships ) {
...
push @p1usedTiles, split /,/, $p1ships{ $ship }{ loc };
}
- or download this
sub checkLocation {
...
}
- or download this
# Get random ship key and href
my @availShips;
...
push(@availShips,$key);
}
}
- or download this
# Get random ship key and href
my @availShips = grep defined( $p2ships{ $_ } ), keys %p2ships;
- or download this
# Make sure AI doesn't try to 'move' if it has no available moves
+left
print "Checking available AI moves\n";
...
push(@availMovers, $key);
}
}
- or download this
# Make sure AI doesn't try to 'move' if it has no available moves
+left
print "Checking available AI moves\n";
my @availMovers = grep defined( $p2ships{ $_ } ) && $p2ships{ $_ }
+{ mc } != 1, keys %p2ships;
- or download this
# Menu loop
while () {
...
$count++;
}
- or download this
# Menu loop
my $count = 0;
while () {
if ( $count == 0 ) {
- or download this
my @opponentRemaining;
foreach my $key ( keys %p2ships ) {
...
{ push(@opponentRemaining, $key)
}
}
- or download this
my @opponentRemaining = grep defined( $p2ships{ $_ } ), ke
+ys %p2ships;
- or download this
my @validInputs;
foreach my $key ( keys %p1ships ) {
...
push(@validInputs,$key);
}
}
- or download this
my @validInputs = grep defined( $p1ships{ $_ } ) && $p
+1ships{ $_ }{ mc } != 1, keys %p1ships;