Help for this page

Select Code to Download


  1. or download this
    #
    # 5x5 map grid for each player
    ...
    # Carrier = @
    # Submarine = ~
    # Ocean/Empty Space = .
    
  2. or download this
    # Stats trackers
    my @p1Attacks;
    my @p2Attacks;
    
  3. 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 );
    
  4. 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 },
        );
    
  5. or download this
        # Get in use tiles for ship hashes
        foreach my $ship ( keys %p1ships ) {
    ...
            }
        
        }
    
  6. or download this
        # Get in use tiles for ship hashes
        foreach my $ship ( keys %p1ships ) {
    ...
            push @p1usedTiles, split /,/, $p1ships{ $ship }{ loc };
    
        }
    
  7. or download this
    sub checkLocation {
    
    ...
    
    
    }
    
  8. or download this
        # Get random ship key and href
        my @availShips;
    ...
                push(@availShips,$key);
            }
        }
    
  9. or download this
        # Get random ship key and href
        my @availShips = grep defined( $p2ships{ $_ } ), keys %p2ships;
    
  10. 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);
            }
        }
    
  11. 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;
    
  12. or download this
    # Menu loop
    while () {
    ...
        $count++;
    
    }
    
  13. or download this
    # Menu loop
    my $count = 0;
    while () {
    
        if ( $count == 0 ) {
    
  14. or download this
                my @opponentRemaining;
                foreach my $key ( keys %p2ships ) { 
    ...
                        { push(@opponentRemaining, $key) 
                    } 
                }
    
  15. or download this
                my @opponentRemaining = grep defined( $p2ships{ $_ } ), ke
    +ys %p2ships;
    
  16. or download this
                    my @validInputs;
                    foreach my $key ( keys %p1ships ) {
    ...
                            push(@validInputs,$key);
                        }
                    }
    
  17. or download this
                    my @validInputs = grep defined( $p1ships{ $_ } ) && $p
    +1ships{ $_ }{ mc } != 1, keys %p1ships;