home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug117.arc
/
MAZE.LBR
/
MAZEBLD.DOC
< prev
next >
Wrap
Text File
|
1979-12-31
|
3KB
|
57 lines
MAZE BUILDER
BY IAN JOHNSTONE
13/9/87
Thi≤á prograφ construct≤ ß mazσ froφ widtΦ anΣ heigh⌠ specificat-ì
ion≤á supplieΣá b∙ thσ use≥ anΣ theε offer≤ hiφ thσ choicσá oµá eithe≥ ì
playinτ hi≤ wa∙ ou⌠ oµ thσ maze¼ o≥ watchinτ thσ compute≥ worδ it≤ wa∙ ì
out«á ┴ Microsof⌠ Basiπ versioε (Seσ Beelinσ September¼ 1986⌐ i≤ incl-ì
udeΣ iε thσ librar∙ fo≥ comparisoε oµ time≤ taken«á Thσ Basiπá prograφ ì
take≤á ove≥ 1▓ minute≤ t∩ builΣ ß ful∞ screeε maze¼á whilσ thσ machinσ ì
language program takes less than six seconds.
Thσá Assembl∙ languagσ sourcσ prograφ i≤ als∩ includeΣá - ╔á hopσ ì
tha⌠á thσ documentatioε i≤ clea≥ enough«á ╔ havσ establisheΣ ß screen-ì
sized buffer at 7000H, each byte being coded as follows:-
Byte value = 0 - The cell is vacant
Bit 0 set - Backtracking prohibited
1 - May move north
2 - " " east
3 - " " south
4 - " " west
Fo≥ example,iµ thσ cel∞ representeΣ b∙ thσ bytσ a⌠ locatioε 7350╚ ì
i≤á t∩ bσ giveε aε exi⌠ t∩ thσ nortΦ (wσ neeΣ no⌠ kno≈á whethe≥á therσ ì
are other exits), this can be done by:-
LD A,(7350H)
OR 2
LD (7350H),A
Thσá graphiπ fo≥ ß cel∞ witΦ ß nortΦ exi⌠ woulΣ bσ ß bo° witΦ thσ ì
to≡á opeε (seσ thσ firs⌠ linσ oµ MAZDAT┴ iε thσ sourcσ codσ wherσá thσ ì
PC╟ areß fo≥ CHR$(129⌐ (o≥ CHR$(128+1⌐ i≤ giveε jus⌠ sucΦ ßá graphic)¼ ì
then all we need to do is:-
LD HL,7350H
LD A,(HL) ;Get the cell code
RRA ;Divide by two
AND 0FH
OR 128 ;A will now be 129
LD DE,8000H ;Offset to equivalent location on screen
ADD HL,DE
LD (HL),A ;This will display CHR$(129) at 0F350H
Iε othe≥ area≤ North¼á East¼á SoutΦ anΣ Wes⌠ (notσ thσ order⌐ arσ ì
giveεá thσ value≤ oµ 1¼á 2¼á │ anΣ 4«á Thi≤ enable≤ ß righ⌠ turε t∩ bσ ì
madσ b∙ incrementinτ thσ directioε anΣ vicσ versß fo≥ ß lef⌠ turn¼á a≤ ì
long as the values are kept within the range 1 to 4.
Wheεá movinτ rounΣ thσ maze¼á yo⌡ caε onl∙ ente≥ cell≤ no⌠á prev-ì
iousl∙á entereΣ,áexcep⌠á wheε backtrackinτ anΣ onl∙ theεá wheεá i⌠á i≤ ì
allowed«á Backtrackinτ i≤ donσ t∩ ge⌠ ou⌠ oµ blinΣ alley≤ anΣ ma∙ onl∙ ì
bσ donσ oncσ iε eacΦ cell« Unles≤ yo⌡ haΣ thi≤ rule¼ yo⌡ coulΣ bσ lef⌠ ì
wandering through the maze for all eternity.
Thσá auto-escapσá routinσ wa≤ thσ resul⌠ oµá thσá thought¼á whicΦ ì
proved wrong, that this might be the beginnings of an experience in AI
Thσá rulσá fo≥ escapinτ froφ ß mazσ i≤ t∩ pu⌠ onσ hanΣ oε ßá wal∞á anΣ ì
neve≥ le⌠ i⌠ leavσ tha⌠ wal∞ unti∞ yo⌡ arσ ou⌠ oµ thσ maze«á Thσ righ⌠ ì
hand rule is applied here viz.,
Take a stem
If you strike a wall, turn leftè If you don't strike a wall, turn right
Never go straight ahead