Knight-Path 1.0.D018
|
#include <taxi.h>
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_taxi & | operator= (const solver_taxi &rhs) |
Private Attributes | |
list_t | shortest_solution |
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.
solver_taxi::solver_taxi | ( | ) | [private] |
solver_taxi::solver_taxi | ( | const solver_taxi & | rhs | ) | [private] |
The copy constructor. It is private on purpose, use a create class method instead.
rhs | The right hand side of the initialization. |
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.
solver_taxi& solver_taxi::operator= | ( | const solver_taxi & | rhs | ) | [private] |
The assignment operator.
rhs | The 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.
from | The position to start from |
to | The position to finish at. |
progress | The cumulative path so far, from earlier ply()s. |
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.
from | The position at the start of the path. |
to | The position at the end of the path. |
Implements solver.
list_t solver_taxi::shortest_solution [private] |