hex::move::_Route Class Reference

#include <hexmove.h>

List of all members.


Detailed Description

A partial solution to the A* algorithm.

Only used in the internal workings of the routing algorithms. You won't need this class unless you are writing your own routing algorithms.

Definition at line 109 of file hexmove.h.

Public Member Functions

_Route step (hex::Hex *next, Cost cost, hex::Hex *goal=NULL) const
 Return a new _Route based upon this one.
hex::Distance distance (hex::Hex *goal) const
 Distance between the end of this route and the goal, if any.
bool operator< (const _Route &right) const
 Routes sort by value.

Static Public Member Functions

static _Route factory (hex::Hex *start, hex::Hex *goal=NULL)
 Generate an entirely new route, just one hex long.

Public Attributes

std::list< Hex * > path
 from start to current hex
Cost cost
 sum of weights of hexes in path. (g() in A*)


Member Function Documentation

_Route hex::move::_Route::factory ( hex::Hex start,
hex::Hex goal = NULL 
) [static]

Generate an entirely new route, just one hex long.

Definition at line 235 of file move.cc.

References _value, cost, distance(), and path.

Referenced by hex::move::Topography::best_path(), and hex::move::Topography::horizon().

00236 {
00237   _Route result;
00238   result.path.push_back(start);
00239   result.cost  = 0; // g()
00240   result._value = result.distance(goal); // f()
00241   return result;
00242 }

_Route hex::move::_Route::step ( hex::Hex next,
Cost  cost,
hex::Hex goal = NULL 
) const

Return a new _Route based upon this one.

Definition at line 246 of file move.cc.

References _value, cost, distance(), and path.

00247 {
00248   _Route result;
00249   result.path  = path;
00250   result.path.push_back(next);
00251   result.cost  = this->cost + cost; // g()
00252   result._value = result.cost + result.distance(goal); // f()
00253   return result;
00254 }

hex::Distance hex::move::_Route::distance ( hex::Hex goal  )  const

Distance between the end of this route and the goal, if any.

Used for the h() heuristic function in A* algorithm.

Definition at line 258 of file move.cc.

References hex::Hex::centre(), path, hex::Point::x, and hex::Point::y.

Referenced by factory(), and step().

00259 {
00260   if(goal)
00261   {
00262     hex::Point vector = goal->centre() - path.back()->centre();
00263     return sqrt( vector.x * vector.x  +  vector.y * vector.y );
00264   }
00265   return 0;
00266 }

bool hex::move::_Route::operator< ( const _Route right  )  const [inline]

Routes sort by value.

Definition at line 128 of file hexmove.h.

References _value.

00128 { return _value < right._value; }


Member Data Documentation

std::list<Hex*> hex::move::_Route::path

from start to current hex

Definition at line 114 of file hexmove.h.

Referenced by distance(), factory(), and step().

Cost hex::move::_Route::cost

sum of weights of hexes in path. (g() in A*)

Definition at line 115 of file hexmove.h.

Referenced by factory(), and step().


The documentation for this class was generated from the following files:
Generated on Thu Feb 21 00:00:55 2008 for libhex by  doxygen 1.5.1