Author Topic: Maze Generator  (Read 3556 times)

0 Members and 1 Guest are viewing this topic.

Offline EgoTrip

  • 6128 Plus
  • ******
  • Posts: 1.050
  • Country: gl
    • http://egochip.blogspot.co.uk/
  • Liked: 677
  • Likes Given: 294
Maze Generator
« on: 17:27, 09 March 15 »
Whats the best way to go about generating a random maze in BASIC? Preferably in 1-3 lines?

I want the maze to be in this style:

http://i.imgur.com/vnioZ7q.png

But with the entrance top left and exit bottom right.


EgoTrip's Stuff
EgoTrip's Stuff

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.914
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1122
  • Likes Given: 1898
Re: Maze Generator
« Reply #1 on: 01:09, 15 March 15 »

Whats the best way to go about generating a random maze in BASIC? Preferably in 1-3 lines?

I want the maze to be in this style:

http://i.imgur.com/vnioZ7q.png

But with the entrance top left and exit bottom right.


The closest thing I know of which generates a random like maze in 1 line is a game called Mines from AA58, but it's not a true Maze in the sense of what your looking for, so what the writer has done is made the thing invisible and given you a device to say how many mines are around you, but you still have to guess where they are (Left, Right or Ahead of you).


The only other program I know of, has you creating a maze in the sense of what you're after.


I found a Maze Generator on Rosetta Code, but the closest thing they have there which produces a Maze Like Output is written in BBC BASIC, and is a lot bigger than 3 Lines, as are many of the code samples there, sadly no Locomotive BASIC is available there yet. Was surprised to see no Pascal examples either.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Morn

  • 464 Plus
  • *****
  • Posts: 346
  • Country: de
  • Liked: 94
  • Likes Given: 63
Re: Maze Generator
« Reply #2 on: 12:34, 15 March 15 »
Maybe look at LABYRATT on the disc for this book: Intelligenz in BASIC - Für Schneider CPC 464/664/6128 - CPCWiki


Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.182
  • Country: fr
  • Liked: 1144
  • Likes Given: 167
Re: Maze Generator
« Reply #3 on: 12:38, 15 March 15 »
I did something to do that for a tutorial in Demoniak 7 ("coding corner/The Maze" article). It is far from 3 lines, though.
Targhan/Arkos

Arkos Tracker 2.0.0 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.914
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1122
  • Likes Given: 1898
Re: Maze Generator
« Reply #4 on: 10:29, 16 April 17 »
I'm raising this old thread up again because I've tried to interpret the BBC BASIC Maze Generator code on Rosetta Code for Locomotive BASIC, but have had trouble with the code I've produced:


Code: [Select]

10 MODE 1
20 MazeWidth%=11 : MazeHeight%=8 : MazeCell%=44
30 DIM maze%(MazeWidth%,MazeHeight%)
40 FOR y% = 0 TO MazeHeight%
50   MOVE 0,398-(y%*MazeCell%)
60   DRAW MazeWidth%*MazeCell%,398-(y%*MazeCell%),1
70 NEXT y%
80 FOR x%= 0 TO MazeWidth%
90   MOVE x%*MazeCell%,398
100   DRAW x%*MazeCell%,398-(MazeHeight%*MazeCell%)
110 NEXT x%
120 PLOT -2,-2,0
130 x%=(RND*MazeWidth%): y%=(RND*MazeHeight%): w%=MazeWidth% : h%=MazeHeight% : s%=MazeCell%
140 GOSUB 160
150 GOTO 130
160 maze%(x%,y%)=&40
170 r%=INT(RND*4)
180 FOR i%=r% TO r%+3
190   IF i% MOD 4=0 THEN p%=x%-1:q%=y% ELSE IF i% MOD 4=1 THEN p%=x%:q%=y% ELSE IF i% MOD 4=2 THEN p%=x%:q%=y%-1 ELSE IF i% MOD 4=3 THEN p%=x%:q%=y%
200   IF p%>=0 THEN GOSUB 270
210   IF p%<w% THEN GOSUB 270
220   IF q%>=0 THEN GOSUB 270
230   IF q%<h% THEN GOSUB 270
240   IF maze%(p%,q%)<&40 THEN GOSUB 270
250 NEXT i%
260 RETURN
270 IF p% > x% OR maze%(p%,q%)=1 THEN MOVE p%*s%,398-(y%*s%+4):DRAW p%*s%,398-(y%*s%-4)
280 IF q% > y% OR maze%(p%,q%)=2 THEN MOVE x%*s%+4,398-(q%*s%):DRAW (x%+1)*s%-4,398-(q%*s%)
290 IF x% > p% OR maze%(x%,y%)=1 THEN MOVE x%*s%,398-y%*s%+4:DRAW x%*s%,398-(y%+1)*s%-4
300 IF y% > q% OR maze%(x%,y%)=2 THEN MOVE x%*s%+4,398-y%*s%:DRAW (x%+1)*s%-4,398-(y%*s%)
310 RETURN


It's difficult because I don't have BBC BASIC for Windows and I guess it's a wild goose chase asking if anyone knows how to interpret BBC BASIC code here, alternatively I found a Forum for BBC BASIC, but there's a good chance they won't know how to code it into Locomotive BASIC.


There seems to be a number of bugs that occur, though even when the program has done some removal of lines, it's not really looking like the Maze Pictured on Rosetta code.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.914
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1122
  • Likes Given: 1898
Re: Maze Generator
« Reply #5 on: 07:47, 22 April 17 »
I was unsuccessful at coding a BBC BASIC version of a Maze Generator for Locomotive BASIC, but I had another down to earth idea for generating a Maze out of the Binary Notation as represented from the Character string.


[attachimg=1]


I had to attach this program as an image because of the extended character set representations, as you can see there's 8 Characters (CHR(255) & CHR(129)), so the Binary used is 11111111 & 10000001 and prints out a Box 8x8. The d2$ holds the initial 8 bit binary data & then when the Nested Loop is setup, that data gets spread across the 8x8 array to enable a larger field to be displayed.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.914
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1122
  • Likes Given: 1898
Re: Maze Generator
« Reply #6 on: 09:35, 23 April 17 »
So with the routine I wrote previously, I made some modifications to produce a 16x16 Maze. The Binary routine I wrote earlier worked fine for that routine, though once it starts getting leading Zero's for the pattern, they are removed, since the character set is 8bit it's easily resolved when the 2nd parameter is used. Once that was used the correct pattern emerged.


Initially I used a character definer to produce some maze shape, the Graphic Definer from Home Computing Weekly is handy for that because you can setup 4 8x8 grids. From that I could save a screen shot with all the details in it:



* Maze Program.png
(4.2 kB, 768x540 - viewed 403 times)



From that I can simply PRINT chr$(pattern number);chr$(pattern number) ..etc to use the Copy Control Key to insert those characters into the character strings. Because the Maze is 16 wide now, I need to set up another string & extract that into another array, but after that the information gets stored into the Main Array m$(16,16), so when I draw it, there's a Left & Right Side getting drawn.  It's only limitation is it's limited to a single maze, though has the advantage of setting up a Maze type field from a small amount of data.


* 16x16 Maze.zip
(2.2 kB - downloaded 61 times)



I've attached a Disk Image of the program which still only 1k as well.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3