Skip to content

Commit b465170

Browse files
committed
Functioning cell lookup. Need to useAnimationHook render to board
1 parent 710b5a2 commit b465170

10 files changed

Lines changed: 108 additions & 141 deletions

File tree

‎src/components/Algorithms/Display.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import './display.css';
1010
the game control interface, and the navigation bar.
1111
1212
"The Mediator"
13-
or a psudo
13+
or a psudo
1414
"Layers Pattern"
1515
1616
*/
@@ -21,16 +21,16 @@ export default function Display() {
2121
const [selectedStartPoint, setSelectedStartPoint] = useState(null);
2222
// const board = new Array(10000).fill(0).map(
2323
const board = new Array(3844).fill(0).map(
24-
(i, id, type: string) => ({id}));
24+
(i, id, type: string = '_wall_', visited: boolean = false) => ({id, type, visited}));
2525

26-
const boardRef = useRef(); // Mutable(Persistant) board reference object.
26+
const boardRef = useRef(); // Mutable(Persistant) board reference object.
2727

2828
const handleResetCamera = () => {
2929
boardRef.current.resetCamera();
3030
};
31-
const handleResetBoard = () => {
31+
const handleResetBoard = () => {
3232
boardRef.current.resetBoard();
33-
}
33+
};
3434

3535

3636
return (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {directions} from './Directions';
2+
import {_FindCellVisitState, _FindCellTypeState, _FindCell} from './Tools';
3+
4+
5+
6+
7+
export default function BinaryTreeCreation(board) {
8+
for (var i = 0; i < board.length; i++) {
9+
let direction = Math.floor(Math.random() * 4);
10+
// console.log(board[i]);
11+
12+
// console.log(direction);
13+
// console.log(directions[direction].x);
14+
// console.log(board[i].x + directions[direction].x);
15+
let xcord = board[i].x + directions[direction].x;
16+
let ycord = board[i].y + directions[direction].y;
17+
const cell = board.find(item => Math.floor(item.x) === Math.floor(xcord) && Math.floor(item.y) === Math.floor(ycord));
18+
19+
20+
if (cell) {
21+
if (!cell.visited) {
22+
// console.log(cell);
23+
board[cell.id].visited = true;
24+
board[cell.id].type = '_wall_';
25+
}
26+
}
27+
}
28+
console.log('BinaryTreeCreation: ' + board.length);
29+
return board;
30+
}

‎src/components/Algorithms/Maze/Generation/BreathFirstSearchCreation.js‎

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var directions = new Array();
2+
directions.push({x: 0, y: 0.5});
3+
directions.push({x: 0.5, y: 0});
4+
directions.push({x: 0, y: -0.5});
5+
directions.push({x: -0.5, y: 0});
6+
7+
export {directions};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class GrowingTree {
2+
constructor(n) {
3+
this.id = number;
4+
this.name = string;
5+
this.description = strin;
6+
this.image = string;
7+
this.price = number;
8+
this.category = string;
9+
this.created_at = string;
10+
this.updated_at = strin;
11+
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Quick selection test
3+
*/
4+
export const _FindCellVisitState = (board, x, y) => {
5+
for (let i = 0; i < board.length; i++) {
6+
if (Math.floor(board[i].x) === Math.floor(x) && Math.floor(board[i].y) === Math.floor(y)) {
7+
board[i].type = '_test_';
8+
return board[i].visited;
9+
}
10+
}
11+
};
12+
13+
14+
export const _FindCellTypeState = (board, x, y) => {
15+
for (let i = 0; i < board.length; i++) {
16+
if (Math.floor(board[i].x) === Math.floor(x) && Math.floor(board[i].y) === Math.floor(y)) {
17+
board[i].type = '_test_';
18+
return board[i].visited;
19+
}
20+
}
21+
};
22+
23+
24+
export function _FindCell(board, x, y) {
25+
for (let i = 0; i < board.length; i++) {
26+
console.log(Math.floor(board[i].x), Math.floor(x));
27+
28+
if (Math.floor(board[i].x) === Math.floor(x) && Math.floor(board[i].y) === Math.floor(y)) {
29+
board[i].type = '_test_';
30+
return board[i];
31+
}
32+
}
33+
};
34+

‎src/components/Algorithms/MinMax/Board.js‎

Lines changed: 0 additions & 121 deletions
This file was deleted.

‎src/components/BoardCanvas/Cells.js‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import * as React from 'react';
44
import {useEffect, useRef, useMemo} from 'react';
55
import * as THREE from 'three';
6-
import {a} from 'react-spring/three';
7-
import {useAnimationHook} from './layouts';
6+
import {a} from 'react-spring/three';
7+
import {useAnimationHook, useGenerateMaze} from './layouts';
88

99

1010

@@ -196,12 +196,6 @@ const Cells = ({board, layoutType, selectedPoint, onSelectPoint, groupingWallPoi
196196
return path;
197197
};
198198

199-
const directions = {
200-
south: [0, -1],
201-
north: [0, 1],
202-
west : [-1, 0],
203-
east : [1, 0],
204-
};
205199

206200
/*
207201
* Quick selection test
@@ -271,11 +265,12 @@ const Cells = ({board, layoutType, selectedPoint, onSelectPoint, groupingWallPoi
271265
/* useDrag */
272266
});
273267

274-
generateMaze(board);
275-
findCell(1, 1);
268+
// generateMaze(board);
269+
// findCell(1, 1);
276270
// initializeCellColors();
277271
const {colorAttrib, colorArray} = usePointColorsHook({board, selectedPoint});
278272

273+
279274
// const { colorAttrib: groupingColorAttrib, colorArray: groupingColorArray } = useGroupColors({
280275
// board,
281276
// type: WALL_TYPE,
@@ -298,7 +293,7 @@ const Cells = ({board, layoutType, selectedPoint, onSelectPoint, groupingWallPoi
298293
{/* args = {[colorArray, 3]}*/}
299294
{/* />*/}
300295
{/*</sphereBufferGeometry>*/}
301-
<boxBufferGeometry attach = "geometry" args = {[0.6, 0.3, 0.6, 18]}>
296+
<boxBufferGeometry attach = "geometry" args = {[1, 0.5, 1, 18]}>
302297
<instancedBufferAttribute
303298
ref = {colorAttrib}
304299
attachObject = {['attributes', 'color']}

‎src/components/BoardCanvas/OrbitControls.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default forwardRef(OrbitControls);
115115

116116

117117
/*
118-
* const usePointColorsHook = ({board, selectedPoint}) => {
118+
const usePointColorsHook = ({board, selectedPoint}) => {
119119
const numPoints = board.length;
120120
const colorAttrib = useRef();
121121
const colorArray = useMemo(() => new Float32Array(numPoints * 3), [

‎src/components/BoardCanvas/layouts.js‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react';
22
import {useEffect, useRef} from 'react';
33
import {useSpring} from 'react-spring/three';
4+
import BinaryTreeCreation from '../Algorithms/Maze/Generation/BinaryTreeCreation';
5+
46

57
/*
68
* Board type selector hook.
@@ -59,6 +61,14 @@ function interpolateSourceTarget(board, progress) {
5961
}
6062

6163

64+
export const useGenerateMaze = ({board, layoutType}) => {
65+
useEffect(() => {
66+
67+
BinaryTreeCreation(board);
68+
69+
}, [board]);
70+
}
71+
6272
export function useAnimationHook({board, layoutType, onFrame}) {
6373

6474
useTargetLayoutHook({board, layoutType});
@@ -70,10 +80,9 @@ export function useAnimationHook({board, layoutType, onFrame}) {
7080
from : {animationInProgress: 0},
7181
reset : layoutType !== prevLayout.current,
7282
onFrame : ({animationInProgress}) => {
73-
// interpolate based on progress
83+
// insert based on progress of animation
7484
interpolateSourceTarget(board, animationInProgress);
75-
// callback to indicate board has updated
76-
onFrame({animationInProgress});
85+
onFrame({animationInProgress}); // callback
7786
},
7887
});
7988
prevLayout.current = layoutType;

0 commit comments

Comments
 (0)