File:MAZE 30x20 DFS.ogv
מתוך Wikimedia Commons
קפיצה לניווט
קפיצה לחיפוש
אין גרסה ברזולוציה גבוהה יותר.
MAZE_30x20_DFS.ogv (קובץ וידאו Theora של Ogg, באורך דקה שנייה, 732 × 492 פיקסלים, 69 קילו־ביטים בשנייה, גודל הקובץ: 510 ק"ב)
מידע על הקובץ
נתונים מובְנים
כיתובים
כיתובים
נא להוסיף משפט שמסביר מה הקובץ מייצג
mazeWave Degenrated Back by Backtracking prims algorithm
|
תקציר
[עריכה]תיאורMAZE 30x20 DFS.ogv |
English: The generation of a maze using a depth-first search algorithm. This maze is 30x20 in size. The C++ source code used to create this can be seen at w:User:Purpy Pupple/Maze. |
תאריך יצירה | |
מקור | נוצר על־ידי מעלה היצירה |
יוצר | Purpy Pupple |
גרסאות אחרות |
|
C src code
[עריכה]//Purpy Pupple's amazing maze generator.
//Released under the CC-BY-SA 3.0 License and the GFDL
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define UP 0 //-y
#define DOWN 1 //+y
#define LEFT 2 //-x
#define RIGHT 3 //+x
#define OUTFILE "MAZE"
#define WHITE fprintf(outfile, "%c%c%c", 255,255,255)
#define BLACK fprintf(outfile, "%c%c%c", 0,0,0)
#define RED fprintf(outfile, "%c%c%c", 0,0,255)
#define nodeadend//generate a maze without any dead ends! (consequently, many solutions to maze)
//#define prim //enable this to generate mazes using prim's algorithm.
#define backtrack//enable this to generate mazes using depth-first search. Don't enable both.
//#define movie //this option spams bitmaps to illustrate each step of generation.
long numin=1; //Number of cells in the maze.
const int xsize=152;
const int ysize=122;
void initialize();
void generate();
void savebmp(int xspecial, int yspecial);
struct cell{
bool in; //Is this cell in the maze?
bool up; //Does the wall above this cell exist?
bool left;//Does the wall to the left of this cell exist?
int prevx, prevy; //The coordinates of the previous cell, used for backtracking.
};
cell MAZE[xsize][ysize];
int main(){
srand((unsigned int)time(NULL)); //seed random number generator with system time
initialize(); //initialize the maze
generate(); //generate the maze
#ifdef movie
for(int i=1;i<10;i++){
numin++;
savebmp(0,0); //output the bitmap
}
#else movie
savebmp(0,0);
#endif
return 0;
}
void initialize(){
//Initialize the maze!
for(int x=0;x<xsize;x++){
for(int y=0;y<ysize;y++){
//The maze cells on the edges of the maze are "in" to provide padding. Otherwise, all maze cells are not in.
MAZE[x][y].in = (x==0||x==xsize-1||y==0||y==ysize-1)?1:0;
//All maze cells have all walls existing by default, except the perimeter cells.
MAZE[x][y].up = (x==0||x==xsize-1||y==0)?0:1;
MAZE[x][y].left = (x==0||y==0||y==ysize-1)?0:1;
}
}
return;
}
void generate(){
int xcur=1, ycur=1;//start growing from the corner. It could theoretically start growing from anywhere, doesn't matter.
MAZE[xcur][ycur].in = 1;
int whichway;
bool success;
do{
#ifdef movie
savebmp(xcur,ycur);
#endif
#ifdef nodeadend
if( MAZE[xcur][ycur-1].in&&MAZE[xcur][ycur+1].in&&
MAZE[xcur-1][ycur].in&&MAZE[xcur+1][ycur].in ){
//If at a dead end, randomly destroy a wall to make it not a dead end!
do{
success=0;
whichway=rand()%4;
switch(whichway){
case UP:
if(MAZE[xcur][ycur].up&&ycur!=1){
success=1;
MAZE[xcur][ycur].up=0;
}
break;
case DOWN:
if(MAZE[xcur][ycur+1].up&&ycur!=ysize-2){
success=1;
MAZE[xcur][ycur+1].up=0;
}
break;
case LEFT:
if(MAZE[xcur][ycur].left&&xcur!=1){
success=1;
MAZE[xcur][ycur].left=0;
}
break;
case RIGHT:
if(MAZE[xcur+1][ycur].left&&xcur!=xsize-2){
success=1;
MAZE[xcur+1][ycur].left=0;
}
break;
}
}while(!success);
}
#endif
#ifdef backtrack
while( MAZE[xcur][ycur-1].in&&MAZE[xcur][ycur+1].in&&
MAZE[xcur-1][ycur].in&&MAZE[xcur+1][ycur].in ){
//If all the neighbourhood cells are in, backtrack.
int xcur2=MAZE[xcur][ycur].prevx;
ycur=MAZE[xcur][ycur].prevy;
xcur=xcur2;
}
#endif
#ifdef prim
do{
//randomly find a cell that's in the maze
xcur=rand()%(xsize-2)+1;
ycur=rand()%(ysize-2)+1;
}while(!MAZE[xcur][ycur].in ||
MAZE[xcur][ycur-1].in&&MAZE[xcur][ycur+1].in&&
MAZE[xcur-1][ycur].in&&MAZE[xcur+1][ycur].in);
#endif
do{
//Randomly grow the maze if possible.
success=0;
whichway=rand()%4;
switch(whichway){
case UP:
if(!MAZE[xcur][ycur-1].in){
success=1;
MAZE[xcur][ycur].up=0;
MAZE[xcur][ycur-1].prevx=xcur;
MAZE[xcur][ycur-1].prevy=ycur;
ycur--;
}
break;
case DOWN:
if(!MAZE[xcur][ycur+1].in){
success=1;
MAZE[xcur][ycur+1].up=0;
MAZE[xcur][ycur+1].prevx=xcur;
MAZE[xcur][ycur+1].prevy=ycur;
ycur++;
}
break;
case LEFT:
if(!MAZE[xcur-1][ycur].in){
success=1;
MAZE[xcur][ycur].left=0;
MAZE[xcur-1][ycur].prevx=xcur;
MAZE[xcur-1][ycur].prevy=ycur;
xcur--;
}
break;
case RIGHT:
if(!MAZE[xcur+1][ycur].in){
success=1;
MAZE[xcur+1][ycur].left=0;
MAZE[xcur+1][ycur].prevx=xcur;
MAZE[xcur+1][ycur].prevy=ycur;
xcur++;
}
break;
}
}while(!success);
MAZE[xcur][ycur].in=1;
numin++; //Every iteration of this loop, one maze cell is added to the maze.
}while(numin<(xsize-2)*(ysize-2));
#ifdef movie
savebmp(xcur,ycur);
#endif
return;
}
void savebmp(int xspecial, int yspecial){
//save a bitmap file! the xspecial, yspecial pixel is coloured red.
FILE * outfile;
int extrabytes, paddedsize;
int x, y, n;
int width=(xsize-1)*2-1;
int height=(ysize-1)*2-1;
extrabytes = (4 - ((width * 3) % 4))%4;
char filename[200];
sprintf(filename, "%s_%dx%d_n%d.bmp", OUTFILE, xsize, ysize, numin);
paddedsize = ((width * 3) + extrabytes) * height;
unsigned int headers[13] = {paddedsize + 54, 0, 54, 40, width, height, 0, 0, paddedsize, 0, 0, 0, 0};
outfile = fopen(filename, "wb");
fprintf(outfile, "BM");
for (n = 0; n <= 5; n++){
fprintf(outfile, "%c", headers[n] & 0x000000FF);
fprintf(outfile, "%c", (headers[n] & 0x0000FF00) >> 8);
fprintf(outfile, "%c", (headers[n] & 0x00FF0000) >> 16);
fprintf(outfile, "%c", (headers[n] & (unsigned int) 0xFF000000) >> 24);
}
fprintf(outfile, "%c", 1);fprintf(outfile, "%c", 0);
fprintf(outfile, "%c", 24);fprintf(outfile, "%c", 0);
for (n = 7; n <= 12; n++){
fprintf(outfile, "%c", headers[n] & 0x000000FF);
fprintf(outfile, "%c", (headers[n] & 0x0000FF00) >> 8);
fprintf(outfile, "%c", (headers[n] & 0x00FF0000) >> 16);
fprintf(outfile, "%c", (headers[n] & (unsigned int) 0xFF000000) >> 24);
}
//Actual writing of data begins here:
for(y = 0; y <= height - 1; y++){
for(x = 0; x <= width - 1; x++){
if(x%2 == 1 && y%2 == 1){
if(x/2+1 == xspecial && y/2+1 == yspecial) RED;
else{
if(MAZE[x/2+1][y/2+1].in) WHITE; else BLACK;
}
}else if(x%2 == 0 && y%2 == 0){
BLACK;
}else if(x%2 == 0 && y%2 == 1){
if(MAZE[x/2+1][y/2+1].left) BLACK; else WHITE;
}else if(x%2 == 1 && y%2 == 0){
if(MAZE[x/2+1][y/2+1].up) BLACK; else WHITE;
}
}
if (extrabytes){ // See above - BMP lines must be of lengths divisible by 4.
for (n = 1; n <= extrabytes; n++){
fprintf(outfile, "%c", 0);
}
}
}
printf("file printed: %s\n", filename);
fclose(outfile);
return;
}
רישיון
[עריכה]אני, בעל זכויות היוצרים על היצירה הזאת, מפרסם אותה בזאת תחת הרישיונות הבאים:
![w:he:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![ייחוס](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![שיתוף זהה](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
הקובץ הזה מתפרסם לפי תנאי רישיון קריאייטיב קומונז ייחוס-שיתוף זהה 3.0 לא מותאם.
- הנכם רשאים:
- לשתף – להעתיק, להפיץ ולהעביר את העבודה
- לערבב בין עבודות – להתאים את העבודה
- תחת התנאים הבאים:
- ייחוס – יש לתת ייחוס הולם, לתת קישור לרישיון, ולציין אם נעשו שינויים. אפשר לעשות את זה בכל צורה סבירה, אבל לא בשום צורה שמשתמע ממנה שמעניק הרישיון תומך בך או בשימוש שלך.
- שיתוף זהה – אם תיצרו רמיקס, תשנו, או תבנו על החומר, חובה עליכם להפיץ את התרומות שלך לפי תנאי רישיון זהה או תואם למקור.
![]() |
מוענקת בכך הרשות להעתיק, להפיץ או לשנות את המסמך הזה, לפי תנאי הרישיון לשימוש חופשי במסמכים של גנו, גרסה 1.2 או כל גרסה מאוחרת יותר שתפורסם על־ידי המוסד לתוכנה חופשית; ללא פרקים קבועים, ללא טקסט עטיפה קדמית וללא טקסט עטיפה אחורית. עותק של הרישיון כלול בפרק שכותרתו הרישיון לשימוש חופשי במסמכים של גנו.http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue |
הנכם מוזמנים לבחור את הרישיון הרצוי בעיניכם.
היסטוריית הקובץ
ניתן ללחוץ על תאריך/שעה כדי לראות את הקובץ כפי שנראה באותו זמן.
תאריך/שעה | תמונה ממוזערת | ממדים | משתמש | הערה | |
---|---|---|---|---|---|
נוכחית | 01:41, 6 בפברואר 2011 | דקה שנייה, 732 × 492 (510 ק"ב) | Dllu (שיחה | תרומות) | {{Information |Description ={{en|1=The generation of a maze using a depth-first search algorithm. This maze is 30x20 in size. The C++ source code used to create this can be seen at w:User:Purpy Pupple/Maze.}} |Source |
אין באפשרותך לדרוס את הקובץ הזה.
שימוש בקובץ
הדפים הבאים משתמשים בקובץ הזה:
מצב המרה משנית
עדכון מצב המרה משניתשימוש גלובלי בקובץ
אתרי הוויקי השונים הבאים משתמשים בקובץ זה:
- שימוש באתר ca.wikipedia.org
- שימוש באתר de.wikipedia.org
- שימוש באתר el.wikipedia.org
- שימוש באתר en.wikipedia.org
- Depth-first search
- Talk:Maze generation algorithm
- Wikipedia:WikiProject Mathematics/Recognized content
- Wikipedia:Featured pictures/Sciences/Mathematics
- Wikipedia:Featured pictures thumbs/25
- User:Dllu
- User talk:Dllu
- Wikipedia:Featured picture candidates/February-2011
- User:Dllu/Maze
- Wikipedia:Featured picture candidates/Maze Generation 2
- Wikipedia:Picture of the day/September 2012
- Template:POTD/2012-09-19
- Wikipedia:Main Page history/2012 September 19
- Wikipedia:Reference desk/Archives/Mathematics/2012 September 19
- Portal:Mathematics/Recognized content
- שימוש באתר fa.wikipedia.org
- שימוש באתר fr.wikipedia.org
- שימוש באתר hu.wikipedia.org
- שימוש באתר hy.wikipedia.org
- שימוש באתר sr.wikipedia.org
מטא־נתונים
קובץ זה מכיל מידע נוסף, שכנראה הגיע ממצלמה דיגיטלית או מסורק שבהם הקובץ נוצר או עבר דיגיטציה.
אם הקובץ שונה ממצבו הראשוני, כמה מהנתונים להלן עלולים שלא לשקף באופן מלא את הקובץ הנוכחי.
תוכנה בשימוש | |
---|---|
מידע ליצירת קשר | http://sourceforge.net/projects/theoraconverter |