Giter Club home page Giter Club logo

a-star-objc-c's Introduction

a-star-obj-c

A* Pathfinding Algorithm implemented in Objective-C

Installation

You should clone this project and just copy/paste the files into your project, maybe under a new group.

Usage

There are three things you need to worry about while using this library:

##HSAIPathFindingNode

The HSAIPathFindingNode contains all the logic for scoring a particular point, as well as comparing itself to other points. You shouldn't need to subclass this object, just use it as is.

##HSAIPathFindingDelegate

There are two required tasks for the HSAIPathFindingDelegate:

  • Figure out whether or not any given HSAIPathFindingNode is passable or not
  • Figure out the list of neighbors for any given HSAIPathFindingNode

In addition to the required delegate methods, there are two other methods available:

  • nodeWasAddedToOpenList: (HSAIPathFindingNode *)node: This is called whenever a node is added to the open list
  • nodeWasAddedToPath: (HSAIPathFindingNode *)node: This is called whenever a node is determined to be on the path

##HSAIPathFinding

You shouldn't need to subclass this either.

###HSAIPathFindingHeuristic

There are three different ways to calculate the heuristic between any given node and the goal,

[HSAIPathFindingHeuristic diagonalHeuristic] - calculates the heuristic assuming 8 directions of travel [HSAIPathFindingHeuristic manhattanHeuristic] - calculates the heuristic assuming 4 directions of travel [HSAIPathFindingHeuristic euclidianHeuristic] - calculates the heuristic assuming any direction of travel

I've been using it like this:

// This is the class that will do the path finding
// MyPathFinder.h

#include <Foundation/Foundation.h>
#include "HSAIPathFinding.h"

@interface MyPathFinder : NSObject <HSAIPathFindingDelegate>
- (void) findPathFrom: (CGPoint) start to: (CGPoint): end;
@end

// MyPathFinder.m

@implementation MyPathFinder
- (void) findPathFrom: (CGPoint) start to: (CGPoint): end
{
  HSAIPathFinding *pathFinder = [[HSAIPathFinding alloc] init];
  pathFinder.delegate = self;
  pathFinder.heuristic = [HSAIPathFindingHeuristic diagonalHeuristic];

  [pathFinder findPathFrom: start to: end]; // returns an array of HSAIPathFindingNodes
}

- (BOOL) nodeIsPassable: (HSAIPathFindingNode *) node
{
  // The logic you use to figure out if a node is passable.
  return YES;
}

- (NSArray *) neighborsFor: (HSAIPathFindingNode *) node
{
  // The logic you use to figure out neighbors
  return [[NSArray alloc] init];
}

@end

a-star-objc-c's People

Contributors

jaredonline avatar

Stargazers

 avatar Damiaan Dufaux avatar Fantasy avatar  avatar Nikola Novak avatar Leonardo Wistuba de França avatar Quique Fagoaga avatar  avatar John Joyce avatar  avatar Haithem BH avatar Andrew Apperley avatar Ephrat avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.