-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prim.cpp
117 lines (103 loc) · 2.65 KB
/
Prim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <vector>
#include <time.h>
#include <Windows.h>
#define WALL 0
#define PATH 1
#define PLAYER 2
#define GOAL 3
using namespace std;
struct Node
{
int x;
int y;
bool visited;
int type;
Node *parent;
void open(){
}
}*map[25][75];
vector<Node*> asu;
void anjingMap(){
for(int i=0;i<25;i++)
{
for(int j=0;j<75;j++)
{
if(map[i][j]->type==WALL){
cout<<(char)219;
}else if(map[i][j]->type==PLAYER){
cout<<(char)2;
}else if(map[i][j]->type==PATH){
cout<<' ';
}
}
cout << endl;
}
}
int main()
{
for(int i=0;i<25;i++)
{
for(int j=0;j<75;j++)
{
map[i][j]=(Node *)malloc(sizeof(Node));
map[i][j]->x=j;
map[i][j]->y=i;
map[i][j]->type= WALL;
map[i][j]->visited=false;
}
}
anjingMap();
asu.push_back(map[13][36]);
map[13][36]->type=PLAYER;
while(!asu.empty()){
int index = rand()%asu.size();
Node * asusementara=asu[index];
asu.erase(asu.begin()+index);
//kiri
if(asusementara->x-2>0&&!map[asusementara->y][asusementara->x-2]->visited){
asu.push_back(map[asusementara->y][asusementara->x-2]);
map[asusementara->y][asusementara->x-2]->type=PATH;
map[asusementara->y][asusementara->x-2]->visited=true;
map[asusementara->y][asusementara->x-1]->type=PATH;
map[asusementara->y][asusementara->x-1]->visited=true;
//cout<<"kiri"<<endl;
}
//kanan
if(asusementara->x+2<74&&!map[asusementara->y][asusementara->x+2]->visited){
asu.push_back(map[asusementara->y][asusementara->x+2]);
map[asusementara->y][asusementara->x+2]->type=PATH;
map[asusementara->y][asusementara->x+2]->visited=true;
map[asusementara->y][asusementara->x+1]->type=PATH;
map[asusementara->y][asusementara->x+1]->visited=true;
//cout<<"kanan"<<endl;
}
//atas
if(asusementara->y-2>0&&!map[asusementara->y-2][asusementara->x]->visited){
asu.push_back(map[asusementara->y-2][asusementara->x]);
map[asusementara->y-2][asusementara->x]->type=PATH;
map[asusementara->y-2][asusementara->x]->visited=true;
map[asusementara->y-1][asusementara->x]->type=PATH;
map[asusementara->y-1][asusementara->x]->visited=true;
//cout<<"atas"<<endl;
}
//bawah
if(asusementara->y+2<24&&!map[asusementara->y+2][asusementara->x]->visited){
asu.push_back(map[asusementara->y+2][asusementara->x]);
map[asusementara->y+2][asusementara->x]->type=PATH;
map[asusementara->y+2][asusementara->x]->visited=true;
map[asusementara->y+1][asusementara->x]->type=PATH;
map[asusementara->y+1][asusementara->x]->visited=true;
//cout<<"bawah"<<endl;
}
asusementara->visited=true;
system("cls");
Sleep(2);
anjingMap();
//cin.get();
cout<<endl;
cout<<endl;
}
cin.get();
return 0;
}