MAZE_30x20_Prim.ogv (Ogg Theora video file, length 1 min 0 s, 732 × 492 pixels, 154 kbps, file size: 1.1 MB)

Wikipedia

 This is a featured picture on the English language Wikipedia (Featured pictures) and is considered one of the finest images. See its nomination here.
 This is a featured picture on the Persian language Wikipedia (نگاره‌های برگزیده) and is considered one of the finest images. See its nomination here.

If you think this file should be featured on Wikimedia Commons as well, feel free to nominate it.
If you have an image of similar quality that can be published under a suitable copyright license, be sure to upload it, tag it, and nominate it.

Summary

Description
English: The generation of a maze using a randomized Prim's algorithm. This maze is 30x20 in size.
Date
Source Own work
Author Purpy Pupple
Other versions
Using depth-first search instead of Prim's algorithm.

Source code

#include <iostream>
#include <queue>
#include <random>
#include <utility>
#include <vector>
#include <cstdio>

using namespace std;

const int xsize = 20;
const int ysize = 30;

int main() {
    random_device rd;
    mt19937 en(rd());
    uniform_real_distribution<double> uni(0,1);

    vector<int> v(xsize*ysize, 0);
    vector<int> w(xsize*ysize*2, 1);
    vector<vector<pair<double, pair<int, int>>>> e(xsize*ysize);

    for(int i=0; i<xsize; i++) {
        for(int j=0; j<ysize; j++) {
            int k = i*ysize + j;
            if(i>0) e[k].push_back(make_pair(uni(en), make_pair(k, (i-1)*ysize + j)));
            if(j>0) e[k].push_back(make_pair(uni(en), make_pair(k, i*ysize + (j-1))));
            if(i<xsize-1) e[k].push_back(make_pair(uni(en), make_pair(k, (i+1)*ysize + j)));
            if(j<ysize-1) e[k].push_back(make_pair(uni(en), make_pair(k, i*ysize + (j+1))));
        }
    }
    priority_queue <pair<double, pair<int, int>>> frontier;
    int x = 0, y = 0;
    v[x*ysize + y] = 1;
    for(auto k : e[0]) {
        frontier.push(k);
    }
    while(!frontier.empty()) {
        auto z = frontier.top();
        frontier.pop();
        int a = z.second.first;
        int b = z.second.second;
        if(v[b]) continue;
        v[b] = 2;
        int aa = min(a,b);
        int bb = max(a,b);
        if(bb-aa == 1) {
            w[2*aa] = 0;
        } else {
            w[2*aa+1] = 0;
        }
        for(auto k : e[b]) {
            if(!v[k.second.second]) {
                frontier.push(k);
            }
        }
        // print the thing lol
        for(int j=0; j<2*ysize+1; j++) {
            cout << "1 ";
        }
        for(int i=0; i<xsize; i++) {
            cout << endl << "1 ";
            for(int j=0; j<ysize; j++) {
                cout << "102"[v[i*ysize + j]] << " " << "01"[w[2*(i*ysize + j)]] << " ";
            }
            cout << endl << "1 ";
            for(int j=0; j<ysize; j++) {
                cout << "01"[w[2*(i*ysize + j)+1]] << " 1 ";
            }
        }
        cout << endl;
        v[b] = 1;
    }
}

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
You may select the license of your choice.

Captions

The generation of a maze using a randomized Prim's algorithm. This maze is 30x20 in size.

Items portrayed in this file

depicts

5 February 2011

application/ogg

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current22:13, 11 June 20151 min 0 s, 732 × 492 (1.1 MB)DlluFixes a bug that caused it to be not actually Prim's algorithm.
01:46, 6 February 20111 min 1 s, 732 × 492 (563 KB)Dllu{{Information |Description ={{en|1=The generation of a maze using a randomized Prim's 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

Global file usage

Metadata