BBC BASIC
« Maze Generation with BBC BASIC for Windows »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:21pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Maze Generation with BBC BASIC for Windows  (Read 398 times)
OutBush
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx Maze Generation with BBC BASIC for Windows
« Thread started on: Apr 16th, 2017, 11:13am »

Unfortunately I'm just a passer-by with some BBC BASIC code that I'm trying to understand for another BASIC dialect. Thought if I post the routine here and highlight the sections I'm having trouble with, some explanations might sort out the problems I'm having.

Code:
      MazeWidth% = 11
      MazeHeight% = 9
      MazeCell% = 50
 
      VDU 23,22,MazeWidth%*MazeCell%/2+3;MazeHeight%*MazeCell%/2+3;8,16,16,128
      VDU 23,23,3;0;0;0; : REM Line thickness
      PROCgeneratemaze(Maze&(), MazeWidth%, MazeHeight%, MazeCell%)
      END
 
      DEF PROCgeneratemaze(RETURN m&(), w%, h%, s%)
      LOCAL x%, y%
      DIM m&(w%, h%)
      FOR y% = 0 TO h%
        LINE 0,y%*s%,w%*s%,y%*s%
      NEXT
      FOR x% = 0 TO w%
        LINE x%*s%,0,x%*s%,h%*s%
      NEXT
      GCOL 15
      PROCcell(m&(), RND(w%)-1, y% = RND(h%)-1, w%, h%, s%)
      ENDPROC
 
      DEF PROCcell(m&(), x%, y%, w%, h%, s%)
      LOCAL i%, p%, q%, r%
      m&(x%,y%) OR= &40 : REM Mark visited
      r% = RND(4)
      FOR i% = r% TO r%+3
        CASE i% MOD 4 OF
          WHEN 0: p% = x%-1 : q% = y%
          WHEN 1: p% = x%+1 : q% = y%
          WHEN 2: p% = x% : q% = y%-1
          WHEN 3: p% = x% : q% = y%+1
        ENDCASE
        IF p% >= 0 IF p% < w% IF q% >= 0 IF q% < h% IF m&(p%,q%) < &40 THEN
          IF p% > x% m&(p%,q%) OR= 1 : LINE p%*s%,y%*s%+4,p%*s%,(y%+1)*s%-4
          IF q% > y% m&(p%,q%) OR= 2 : LINE x%*s%+4,q%*s%,(x%+1)*s%-4,q%*s%
          IF x% > p% m&(x%,y%) OR= 1 : LINE x%*s%,y%*s%+4,x%*s%,(y%+1)*s%-4
          IF y% > q% m&(x%,y%) OR= 2 : LINE x%*s%+4,y%*s%,(x%+1)*s%-4,y%*s%
          PROCcell(m&(), p%, q%, w%, h%, s%)
        ENDIF
      NEXT
      ENDPROC
 


In my program I've reduced MazeCell to 44 and MazeHeight to 8 (it was drawing offscreen otherwise), I've setup the initial lines correctly to get a Square Grid (8x11 in my case), but the Procedure Cell isn't working for me (well not quite) and errors are occurring because p% & q% are falling outside the range of the array (mainly), though I don't quite follow these lines:

Code:
m&(x%,y%) OR= &40 : REM Mark visited 


and this one:

Code:
IF p% >= 0 IF p% < w% IF q% >= 0 IF q% < h% IF m&(p%,q%) < &40 THEN 


this series of IFs is baffling me, I couldn't find anything about it in the BBC BASIC Manual or the tutorial, to me it looks like a conditioning thing IF <this> OR <that> OR <do_this> OR <do_that> AND array is less than &40 THEN <do all these other IF checks.

Thanks.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Maze Generation with BBC BASIC for Windows
« Reply #1 on: Apr 16th, 2017, 2:21pm »

on Apr 16th, 2017, 11:13am, OutBush wrote:
Code:
m&(x%,y%) OR= &40 

Is it the OR= that you're unfamiliar with? Compound assignment operators of this kind are common in other languages (and not unusual in other BASICs), in this case it's equivalent to:

Code:
m&(x%,y%) = m&(x%,y%) OR &40 

The compound assignment operator is faster and has the advantage of being atomic (although that's probably not relevant in this case).

Quote:
this series of IFs is baffling me, I couldn't find anything about it in the BBC BASIC Manual or the tutorial
Code:
IF p% >= 0 IF p% < w% IF q% >= 0 IF q% < h% IF m&(p%,q%) < &40 THEN 

You can find this usage described at the Wiki here.

Richard.

User IP Logged

OutBush
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx Re: Maze Generation with BBC BASIC for Windows
« Reply #2 on: Apr 16th, 2017, 10:25pm »

Thanks Richard.

on Apr 16th, 2017, 2:21pm, Richard Russell wrote:
Is it the OR= that you're unfamiliar with? Compound assignment operators of this kind are common in other languages (and not unusual in other BASICs), in this case it's equivalent to:

Code:
m&(x%,y%) = m&(x%,y%) OR &40 

The compound assignment operator is faster and has the advantage of being atomic (although that's probably not relevant in this case).


Sorry yes it was the "OR=" which was confusing me. I suspected it was compounded, though was incorrectly saying "map%(x%,y%)=&40 OR &40"

Quote:
You can find this usage described at the Wiki here.



Great thanks. I must of overlooked that part of the guide :( So based on what I've read in that, that "IF <condition> IF <condition2> etc" has to be completely true before it does any of those other IF checks? In the BASIC dialect I'm using Logical operators can be replaced with another "IF", but it's handled differently as such because THEN has to come before, so it looks like this: "IF <condition> THEN IF <condition2>" and so on.

Unfortunately Time constraints occurred when I posted earlier and I forgot to ask about the 4 IF statements below that series of IFs.

If I analyse the 1st IF condition, in my original code I've got:

"IF p%>x% OR map%(p%,q%)=1 etc"

which will be incorrect. So I'm guessing the correct course would be to say:

"IF p%>x% AND map%(p%,q%)=map%(p%,q%) OR 1 THEN ..."
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Maze Generation with BBC BASIC for Windows
« Reply #3 on: Apr 16th, 2017, 10:45pm »

on Apr 16th, 2017, 10:25pm, OutBush wrote:
but it's handled differently as such because THEN has to come before, so it looks like this: "IF <condition> THEN IF <condition2>" and so on.

It's fine to add the THENs, it doesn't alter the meaning. THEN is a bit like LET, a feature that most BASIC dialects support for legacy reasons but which can be, and often is, omitted in modern programs.

So why aren't you using BBC BASIC for this task? And why are you so reticent to say what the 'other' BASIC dialect is? I'm sure everybody here would like to know!

It's somewhat, um, unusual to ask on the support forum for a language how to translate from it rather than to it!

Richard.
User IP Logged

OutBush
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx Re: Maze Generation with BBC BASIC for Windows
« Reply #4 on: Apr 17th, 2017, 10:17am »

on Apr 16th, 2017, 10:45pm, Richard Russell wrote:
It's fine to add the THENs, it doesn't alter the meaning. THEN is a bit like LET, a feature that most BASIC dialects support for legacy reasons but which can be, and often is, omitted in modern programs.


Understood, I just wasn't sure if a condition like that was only executed if any of the conditions were true or if all those conditions had to be true based on what comes after that single THEN.

Quote:
So why aren't you using BBC BASIC for this task?


I'm using a Computer System which has BASIC in it's ROM as standard. Just recently I compiled some BASIC computer games for a Competition with the aim of keeping them to 10 Lines of BASIC. Though I'm somewhat puzzled by Commodore 64 program from a similar competition going back to 2001 which constructs a Maze in a measly 512 bytes, though I think they were simply looking for programs which could be produced in a small amount of space, the 2 categories they had were 512 bytes & 2Kb.

Earlier I came across this BBC BASIC Maze Generator and raised it, as a member of our Amstrad community was asking if it was possible to produce a Maze Generator in 3 Lines of BASIC. Since I brought it up and no further action took place, I decided to try and interpret it for Locomotive BASIC. It indeed doesn't look like it would be possible for it to fit in 3 Lines of BASIC, though what I have produced seems small enough at 2Kb that it maybe possible to use in 10 Lines of BASIC, though with even the errors being ironed out of it now, it's not generating something that BBC BASIC for Windows has produced, in their screenshot example each area of the Maze has an opening to it, in my case I've got areas which are off-limits. sad

Quote:
And why are you so reticent to say what the 'other' BASIC dialect is? I'm sure everybody here would like to know!


So I use an Amstrad CPC, it has Locomotive BASIC (1.0 or 1.1 depending on which model your using), there are a number of emulators for PCs/Macs for this machine, I use WinApe which is an emulator for Windows which can emulate a range of CPC machines from the early machines (circa '84/'85) to the Plus range (1990 or so), I also have an original machine from '85 (a 6128), but grew up using the 1st model (a 464). BBC BASIC does exist on that system, but it comes as a program which operates through CP/M, which is an operating system popularised on computer systems that either had a Intel 8080 processor or a Zilog Z80 processor. The Zilog Z80 processor is an enhancement through backward compatible to Intel's 8080 processor, which is what the Amstrad machines had before Amstrad went onto making IBM Compatible PCs, though has you could probably imagine the older computers have their followers! smiley

Quote:
It's somewhat, um, unusual to ask on the support forum for a language how to translate from it rather than to it!

Richard.


Well I've had no response and after a couple of days it's probably not going to happen, so I thought if I asked what that line is doing I might be able to interpret that into the language I know. I wasn't suggesting could you please write this in Locomotive BASIC and initially felt raising details about Machine & Dialects might start overwhelming people. shocked
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls