/// GH working  on  knights  tour  20151015
#include  "..\std_lib_facilities.h"
int bWidth{8}, bLength{8};

///prototypes
void displayBoard(vector <int>);

/// let user choose a legal move and update
void getMove(vector<int>& brd,
             int& move,
             int& currPos,
             bool& stuck);

///initialize the board and set first position
void start(vector <int >, int &);

int main() {
    vector<int> board(bWidth*bLength);
    bool stuck = false;
    int move{1};
    int currPos{0};
    start(board , currPos);
    ///game loop
    while(!stuck) {
        displayBoard(board);
        getMove(board , currPos , move , stuck);
    }
    return 0;
}

///initialize the board and set first position
void start(vector<int> brd, int& cp) {
    int row , col;
    cout  << "\nWhat row and column position do you want to start ?";
    cin  >> row  >> col;
    cout << "\n THat's at " << row*bWidth+col << endl;
    brd[row*bWidth+col] = 1;
    cp = row*bWidth+col;
}

void displayBoard(vector <int> board)  {
    for(int i = 0; i < board.size(); ++i) {
        cout << board[i];
        if((i+1)%bWidth == 0)cout << endl;
    }
}

void getMove(vector<int>& brd,
             int& currPos,
             int& move,
             bool& stuck) {
    int row , col;
    cout  << "\nChange in rows and columns (-2,1) for up two-right 1):";
    do {
        cin  >> row  >> col;
        if(abs(row*col) != 2
           || currPos + 8*row + col<0
           || currPos + 8*row + col>63)
            cout << "\nThat's not legal move.  Try again: \n";
    } while(abs(row*col) != 2
            || currPos + 8*row + col<0
            || currPos + 8*row + col>63);
    ///check that this is a legal move
    currPos = currPos + 8*row + col;
    ++move;
    brd[currPos]=move;
}
