Originally Posted by
quzah
I may hand out some extra "style points" if it looks slick. But don't count on that alone to win. I'm thinking something along the lines of:
1000 base points.
+10 points per character under 500.
-10 points per character over.
-N points for unreached cells in the maze.
Alright, let's put up an entry and see what we get...
e:~/programming/maze/shang$ ls -al shang*
-rwxrwxr-x 1 root windows 15527 Nov 4 22:55 shang
-rwxrwxr-x 1 root windows 417 Oct 10 20:43 shang.cpp
-rwxrwxr-x 1 root windows 15345 Nov 4 22:56 shang2
-rwxrwxr-x 1 root windows 352 Nov 4 22:56 shang2.cpp
The executable size doesn't matter. Shang sent in two versions. The second is the one we'll use, because it was done after a bit of shrinking. This gives us the following output:
Code:
:~/programming/maze/shang$ g++ -o shang2 shang2.cpp -Wall -pedantic
:~/programming/maze/shang$ ./shang2
##############################
# #
## ###########################
# #
##### ########################
# #
###### #######################
# #
################# ############
# #
################## ###########
# #
############# ################
# #
######################## #####
# #
##############################
Compiles witout warnings (and naturally without errors, otherwise it wouldn't compile). Shang's version has the simplest interpretation of a 'true maze'. However it does meet the requirement. As far as that goes, it is in fact quite good at interpreting my words of what a maze was. It is the minimalist approach. The bare minimum needed to be considered a maze. The break poin in the horizontal row ends up randomly placed, and that's all it needs to do.
Resizing was simple as it was supposed to be, and didn't give any unexpected results. Space wise, it's the winner of what I was sent.
Given the above scoring:
1000 base + ((500 - 352) * 10) = 2480 points.
Here's his code, which works in a sig as it should:
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int w=30;
int h=15;
void c(int n,char q='#'){cout<<setw(n)<<setfill(q)<<"";}int main()
{srand(time(0));c(w);for(int y=1;y<=h;y++){cout<<endl;c(1);c(w-2,' '),
c(1);if(++y>=h)break;cout<<endl;int s = 1+rand()%(w-2);c(s);c(1,' ');
c(w-s-1);}cout<<endl;c(w);}
It doesn't require any code tags or anything wrapping it for it to work.
I also received an entry from zzzaaahh. Here's what we have:
:~/programming/maze/zzzaaahhh$ ls z* -al
-rwxrwxr-x 1 root windows 13709 Oct 13 17:06 zzzaaahh2
-rwxrwxr-x 1 root windows 487 Oct 13 17:06 zzzaaahh2.cpp
-rwxrwxr-x 1 root windows 501 Oct 11 22:35 zzzaaahhh.cpp
The first character had problems with the way whitespace is handled in the sig box, so a second version was sent. It's the version we're using for judging.
Code:
:~/programming/maze/zzzaaahhh$ g++ -o zzzaaahh2 zzzaaahh2.cpp -W
all -pedantic
:~/programming/maze/zzzaaahhh$ ./zzzaaahh2
###############################
# # # # #
# #### # # # ########## #
# # # # # #
#### # # # ########## # #
# # # # # # # # #
# # # # #### #### # # #
# # # # # # # #
# ########## #### # # # #
# # # # # # #
#### # ####### # # # ####
# # # # # # #
# ####### #### ########## #
# # # # # #
#### # # # #### #### # #
# # # # # # # #
# #### # # #### # #### #
# # # # # #
# ####### ############# # #
# # #
###############################
It turns out a nice looking maze. This is more of what I had in mind when I was thinking along the lines of making a maze generator, but Shang's does in fact fill the requirements. We don't gain or lose anything by resizing the maze, and it is equally as easy to resize as Shang's code.
However, we have one requirement for this code to be functional when copied from the sig box: It requires code tags. Without it, we have problems with the white space getting eaten, and the maze doesn't turn out right. However! The code, with code tags, is exactly 500 bytes in size. Code tags take a total of 13 characters.
While it wasn't a requirement that you have room for code tags, or that they be present at all, this code does both, and is exactly 500 characters doing so. That's pretty snazzy.
Here's the code:
Code:
[code]#include<cstdio>
#include<cstdlib>
#include<ctime>
#define I(u,v) if(c u&&m[v+c]&1)a[k++]=v+c;
#define F for(n=0;n<H;n++)printf
#define X printf("#\n");
const int V=10,H=10;int m[V*H],a[4],n=0,t=0;
void f(int c){int k=1;m[c]&=6;
while(k){k=0;I(%H,-1)I(/H,-H)I(%H<H-1,1)I(/H<V-1,H)
if(k){n=a[rand()%k];m[n<c?c:n]&=(n-c)%H?3:5;f(n);}}}
int main(){while(n<V*H)m[n++]=7;srand(time(NULL));f(rand()%H);
for(;t<V;t++){F(m[t*H+n]&2?"###":"# ");X;F(m[t*H+n]&4?"# ":" ");X}
F("###");return X}
[/code]
At a glance, they could have shaved off another 3 bytes by changing NULL to a zero. But I like the fact that it's exactly 500 this way. At any rate...
1000 + ((500 - 500)*10) = 1000 + 250 bonus snazzy points.
My entry doesn't meet the 500 character requirement. My entry is in C, where as these are both in C++. (Not that it matters.) Mine is 24 characters too big. If only I hadn't mentioned the "without warnings" part.
:~/programming/maze/quzah$ ls wsig* -al
-rwxrwxr-x 1 root windows 14685 Oct 19 21:26 wsig
-rwxrwxr-x 1 root windows 524 Oct 19 21:34 wsig.c
:~/programming/maze/quzah$
I had worked on a few versions of it prior to receiving any entries. I had a recursive version early on, and then went to a non-recursive version. Here's the output of my current code:
Code:
gcc -o wsig wsig.c -Wall -pedantic
quzah@greenhouse:~/programming/maze/quzah$ ./wsig
###############################################
# # # # # # # # # # #
# ##### # # ### # # # # # # # # # # ### # ### #
# # # # # # # # # # # # # # # #
# # # # # # # # ####### ######### # # # ### # #
# # # # # # # # # # # # # # # # # #
# ### # # ####### ### # # # # # # # # # # # # #
# # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # #####
# # # # # # # # # # # # # # # # # # # #
# # # ### # # # # # # ### # ### # ##### # # # #
# # # # # # # # # # # # # # # # # # # # #
# # # # ##### ##### # # # ### ### # # ### # # #
# # # # # # # # # # # # # # # # #
# # # # # # ### # ### # # # # # ### # # ### # #
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # ### # # # # ### ### # # ###
# # # # # # # # # # # # # # # # # # # # #
# # ### # # # ### # # ### # # ### ### ####### #
# # # # # # # # # # # # # # # # #
# # # ##### # # # ### # # ### # # # # ### # # #
# # # # # # # # # # # # # # #
###############################################
Blah blah, resizable without any problems. Mine is rather scrunched, and here it is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define Y 11
#define X 23
#define A _[y][x]
#define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
#define I(J,K)printf(y<0?"#":y&1 J!(_[y/2][x]&K)?"#":" ")
#define L for(x=0;x<X;x++)
int y,x,z,_[Y][X]={{16}};int U(){for(y=0;y<Y;y++)L if(!A)return 1;return 0;}int
main(){srand(time(0));for(;U();){y=rand()%Y;x=rand()%X;if(!A){C(y>0,y-1,x,1,4)C
(x<X-1,y,x+1,2,8)C(y<Y-1,y+1,x,4,1)C(x>0,y,x-1,8,2);}}for(y=-1;y<Y+Y;y++){
printf("\n#");L{I(&&,4);I(||,2);}}return 0;}
If I knock off the #include lines, I can fit it, and that's probably what I'll do when I do stick it in my sig. I have some rather fun lines of code which I'll expand slightly so you can read them. I'll go into depth a bit on this particular entry because... it's mine. Duh!
I have scrunched this up pretty good. Here are two macros I like a great deal:
Code:
#define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
Used here, slightly "clarified" so you can see it:
Code:
for(;U();)
{
y=rand()%Y;x=rand()%X;
if(!A)
{
C(y>0,y-1,x,1,4)
C(x<X-1,y,x+1,2,8)
C(y<Y-1,y+1,x,4,1)
C(x>0,y,x-1,8,2);
}
}
Basicly all this does is, as long as there's an unused cell in the array, it randomly picks one cell, and if it's empty, checks all of its neighbors. If a neighbor is not empty, it marks this as used, and knocks out the wall between the cells.
That's the non-recursive solution I used. I couldn't seem to get the recursion trimmed down as much as I liked. I was probably over complicating it, but I couldn't seem to get it any smaller than this non-recursive version. I'm rather fond of that macro.
I like this one even more:
Code:
#define I(J,K)printf(y<0?"#":y&1 J!(_[y/2][x]&K)?"#":" ")
Don't ask me what it does. I have tried and tried to rewrite this again simpler, and I'll be damned if I can do it. It's used like so:
Code:
for(y=-1;y<Y+Y;y++){
printf("\n#");
L{
I(&&,4);
I(||,2);
}
}
That prints the maze. I really like this macro. I like the fact that the first argument is an operator. The values "2" and "4" are the bit values for the directions "east" and "south" respectively. At any rate, it's fun code.
I had to hard code the values for the starting point of the maze (the 16 in the array initialization), which normally would have been set randomly, but I couldn't afford the space to do it that way. Still, that it works. The maze doesn't look quite as good as if I had done it though. It's still passable though. Also, in shrinking the C and L macros and it slightly detracted from the "nice looking" part of the output. But it still turns out a perfect maze.
Anyone who was working on their version, feel free to send it in. Don't just take someone else's code and rename the variables if you do though, because it'll be posted here.
Also, feel free to toot your own horn and tell us all the finer points of your code as I've done to mine.
Oh, I guess I need a score:
1000 - (24 * 10) = 760. I lose. Ah well, it was fun.
I was considering getting rid of the time function, and hard coding a value for the random number seed. Getting a "random" maze would mean you recompiled every time you wanted a new maze. Not a big deal, but since I didn't feel that truely met my requirement, I didn't. However, had I done so... snazzy!
Code:
ls -al vsig.c
-rwxrwxr-x 1 root windows 500 Nov 4 23:37 vsig.c
Which I'll stick in my sig now for the hell of it.
Quzah.