-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_Draw_cube_experiments.cpp
101 lines (90 loc) · 1.9 KB
/
Create_Draw_cube_experiments.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
#include <iostream>
#include <cstdlib>
using namespace std;
unsigned char array_byte_map[3][3][3] = {
{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
},
{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
},
{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
}
};
void Create_Random_Figure(unsigned char sum_bricks = 4) {
int posx = rand() % 3;
int posy = rand() % 3;
int posz = rand() % 3;
array_byte_map[posz][posy][posx] = 1;
for (int i = 0; i < sum_bricks; i++) {
bool brick_set = false;
while (!brick_set) {
char next_coordinate = (rand() % 3 + 1) * (rand() % 3 - 1);
switch (next_coordinate) {
case -1:
if (posz > 0){
if (array_byte_map[posz - 1][posy][posx] != 1) {
posz--;
brick_set = true;
}
}
break;
case 1:
if (posz < 2){
if (array_byte_map[posz + 1][posy][posx] != 1) {
posz++;
brick_set = true;
}
}
break;
case -2:
if (posy > 0){
if (array_byte_map[posz][posy - 1][posx] != 1) {
posy--;
brick_set = true;
}
}
break;
case 2:
if (posy < 2){
if (array_byte_map[posz][posy + 1][posx] != 1) {
posy++;
brick_set = true;
}
}
break;
case -3:
if (posx > 0){
if (array_byte_map[posz][posy][posx - 1] != 1) {
posx--;
brick_set = true;
}
}
break;
case 3:
if (posx < 2){
if (array_byte_map[posz][posy][posx + 1] != 1) {
posx++;
brick_set = true;
}
}
break;
default:
break;
}
if (brick_set) {
array_byte_map[posz][posy][posx] = 1;
}
}
}
}
int main() {
return 0;
}