@@ -3,6 +3,7 @@ import useWindowDimensions from '../utils/useWindowDimensions';
33import '../styles/pathfinding.css' ;
44import { HiChevronRight } from "react-icons/hi" ;
55import { Cell } from '../algorithms/utils/PathfindingUtils' ;
6+ import { BreadthFirstSearch } from '../algorithms/pathfinding/BreadthFirstSearch.ts' ;
67
78const PathfindingVisualiser : React . FC = ( ) => {
89 const { width = 0 , height = 0 } = useWindowDimensions ( ) ;
@@ -109,30 +110,38 @@ const PathfindingVisualiser: React.FC = () => {
109110 } ) ;
110111 } ;
111112
113+ function triggerBFS ( ) {
114+ let visited = BreadthFirstSearch ( maze , maze [ startNode [ 0 ] ] [ startNode [ 1 ] ] , maze [ endNode [ 0 ] ] [ endNode [ 1 ] ] ) ;
115+ console . log ( visited ) ;
116+ }
117+
112118 return (
113- < div onMouseUp = { handleMouseUp } >
114- { maze . map ( ( row , rowIndex ) => (
115- < div key = { rowIndex } className = "pathfinding-row" id = { 'row-' + rowIndex } >
116- { row . map ( ( cell , colIndex ) => (
117- < div
118- key = { colIndex }
119- onMouseDown = { ( ) => handleMouseDown ( rowIndex , colIndex ) }
120- onMouseEnter = { ( ) => handleMouseEnter ( rowIndex , colIndex ) }
121- style = { {
122- width : '26px' ,
123- height : '26px' ,
124- backgroundColor : cell . start ? 'lightblue' : ( cell . end ? 'lightgreen' : ( cell . wall ? 'black' : 'white' ) ) ,
125- border : '.5px solid lightblue' ,
126- display : 'flex' ,
127- alignItems : 'center' ,
128- justifyContent : 'center'
129- } } >
130- { cell . start ? < HiChevronRight style = { { color : 'black' , fontSize : '26px' } } /> : '' }
131- { cell . end ? < HiChevronRight style = { { color : 'black' , fontSize : '26px' , transform : 'rotate(180deg)' } } /> : '' }
132- </ div >
133- ) ) }
134- </ div >
135- ) ) }
119+ < div >
120+ < div onMouseUp = { handleMouseUp } >
121+ { maze . map ( ( row , rowIndex ) => (
122+ < div key = { rowIndex } className = "pathfinding-row" id = { 'row-' + rowIndex } >
123+ { row . map ( ( cell , colIndex ) => (
124+ < div
125+ key = { colIndex }
126+ onMouseDown = { ( ) => handleMouseDown ( rowIndex , colIndex ) }
127+ onMouseEnter = { ( ) => handleMouseEnter ( rowIndex , colIndex ) }
128+ style = { {
129+ width : '26px' ,
130+ height : '26px' ,
131+ backgroundColor : cell . start ? 'lightblue' : ( cell . end ? 'lightgreen' : ( cell . visited ? 'orange' : ( cell . wall ? 'black' : 'white' ) ) ) ,
132+ border : '.5px solid lightblue' ,
133+ display : 'flex' ,
134+ alignItems : 'center' ,
135+ justifyContent : 'center'
136+ } } >
137+ { cell . start ? < HiChevronRight style = { { color : 'black' , fontSize : '26px' } } /> : '' }
138+ { cell . end ? < HiChevronRight style = { { color : 'black' , fontSize : '26px' , transform : 'rotate(180deg)' } } /> : '' }
139+ </ div >
140+ ) ) }
141+ </ div >
142+ ) ) }
143+ </ div >
144+ < button onClick = { ( ) => triggerBFS ( ) } > </ button >
136145 </ div >
137146 ) ;
138147} ;
0 commit comments