Knight-Path 1.0.D018
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

solver_taxi Class Reference

#include <taxi.h>

Inheritance diagram for solver_taxi:
solver

List of all members.

Public Member Functions

virtual ~solver_taxi ()
list_t solve (const position &from, const position &to)

Static Public Member Functions

static pointer create (void)

Private Member Functions

 solver_taxi ()
void ply (const position &from, const position &to, const list_t &progress)
 solver_taxi (const solver_taxi &rhs)
solver_taxioperator= (const solver_taxi &rhs)

Private Attributes

list_t shortest_solution

Detailed Description

The solver_taxi class is used to represent the processing required to solve the knight path problem, by sorting a superficially brute force search by the distance from the goal. Recursion depth is limited by the shortest solution to date, thus eliminating non-productive search directions.

This algorithm performs in about 80% of the brute force time.

Definition at line 33 of file taxi.h.


Constructor & Destructor Documentation

solver_taxi::~solver_taxi ( ) [virtual]

The destructor.

Definition at line 23 of file taxi.cc.

solver_taxi::solver_taxi ( ) [private]

The default constructor. It is private on purpose, use a create class method instead.

Definition at line 28 of file taxi.cc.

solver_taxi::solver_taxi ( const solver_taxi rhs) [private]

The copy constructor. It is private on purpose, use a create class method instead.

Parameters:
rhsThe right hand side of the initialization.

Member Function Documentation

solver_taxi::pointer solver_taxi::create ( void  ) [static]

The create class method is used to create new dynamically allocated instance of the solver_taxi class.

Definition at line 34 of file taxi.cc.

solver_taxi& solver_taxi::operator= ( const solver_taxi rhs) [private]

The assignment operator.

Parameters:
rhsThe right hand side of the assignment.
void solver_taxi::ply ( const position from,
const position to,
const list_t progress 
) [private]

The ply method is used to perform one ply of recursive analysis. The shortest path found is store into the shortest_solution instance variable.

Parameters:
fromThe position to start from
toThe position to finish at.
progressThe cumulative path so far, from earlier ply()s.

Definition at line 62 of file taxi.cc.

solver::list_t solver_taxi::solve ( const position from,
const position to 
) [virtual]

The solve method is used to calculate the shortest path a knight piece must take between two given positions on a chess board. There are often several equally short paths, the first one found will be returned.

Parameters:
fromThe position at the start of the path.
toThe position at the end of the path.
Returns:
On success, a list of board positions will be returned; it will be a list of squares through which the Knight passes, the list will include the ending position, but will exclude the starting position (unless from == to). On error, (i.e. when no path is possible) an empty list will be returned.
Note:
Behaviour is undefined if either position is not valid.

Implements solver.

Definition at line 41 of file taxi.cc.


Member Data Documentation

The shortest_solution instance variable is used to remember the shortest path found between the two points given to the solve method. It is set by the ply method when it finds a new solution.

Definition at line 65 of file taxi.h.


The documentation for this class was generated from the following files: