src/libUnuk/AStar.h
Go to the documentation of this file.

    00001 #ifndef _ASTAR_H_
    00002 #define _ASTAR_H_
    00003 #include "Node.h"
    00004
    00005 class AStar {
    00006 public:
    00007   AStar(void);
    00008   ~AStar(void);
    00009
    00010   Func udCost;          // Called when the cost is needed.
    00011   Func udValid;         // Check the validity of the coordanate.
    00012   Func udNotifyChild;   // Child is called/checked (LinkChild).
    00013   Func udNotifyList;    // node is added to the open/closed list.
    00014
    00015   void *CBData;         // Data passed back to the callback function.
    00016   void *NCData;         // Data paseed back to to notify child.
    00017
    00018   bool GeneratePath(int startx, int starty, int destx, int desty);
    00019   int Step(void);
    00020   int InitStep(int startx, int starty, int destx, int desty);
    00021   void SetRows(int r) { m_rows = r; }
    00022   void Reset(void) { m_best = NULL; }
    00023
    00024   Node *GetBestNode(void) { return m_best; }
    00025
    00026 private:
    00027   int m_rows; // Used to calculate unique ID for node->number.
    00028   int m_startx;
    00029   int m_starty;
    00030   int m_destx;
    00031   int m_desty;
    00032
    00033   int m_ID;
    00034
    00035
    00036   // Node list.
    00037   Node *m_open;
    00038   Node *m_closed;
    00039   Node *m_best;
    00040
    00041   Stack *m_stack;
    00042
    00043   // Private methods.
    00044   void AddToOpen(Node *node);
    00045   void ClearNodes(void);
    00046   void CreateChildren(Node *node);
    00047   void LinkChild(Node *, Node *);
    00048   void UpdateParent(Node *node);
    00049
    00050   // Stack functions.
    00051   void Push(Node *node);
    00052   Node *Pop(void);
    00053   Node *CheckList(Node *node, int number);
    00054   Node *GetBest(void);
    00055
    00056   inline int Coord2Id(int x, int y) { return x * m_rows + y; }
    00057 };
    00058
    00059 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines