00001 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #include "Move.h"
00026 
00027 #include <cstdlib>
00028 
00029 #include "MoveIterator.h"
00030 
00031 Move::Move(Move * next) : _next(next) {
00032 
00033 }
00034 
00035 Move::~Move(){
00036    delete _next; 
00037 }
00038 
00039 unsigned int Move::size() {
00040   Move * ptr = _next;
00041   unsigned int n = 1;
00042   while(ptr){
00043     ptr = ptr->_next;
00044     n++;
00045   }
00046   return n;
00047 }
00048 
00049 MoveIterator Move::begin() {
00050   MoveIterator m(this);
00051   return m;
00052 }
00053 
00054 MoveIterator Move::end() {
00055   MoveIterator m(NULL);
00056   return m;
00057 }
00058 
00059 std::pair<int,int> Move::getAbsCoords(move_command cmd, int i, int j) const {
00060   std::pair<int,int> result;
00061 
00062   if(cmd == getHandledMovement()){
00063 
00064     std::pair<int,int> relatives;
00065     relatives = getHandledRelCoords();
00066     result.first = i + relatives.first;
00067     result.second = j + relatives.second;
00068 
00069   } else if(_next){
00070     result = _next->getAbsCoords(cmd, i, j);
00071   } else {
00072     throw "Illegal move !";
00073   }
00074   return result;
00075 }
00076 
00077 std::pair<int,int> Move::getAbsCoords(int i, int j) const {
00078   return getAbsCoords(getHandledMovement(), i, j);
00079 }
00080 
00081 move_command Move::opposite(move_command cmd) const {
00082   move_command res;
00083 
00084   
00085   if(cmd == getHandledMovement()){
00086     res = getHandledOpposite();
00087   } else if(_next){ 
00088     res = _next->opposite(cmd);
00089   } else {
00090     throw "Illegal move !";
00091   }
00092   return res;
00093 }