File:MAZE 30x20 Prim.ogv
From HandWiki
MAZE_30x20_Prim.ogv (file size: 1.1 MB, MIME type: application/ogg)
This file is from a shared repository and may be used by other projects. The description on its file description page there is shown below.
|
Summary
DescriptionMAZE 30x20 Prim.ogv |
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 |
|
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](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
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.
Captions
The generation of a maze using a randomized Prim's algorithm. This maze is 30x20 in size.
Items portrayed in this file
depicts
some value
5 February 2011
application/ogg
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Dimensions | User | Comment | |
---|---|---|---|---|
current | 17:13, 11 June 2015 | (1.1 MB) | imagescommonswiki>Dllu | Fixes a bug that caused it to be not actually Prim's algorithm. |
File usage
The following file is a duplicate of this file (more details):
- File:MAZE 30x20 Prim.ogv from Wikimedia Commons
The following 2 pages use this file:
Retrieved from "https://handwiki.org/wiki/File:MAZE_30x20_Prim.ogv"