Labyrinth Polyglot

4

Create a program that can create a randomly arranged maze (The path of the maze changes each time) with exactly 1 exit and one enterance and a minimum size of 8x4 and max size of 32x32, with the exact dimensions x and y as input

Submissions can be original code, but to score higher add onto a submission with another language (polyglot)

Writing code in labyrinth gives brownie points as suggested by Mistah Figgins :)


Example Case (8x4):

__   _____  
| | | __ |  
|_____|  |  
|  |  _| |   
|____|   |

Non-Examples:

__
|_|
Too Small
__   _____  
| | | __ |  
|___|_|  |  
|  |  _| |   
|____|   |
No Solution

Apologies if challenge is confusing or cumbersome, this is my first PCG and after reading up on the meta I still had some blurry regions.

GracefulLemming

Posted 2016-12-15T03:21:55.823

Reputation: 863

Question was closed 2016-12-15T14:42:14.657

Could you elaborate on what within the same function(s)/file(s) means? Also, we need an answer in Labyrinth

– MildlyMilquetoast – 2016-12-15T03:33:22.283

8

You should have posted on the Sandbox first, to have gotten feedback.

– Pavel – 2016-12-15T03:33:34.663

@Pavel Will fix right now, thank you! I guess I got too caught up in the theatrics – GracefulLemming – 2016-12-15T03:33:49.217

Can you provide an example valid labyrinth? – Pavel – 2016-12-15T03:49:00.403

1randomly What does that mean? Someone can have two possible labyrinths and randomly choose among those two. On the other extreme, you may require that all possible labyrinths are produced with the same probability, or at least with nonzero probability. What's the spec here? – Luis Mendo – 2016-12-15T10:15:06.977

What exactly is the bonus for polyglotness? – Rɪᴋᴇʀ – 2016-12-15T22:13:44.610

Answers

1

C and C++, 603 bytes

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define Y x+1+rand()%(y/2-1)*2
#define C(n,i) if(j n&&M[i])c[b++]=i;
typedef int I;I m;I main(I argc, char**argv){srand(time(0));I x=atoi(argv[1]),y=atoi(argv[2]),*L=(I*)malloc(2*x*y*sizeof(I)),j=Y;char*M=(char*)malloc(x*y);memset(M,1,x*y);M[j]=0;for(;;){I b=0,c[4];C(%x>1,j-2)C(>2*x,j-2*x)C(%x<x-3,j+2)C(/x<y-3,j+2*x)if(b){I z=c[rand()%b];M[z]=M[z+j>>1]=0;L[m++]=j=z;}else if(m)j=L[--m];else break;}for(;;){I j=Y;if(!M[j]){M[j-x]=0;break;}}for(j=0;j<y;++j){for(m=0;m<x;++m)putchar(M[j*x+m]?88:32);puts("");}free(M);free(L);}

Edit: this was written before the prompt was revised. This program just outputs X for the walls and places only one door.

bb94

Posted 2016-12-15T03:21:55.823

Reputation: 1 831