A Comprehensive PathFinding Library for Objective-C.
Based on PathFinding.js by @qiao.
- Edit your Podfile
pod 'PathFindingForObjC'
or use the master
branch of the repo :
pod 'PathFindingForObjC', :git => 'https://github.com/wbcyclist/PathFindingForObjC.git'
- Add
#import <PathFindingForObjC/PathFinding.h>
to your source file.
Disable logging
add this code in
Podfile
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if target.name.include? 'PathFindingForObjC'
preprocessorMacros = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
if preprocessorMacros.nil?
preprocessorMacros = ['$(inherited)', 'COCOAPODS=1'];
end
preprocessorMacros << 'PF_DEBUG=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessorMacros
end
end
end
end
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- Open your project in Xcode, then drag and drop
PathFindingForObjC/PathFindingForObjC
into your project - Add
#import PathFinding.h
to your source file.
Disable logging
Click on your
Project
Target, head over toBuild Settings
and search forPreprocessor Macros
. addPF_DEBUG=0
toDebug
Configuration.
PathFinding *finder = [[PathFinding alloc] initWithMapSize:CGSizeMake(6, 5)
tileSize:CGSizeMake(1, 1)
coordsOrgin:CGPointZero];
finder.heuristicType = HeuristicTypeManhattan;
finder.movementType = DiagonalMovement_Never;
// add blocks
[finder addBlockTilePositions:@[PF_CGPointToNSValue(CGPointMake(1, 2)),
PF_CGPointToNSValue(CGPointMake(2, 2)),
PF_CGPointToNSValue(CGPointMake(3, 2))
]];
// set start point
finder.startPoint = CGPointMake(2, 3);
// set end point
finder.endPoint = CGPointMake(2, 1);
// get result
NSArray *foundPaths = [finder findPathing:PathfindingAlgorithm_AStar IsConvertToOriginCoords:YES];
๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ ๐ ๐ ๐
๐ ๐ ๐ ๐ ๐ ๐
HeuristicType
:
- HeuristicTypeManhattan
- HeuristicTypeEuclidean
- HeuristicTypeOctile
- HeuristicTypeChebyshev
DiagonalMovement
:
- DiagonalMovement_Always
- DiagonalMovement_Never
- DiagonalMovement_IfAtMostOneObstacle
- DiagonalMovement_OnlyWhenNoObstacles
PathfindingAlgorithm
:
- PathfindingAlgorithm_AStar
- PathfindingAlgorithm_BestFirstSearch
- PathfindingAlgorithm_Dijkstra
- PathfindingAlgorithm_JumpPointSearch
- PathfindingAlgorithm_BreadthFirstSearch
- PathfindingAlgorithm_BiAStar
- PathfindingAlgorithm_BiBestFirst
- PathfindingAlgorithm_BiDijkstra
- PathfindingAlgorithm_BiBreadthFirst
##DEMO
- OSX Download
- iOS
- MIT