This repository has been archived by the owner on Nov 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cool assembler maze generator. Enjoy.
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Generate a maze to walk through: | ||
================================ | ||
* ```genmaze.pl``` to create a random 32x32 maze | ||
* ```maze2asm.pl``` to convert the maze to 6502 assembler | ||
|
||
Usage: | ||
====== | ||
* ```./genmaze.pl | ./maze2asm.pl >coolmaze.dat``` | ||
* open ```coolmaze.dat``` in your favourite text editor | ||
* copy the content into your mouse | ||
* paste it into http://skilldrick.github.io/easy6502/ and run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Time::HiRes qw( usleep ); | ||
use POSIX; | ||
use Data::Dumper; | ||
|
||
my @maze = map {[(undef)x32]} 1..32; | ||
my @path = (); | ||
|
||
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; | ||
|
||
print STDERR "adding path element [$px, $py]\n"; | ||
push @path, [$px, $py]; | ||
$maze[$px][$py] = 1; | ||
} | ||
|
||
sub get_directions { | ||
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], | ||
); | ||
} | ||
|
||
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], | ||
); | ||
} | ||
|
||
sub get_unmarked { | ||
return grep {!$maze[$_->[0]][$_->[1]]} @_; | ||
} | ||
|
||
sub get_marked { | ||
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++; | ||
} | ||
} | ||
|
||
|
||
|
||
push_path(0,0); | ||
|
||
while (@path) { | ||
usleep(2*1000); | ||
print_maze(); | ||
|
||
my $p = $path[$#path]; | ||
my $px = $p->[0]; | ||
my $py = $p->[1]; | ||
|
||
my %Np = map {($_->[0]).",".($_->[1]) => 1} get_directions($px, $py); | ||
|
||
my @D = get_unmarked(get_directions($px, $py)); | ||
my @candidates = grep {1 == int( | ||
grep {!$Np{($_->[0]).",".($_->[1])}} get_marked(get_neighbors($_->[0], $_->[1])) | ||
)} @D; | ||
|
||
if (@candidates) { | ||
my $i = floor(rand(int(@candidates))); | ||
push_path($candidates[$i][0], $candidates[$i][1]); | ||
} | ||
else { | ||
print STDERR "dont know what to do on [$px;$py]\n"; | ||
pop @path; | ||
} | ||
} | ||
|
||
|
||
|
||
foreach my $row (@maze) { | ||
foreach my $field (@$row) { | ||
if ($field) { | ||
print " "; | ||
} | ||
else { | ||
print "X"; | ||
} | ||
} | ||
print "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my $startaddr = 0x0200; | ||
|
||
my %colmap = ( | ||
"X" => 0x00, | ||
" " => 0x0e, | ||
); | ||
|
||
while (my $line = <>) { | ||
chomp $line; | ||
|
||
die "wrong length" unless length($line) == 32; | ||
my @pixels = map {$colmap{$_}} split //, $line; | ||
|
||
for (my $i=0; $i<int(@pixels); $i++) { | ||
if (defined($pixels[$i])) { | ||
printf "LDA #\$%02x\n", $pixels[$i]; | ||
printf "STA \$%04x\n", $startaddr+$i; | ||
printf "\n"; | ||
|
||
} | ||
} | ||
|
||
$startaddr += 32; | ||
} |