Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Commit

Permalink
Fixing indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tklein23 committed Feb 27, 2014
1 parent bb7b6df commit f9a4ec2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 59 deletions.
118 changes: 60 additions & 58 deletions 2014-02-27/maze-generator/genmaze.pl
Expand Up @@ -13,7 +13,7 @@
sub push_path {
my $px = shift;
my $py = shift;

die "px=$px out of bounds" unless $px >= 0 && $px < 32;
die "py=$py out of bounds" unless $py >= 0 && $py < 32;

Expand All @@ -27,65 +27,69 @@ sub get_directions {
my $fy = shift;

return grep {$_->[0] >= 0 && $_->[0] < 32 && $_->[1] >= 0 && $_->[1] < 32} (
# [$fx-1, $fy-1],
[$fx-1, $fy],
# [$fx-1, $fy+1],
[$fx, $fy-1],
# [$fx, $fy],
[$fx, $fy+1],
# [$fx+1, $fy-1],
[$fx+1, $fy],
# [$fx+1, $fy+1],
);

# [$fx-1, $fy-1],
[$fx-1, $fy],

# [$fx-1, $fy+1],
[$fx, $fy-1],

# [$fx, $fy],
[$fx, $fy+1],

# [$fx+1, $fy-1],
[$fx+1, $fy],

# [$fx+1, $fy+1],
);
}

sub get_neighbors {
my $fx = shift;
my $fy = shift;

return grep {$_->[0] >= 0 && $_->[0] < 32 && $_->[1] >= 0 && $_->[1] < 32} (
[$fx-1, $fy-1],
[$fx-1, $fy],
[$fx-1, $fy+1],
[$fx, $fy-1],
# [$fx, $fy],
[$fx, $fy+1],
[$fx+1, $fy-1],
[$fx+1, $fy],
[$fx+1, $fy+1],
);
[$fx-1, $fy-1],
[$fx-1, $fy],
[$fx-1, $fy+1],
[$fx, $fy-1],

# [$fx, $fy],
[$fx, $fy+1],
[$fx+1, $fy-1],
[$fx+1, $fy],
[$fx+1, $fy+1],
);
}

sub get_unmarked {
return grep {!$maze[$_->[0]][$_->[1]]} @_;
return grep {!$maze[$_->[0]][$_->[1]]} @_;
}

sub get_marked {
return grep {$maze[$_->[0]][$_->[1]]} @_;
return grep {$maze[$_->[0]][$_->[1]]} @_;
}

sub print_maze {
for (1..30) {
print STDERR "\n";
}

my $lineno = 0;
foreach my $row (@maze) {
printf STDERR "%2d ", $lineno;
foreach my $field (@$row) {
if ($field) {
print STDERR ".";
}
else {
print STDERR "#";
}
}
print STDERR "\n";
$lineno++;
}
}

for (1..30) {
print STDERR "\n";
}

my $lineno = 0;
foreach my $row (@maze) {
printf STDERR "%2d ", $lineno;
foreach my $field (@$row) {
if ($field) {
print STDERR ".";
}
else {
print STDERR "#";
}
}
print STDERR "\n";
$lineno++;
}
}

push_path(0,0);

Expand All @@ -101,8 +105,8 @@ sub print_maze {

my @D = get_unmarked(get_directions($px, $py));
my @candidates = grep {1 == int(
grep {!$Np{($_->[0]).",".($_->[1])}} get_marked(get_neighbors($_->[0], $_->[1]))
)} @D;
grep {!$Np{($_->[0]).",".($_->[1])}} get_marked(get_neighbors($_->[0], $_->[1]))
)} @D;

if (@candidates) {
my $i = floor(rand(int(@candidates)));
Expand All @@ -114,16 +118,14 @@ sub print_maze {
}
}



foreach my $row (@maze) {
foreach my $field (@$row) {
if ($field) {
print " ";
}
else {
print "X";
}
}
print "\n";
}
foreach my $row (@maze) {
foreach my $field (@$row) {
if ($field) {
print " ";
}
else {
print "X";
}
}
print "\n";
}
2 changes: 1 addition & 1 deletion 2014-02-27/maze-generator/maze2asm.pl
Expand Up @@ -8,7 +8,7 @@
my %colmap = (
"X" => "X",
" " => "A",
);
);

printf "LDX #\$00\n"; # color of walls
printf "LDA #\$0e\n"; # color of free space
Expand Down

0 comments on commit f9a4ec2

Please sign in to comment.