Skip to content

Commit 28c7415

Browse files
committed
Fixed
1 parent 0992b87 commit 28c7415

File tree

5 files changed

+66
-25
lines changed

5 files changed

+66
-25
lines changed

src/components/Algorithms/Maze/Generation/BinaryTreeCreation.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function BinaryTreeCreation(board) {
3636
}
3737
}
3838
}
39+
3940
for (var x = 0; x < numPoints; x++) {
4041
let node = board[x];
4142

@@ -48,6 +49,15 @@ export function BinaryTreeCreation(board) {
4849
node.type = '_wall_';
4950
}
5051
}
51-
// console.log('BinaryTreeCreation: ' + board.length);
52+
53+
let [setG, setS] = [false, false];
54+
// while (!setG || !setS) {
55+
// let node = board[w];
56+
//
57+
// if (node.type === '_wall_') {
58+
// continue;
59+
// }
60+
//
61+
// }
5262
}
5363

src/components/Algorithms/Maze/Solving/RecursiveSolve.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ import {_FindCellVisitState, _FindCellTypeState, _FindCell} from '../Tools';
33
// import exit from 'exit';
44

55

6+
/*
7+
* Recursive backtracking algorithm to solve a solvable maze.
8+
*/
69
export function RecursiveSolve(board, start, end, position) {
710
let copyBoard = board;
11+
let current = start;
12+
let path = [];
13+
while (current !== end) {
14+
path.push(current);
15+
current = board[current.parent];
16+
}
817

918

1019
}

src/components/Algorithms/Maze/Tools.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ export function _BoardReset(board) {
4444
board[i].type = DEFAULT_TYPE;
4545
}
4646
}
47+
48+
export function _VisitReset(board) {
49+
for (let i = 0; i < board.length; i++) {
50+
board[i].visited = false;
51+
}
52+
}

src/components/BoardCanvas/Cells.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,24 @@ import {BinaryTreeCreation} from '../Algorithms/Maze/Generati
1313

1414

1515

16-
export const TEST_COLOR = '#FF66CC', BURN_COLOR = '#fad6ee', PATH_COLOR = '#63caef', WALL_COLOR = '#1c1b1b', GOAL_COLOR = '#30fa04', START_COLOR = '#ff0000', SELECTED_COLOR = '#ffd300', FLOOR_COLOR = '#ffffff', DEFAULT_COLOR = '#8f8d8d', FLOOR_TYPE = '_floor_', DEFAULT_TYPE = '_default_', WALL_TYPE = '_wall_', PATH_TYPE = '_path_', GOAL_TYPE = '_goal_', START_TYPE = '_start_', TEST_TYPE = '_test_';
17-
const tempOBJ = new THREE.Object3D();
16+
export const TEST_COLOR = '#FF66CC';
17+
export const BURN_COLOR = '#fad6ee';
18+
export const PATH_COLOR = '#63caef';
19+
export const WALL_COLOR = '#624646';
20+
export const GOAL_COLOR = '#30fa04';
21+
export const START_COLOR = '#ff0000';
22+
export const SELECTED_COLOR = '#ffd300';
23+
export const FLOOR_COLOR = '#ffffff';
24+
export const DEFAULT_COLOR = '#8f8d8d';
25+
export const FLOOR_TYPE = '_floor_';
26+
export const DEFAULT_TYPE = '_default_';
27+
export const WALL_TYPE = '_wall_';
28+
export const PATH_TYPE = '_path_';
29+
export const GOAL_TYPE = '_goal_';
30+
export const START_TYPE = '_start_';
31+
export const TEST_TYPE = '_test_';
32+
33+
export const tempOBJ = new THREE.Object3D();
1834

1935

2036
function getColor(type) {
@@ -40,32 +56,42 @@ function getColor(type) {
4056

4157

4258

43-
function updateInstancedMeshMatrices({mesh, board}) {
59+
function updateInstancedMeshMatrices({mesh, board, colorAttrib, colorArray}) {
4460
if (!mesh) {
4561
return;
4662
}
63+
const numPoints = board.length;
64+
4765
// transform mesh to world space
4866
for (let i = 0; i < board.length; ++i) {
4967
const {x, y, z} = board[i];
5068
tempOBJ.position.set(x, y, z);
5169
tempOBJ.rotation.set(0.5 * Math.PI, 0, 0); // Look at the origin
5270
tempCOLOR.set(getColor(board[i].type));
71+
tempCOLOR.toArray(colorArray, i * 3);
5372
tempOBJ.updateMatrix();
54-
mesh.setMatrixAt(i, tempOBJ.matrix, tempCOLOR);
73+
mesh.setMatrixAt(i, tempOBJ.matrix);
5574
}
75+
colorAttrib.current.needsUpdate = true;
5676
mesh.instanceMatrix.needsUpdate = true;
5777
}
5878

5979

60-
function updateInstancedMeshColors({mesh, board}) {
61-
62-
}
80+
// function updateInstancedMeshColors({mesh, board}) {
81+
// for (let i = 0; i < board.length; ++i) {
82+
// tempCOLOR.set(getColor(board[i].type));
83+
// mesh.setColorAt(i, tempCOLOR);
84+
// }
85+
//
86+
// return {colorAttrib, colorArray};
87+
//
88+
// }
6389

6490

6591

6692
const tempCOLOR = new THREE.Color();
6793

68-
const usePointColorsHook = ({board, mazeType}) => {
94+
const usePointColorsHook = ({board}) => {
6995
console.log('usePointColorsHook');
7096
const numPoints = board.length;
7197
const colorAttrib = useRef();
@@ -78,7 +104,7 @@ const usePointColorsHook = ({board, mazeType}) => {
78104
tempCOLOR.toArray(colorArray, i * 3);
79105
}
80106
colorAttrib.current.needsUpdate = true;
81-
}, [board, mazeType, colorArray]);
107+
}, [board, colorArray]);
82108

83109
return {colorAttrib, colorArray};
84110
};
@@ -162,10 +188,12 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
162188

163189
const {colorAttrib, colorArray} = usePointColorsHook({board});
164190

191+
165192
useEffect(() => {
166193
console.log('Board updated');
167-
updateInstancedMeshMatrices({mesh: meshRef.current, board});
168-
}, [layoutType, mazeType]);
194+
updateInstancedMeshMatrices({mesh: meshRef.current, board, colorAttrib, colorArray});
195+
}, [board, layoutType, mazeType]);
196+
169197

170198

171199
return (

src/components/BoardCanvas/Layouts.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,4 @@ export function standardLayout(board) {
8686
}
8787

8888

89-
/*
90-
* Recursive backtracking algorithm to generate a solvable maze.
91-
*/
92-
const backtrack = (board, start, goal) => {
93-
let current = start;
94-
let path = [];
95-
while (current !== goal) {
96-
path.push(current);
97-
current = board[current.parent];
98-
}
99-
path.push(current);
100-
return path;
101-
};
89+

0 commit comments

Comments
 (0)