Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

FinderAlg Class Reference

Collaboration diagram for FinderAlg:

Collaboration graph
[legend]

Detailed Description

Algorithm to find shortest path.

Definition at line 16 of file FinderAlg.h.

Public Member Functions

 FinderAlg (int w, int h)
Dir::eDir findDir (const Unit *unit, const V2 &dest)
 Finds the best start direction to the destination.


Constructor & Destructor Documentation

FinderAlg::FinderAlg int  w,
int  h
 

Definition at line 16 of file FinderAlg.cpp.

00017     : m_closed(w, h)
00018 {
00019     m_unit = NULL;
00020 }


Member Function Documentation

Dir::eDir FinderAlg::findDir const Unit unit,
const V2 dest
 

Finds the best start direction to the destination.

Parameters:
unit unit which finds path
dest destination, final destination must be under unit
Returns:
direction or DIR_NO

Definition at line 29 of file FinderAlg.cpp.

00030 {
00031     if (m_unit) {
00032         m_closed.reset();
00033         m_fifo.clear();
00034     }
00035     m_unit = unit;
00036     V2 uLoc = unit->getLoc();
00037     int w = unit->getW();
00038     int h = unit->getH();
00039     if (isInRect(uLoc, w, h, dest)) {
00040         return Dir::DIR_NO;
00041     }
00042     //TODO: don't compute when dest is on the wall
00043 
00044     m_closed.markClosed(uLoc);
00045     m_fifo.push_back(FinderPlace(Dir::DIR_LEFT, uLoc.plus(V2(-1, 0))));
00046     m_fifo.push_back(FinderPlace(Dir::DIR_RIGHT, uLoc.plus(V2(+1, 0))));
00047     m_fifo.push_back(FinderPlace(Dir::DIR_UP, uLoc.plus(V2(0, -1))));
00048     m_fifo.push_back(FinderPlace(Dir::DIR_DOWN, uLoc.plus(V2(0, +1))));
00049 
00050     while (!m_fifo.empty()) {
00051         FinderPlace place = m_fifo.front();
00052         m_fifo.pop_front();
00053         if (tryPlace(place)) {
00054             if (isInRect(place.getLoc(), w, h, dest)) {
00055                 return place.getStartDir();
00056             }
00057 
00058             pushNext(place, V2(-1, 0));
00059             pushNext(place, V2(+1, 0));
00060             pushNext(place, V2(0, -1));
00061             pushNext(place, V2(0, +1));
00062         }
00063     }
00064     return Dir::DIR_NO;
00065 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:05 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2