rendered paste body#ifndef KNIGHT_H
#define KNIGHT_H
#include <iostream>
struct KnightBase {
unsigned short accessibility[8][8];
};
KnightBase knightBase = { { { 2, 3, 4, 4, 4, 4, 3, 2 }, { 3, 4, 6, 6, 6, 6, 4, 3 },
{ 4, 6, 8, 8, 8, 8, 6, 4 }, { 4, 6, 8, 8, 8, 8, 6, 4 }, { 4, 6, 8, 8, 8, 8, 6, 4 },
{ 4, 6, 8, 8, 8, 8, 6, 4 }, { 3, 4, 6, 6, 6, 6, 4, 3 }, { 2, 3, 4, 4, 4, 4, 3, 2 } } };
class Knight {
public:
Knight( int theRow = 0, int theColumn = 0)
: moveCounter(0), currentRow(theRow), currentColumn(theColumn) {
this->accessibility[8][8] = knightBase.accessibility[8][8];
}
void moveTo(int row, int column) {
this->currentRow = row;
this->currentColumn = column;
this->accessibility[row][column] = 0;
std::cout << row << ":" << column << "\n";
}
void move() {
unsigned short leastAccessible = 8;
unsigned short newRow, newColumn;
for ( unsigned short moveNumber = 0; moveNumber < 8; ++moveNumber ) {
/* Make sure the */
if ( this->currentRow + this->vertical[moveNumber] >= 0 &&
this->currentRow + this->vertical[moveNumber] < 8 &&
this->currentColumn + this->horizontal[moveNumber] >= 0 &&
this->currentColumn + this->horizontal[moveNumber] < 8 ) {
newRow = this->currentRow + this->vertical[moveNumber];
newColumn = this->currentColumn + this->horizontal[moveNumber];
std::cout << newRow << ":" << newColumn << "\n";
}
if ( this->accessibility[newRow][newColumn] < leastAccessible ) {
std::cout << "z";
}
std::cout << newRow << "x" << newColumn;
this->moveTo(newRow, newColumn);
}
// find room in the accessibility table
}
void printAccessibility() const {
for ( unsigned short i = 0; i < 8; ++i ) {
for ( unsigned short j = 0; j < 8; ++j ) {
std::cout << this->accessibility[i][j] << " ";
}
std::cout << "\n";
}
}
private:
const static short horizontal[8];
const static short vertical[8];
// const static unsigned short Accessibility
unsigned short moveCounter;
unsigned short accessibility[8][8];
unsigned short currentRow;
unsigned short currentColumn;
};
const short Knight::horizontal[] = {2, 1, -1, -2, -2, -1, 1, 2};
const short Knight::vertical[] = {-1, -2, -2, -1, 1, 2, 2, 1};
#endif