File:MAZE 30x20 PRIM.gif
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
MAZE_30x20_PRIM.gif (732 × 492 pixels, file size: 4.24 MB, MIME type: image/gif, looped, 599 frames, 1 min 0 s)
Note: Due to technical limitations, thumbnails of high resolution GIF images such as this one will not be animated. The limit on Wikimedia Commons is width × height × number of frames ≤ 100 million.
File information
Structured data
Captions
Summary
[edit]DescriptionMAZE 30x20 PRIM.gif |
English: The generation of a maze using a randomized variant of 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. |
Date | |
Source | Own work |
Author | Purpy Pupple |
Other versions |
C++11 source code
[edit]#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
[edit]I, the copyright holder of this work, hereby publish it under the following licenses:
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.
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.http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue |
You may select the license of your choice.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 23:10, 11 June 2015 | 732 × 492 (4.24 MB) | Dllu (talk | contribs) | Fix a bug | |
00:37, 5 December 2012 | 732 × 492 (4.02 MB) | Dllu (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file: