' Maze Generator — array-based map representation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL maze(149) AS LONG
    LOCAL x AS LONG
LOCAL y AS LONG
LOCAL px AS LONG
LOCAL py AS LONG
    LOCAL walls AS LONG
LOCAL paths AS LONG
    LOCAL outLine AS STRING

    PRINT "Maze Generator Demo"
    PRINT "===================="
    PRINT ""

    maze(0) = 1: maze(1) = 1: maze(2) = 1: maze(3) = 1: maze(4) = 1
    maze(5) = 1: maze(6) = 1: maze(7) = 1: maze(8) = 1: maze(9) = 1
    maze(10) = 1: maze(11) = 2: maze(12) = 0: maze(13) = 0: maze(14) = 1
    maze(15) = 0: maze(16) = 0: maze(17) = 0: maze(18) = 0: maze(19) = 1
    maze(20) = 0: maze(21) = 0: maze(22) = 0: maze(23) = 0: maze(24) = 1
    maze(25) = 0: maze(26) = 1: maze(27) = 0: maze(28) = 1: maze(29) = 1
    maze(30) = 0: maze(31) = 0: maze(32) = 0: maze(33) = 0: maze(34) = 1
    maze(35) = 0: maze(36) = 1: maze(37) = 0: maze(38) = 0: maze(39) = 1
    maze(40) = 1: maze(41) = 1: maze(42) = 0: maze(43) = 1: maze(44) = 1
    maze(45) = 0: maze(46) = 0: maze(47) = 0: maze(48) = 0: maze(49) = 1
    maze(50) = 0: maze(51) = 1: maze(52) = 0: maze(53) = 0: maze(54) = 1
    maze(55) = 0: maze(56) = 0: maze(57) = 0: maze(58) = 0: maze(59) = 1
    maze(60) = 1: maze(61) = 1: maze(62) = 0: maze(63) = 0: maze(64) = 1
    maze(65) = 0: maze(66) = 0: maze(67) = 0: maze(68) = 3: maze(69) = 1
    maze(70) = 1: maze(71) = 1: maze(72) = 1: maze(73) = 1: maze(74) = 1

    PRINT "Maze (6 rows x 15 cols):"
    PRINT "  0=path, 1=wall, 2=start, 3=exit"
    PRINT ""
    y = 0
    WHILE y <= 4
        outLine = ""
        x = 0
        WHILE x <= 14
            IF maze(y * 15 + x) = 1 THEN outLine = outLine + "#"
            IF maze(y * 15 + x) = 2 THEN outLine = outLine + "S"
            IF maze(y * 15 + x) = 3 THEN outLine = outLine + "E"
            IF maze(y * 15 + x) = 0 THEN outLine = outLine + "."
            x = x + 1
        WEND
        PRINT outLine
        y = y + 1
    WEND

    PRINT ""
    PRINT "Find start (S) and exit (E):"
    y = 0
    WHILE y <= 4
        x = 0
        WHILE x <= 14
            IF maze(y * 15 + x) = 2 THEN PRINT "  Start at ("; x; ","; y; ")"
            IF maze(y * 15 + x) = 3 THEN PRINT "  Exit at ("; x; ","; y; ")"
            x = x + 1
        WEND
        y = y + 1
    WEND

    walls = 0: paths = 0
    y = 0
    WHILE y <= 4
        x = 0
        WHILE x <= 14
            IF maze(y * 15 + x) = 1 THEN walls = walls + 1
            IF maze(y * 15 + x) = 0 THEN paths = paths + 1
            x = x + 1
        WEND
        y = y + 1
    WEND
    PRINT "  Walls: "; walls; " Paths: "; paths; " Total: "; walls + paths

    FUNCTION = 0
END FUNCTION
