Knight-Path 1.0.D018

/home/archives/knight-path/branch.1/branch.0/delta5682.018/knight-path/position.h

Go to the documentation of this file.
00001 //
00002 // knight-path - shortest knight path between two squares
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef KNIGHT_PATH_POSITION_H
00020 #define KNIGHT_PATH_POSITION_H
00021 
00022 #include <iostream>
00023 #include <vector>
00024 
00040 class position
00041 {
00042 public:
00043     typedef std::vector<position> list_t;
00044 
00051     ~position();
00052 
00060     position();
00061 
00075     position(char rank, char file);
00076 
00083     position(const position &rhs);
00084 
00091     position &operator=(const position &rhs);
00092 
00102     list_t knight_moves(void) const;
00103 
00119     static position read(std::istream &is);
00120 
00128     void write(std::ostream &os) const;
00129 
00138     bool operator==(const position &rhs) const;
00139 
00148     bool operator!=(const position &rhs) const;
00149 
00160     void plot(char board[8][8], char c) const;
00161 
00170     int distance(const position &elsewhere) const;
00171 
00172 private:
00184     position(int x, int y);
00185 
00194     unsigned p;
00195 
00200     bool valid(void) const;
00201 
00211     char get_rank(void) const;
00212 
00222     char get_file(void) const;
00223 
00224 public:
00225     // reluctantly made public, becaiuse solver_maze needs access
00226 
00233     int get_x(void) const;
00234 
00241     int get_y(void) const;
00242 };
00243 
00254 inline std::istream &
00255 operator>>(std::istream &is, position &p)
00256 {
00257     p = position::read(is);
00258     return is;
00259 }
00260 
00269 inline std::ostream &
00270 operator<<(std::ostream &os, const position &p)
00271 {
00272     p.write(os);
00273     return os;
00274 }
00275 
00276 #endif // KNIGHT_PATH_POSITION_H