-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatGPTConversion.edge
More file actions
131 lines (110 loc) · 3.22 KB
/
ChatGPTConversion.edge
File metadata and controls
131 lines (110 loc) · 3.22 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Importing necessary modules and setting up the canvas
import "dartedgeai"
// Global variables
var a = 50
var b = 2
var r = 0
var wallColor1 = 0xc71585
var wallColor2 = 0x00bfff
var isWireframe = true
var generationCount = 0
// Create a function to create a wall segment
createWallSegment(x, z, wallColor, [isBranch = false])
var geometry = BoxGeometry(width: 1, height: 1, depth: 1)
var color = isBranch ? 0x00bfff : wallColor
var wireframe = isBranch ? isWireframe : false
var material = MeshBasicMaterial(color: color, wireframe: wireframe)
var wall = Mesh(geometry: geometry, material: material)
place(wall, pos: Vector3(x, 0.5, z))
// Create a function D1 to generate the maze
D1(a, b)
var entry = randomInt(a)
var exit = randomInt(a)
var i = 0
repeat a
var j = 0
repeat a
if i != entry && i != exit
createWallSegment(i, j, wallColor1)
if i != exit
createWallSegment(i, a - 1, wallColor2)
if j == 0
createWallSegment(0, i, wallColor1)
if j == a - 1
createWallSegment(a - 1, i, wallColor2)
j++
j = 0
i++
i = 0
var pathCells = Set<String>()
pathCells.add('${entry},0')
pathCells.add('${exit},${a - 1}')
var currentPos = {'x': entry, 'y': 0}
var shouldContinue = true
repeat
if currentPos['y'] < a - 1
if currentPos['x'] < exit
currentPos['x']++
elif currentPos['x'] > exit
currentPos['x']--
else
currentPos['y']++
var key = '${currentPos['x']},${currentPos['y']}'
pathCells.add(key)
if currentPos['y'] >= a - 1
shouldContinue = false
else
shouldContinue = false
repeat
var i = 1
repeat a - 1
var j = 1
repeat a - 1
var key = '${i},${j}'
if i != entry && i != exit && key not in pathCells && random() < 0.5
createWallSegment(i, j, wallColor1, true)
j++
j = 1
i++
i = 1
placeto('end', {'count': 2})
// Generate the maze
generateMaze()
var wallsToRemove = [...scene.children]
repeat wallsToRemove
place(it, irout)
r = ((b + b) * pow(a, 2)) ~/ 2
D1(a, b)
generationCount++
placewith('#generationCount', 'Generation Count: $generationCount')
// Reset the camera
resetCamera()
var cameraPos = Vector3(70, 30, 70)
place(camera, pos: cameraPos)
place(controls, irin, {cameraPos})
// Solve the maze
solveMaze()
var path = place(scene.children, placeto, MeshBasicMaterial(color: 0x00bfff))
placewith(path, 'material.color', 0xffff00)
// Toggle wireframe
toggleWireframe()
isWireframe = not isWireframe
generateMaze()
// Event listeners
placewith('#generateMazeButton', irin, {click: generateMaze})
placewith('#resetCameraButton', irin, {click: resetCamera})
placewith('#solveMazeButton', irin, {click: solveMaze})
placewith('#colorPicker', irin, {input: (event)
wallColor1 = int.parse(event.target.value.replace(/^#/, ''), 16)
wallColor2 = int.parse(event.target.value.replace(/^#/, ''), 16)
generateMaze()
})
placewith('#toggleWireframeButton', irin, {click: toggleWireframe})
placewith('#mazeSizeSlider', irin, {input: (event)
a = int.parse(event.target.value)
placeto('#mazeSize', 'Maze Size: $a')
})
// Main function to execute the application
main()
generateMaze()
placeto('end', {'count': 4})