import { Point , Tile } from '../core/Components' ; import Navigator from '../core/Navigator' ; import { Node } from './Node' ; /**
 * Pathfinder performs algorithms operations on the grid
 * Uses the navigator rank and expand nodes
 */ abstract class Pathfinder { protected recentSearch : Node [ ] = [ ] ; protected navigator : Navigator ; constructor ( navigator ) { this . navigator = navigator ; } setNavigator ( navigator ) { this . navigator = navigator ; } getNavigator ( ) { return this . navigator ; } getRecentNodes ( ) { return this . recentSearch . length ; } clearRecentSearch ( ) { this . recentSearch = [ ] ; } getRecentGenerations ( ) { return this . recentSearch . slice ( ) ; } protected addRecent ( node ) { this . recentSearch . push ( node ) ; } abstract getAlgorithmName ( ) ; param initial param goal abstract findPath ( initial , goal ) ; } param bottomLeaf export function reconstructPath ( bottomLeaf ) { return reconstructPathReversed ( bottomLeaf ) . reverse ( ) ; } param bottomLeaf export function reconstructPathReversed ( bottomLeaf ) { const path = [ ] ; while ( bottomLeaf . parent !== null ) { path . push ( bottomLeaf . tile ) ; bottomLeaf = bottomLeaf . parent ; } return path ; } export default Pathfinder ;