Commit d1aa2008 authored by AlaskaLinuxUser's avatar AlaskaLinuxUser

King moves, no castling.

parent 8b7fe75e
......@@ -632,7 +632,7 @@ string Moves::bishopMovesB(string boardPositions, int i) {
vector <int> theseMoves;
string moveSquare;
string theBoard = boardPositions;
bool turn = true;
bool turn = false;
int rowNum = i/8;
int colNum = i%8;
int g = i%8;
......@@ -806,6 +806,63 @@ string Moves::bishopMovesB(string boardPositions, int i) {
}
return list;
} // End black queen moves.
string Moves::kingMovesB(string boardPositions, int i) {
string list = "";
vector <int> theseMoves;
string moveSquare;
string theBoard = boardPositions;
bool turn = false;
int rowNum = i/8;
int colNum = i%8;
if (rowNum > 0) {
if (theBoard[i-8] == '-' || isupper(theBoard[i-8])) {
theseMoves.push_back(i-8);}
if (colNum > 0) {
if (theBoard[i-9] == '-' || isupper(theBoard[i-9])) {
theseMoves.push_back(i-9);}}
if (colNum < 7) {
if (theBoard[i-7] == '-' || isupper(theBoard[i-7])) {
theseMoves.push_back(i-7);}}}
if (rowNum < 7) {
if (theBoard[i+8] == '-' || isupper(theBoard[i+8])) {
theseMoves.push_back(i+8);}
if (colNum < 7) {
if (theBoard[i+9] == '-' || isupper(theBoard[i+9])) {
theseMoves.push_back(i+9);}}
if (colNum > 0) {
if (theBoard[i+7] == '-' || isupper(theBoard[i+7])) {
theseMoves.push_back(i+7);}}}
if (colNum < 7) {
if (theBoard[i+1] == '-' || isupper(theBoard[i+1])) {
theseMoves.push_back(i+1);}}
if (colNum > 0) {
if (theBoard[i-1] == '-' || isupper(theBoard[i-1])) {
theseMoves.push_back(i-1);}}
// Need castle moves //
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
if (islower(theBoard[k]) || theBoard[k] == '-') {
moveSquare = theBoard[k];
theBoard[k] = 'k';
theBoard[i] = '-';
if (isKingSafe(theBoard, turn)) {
char F = (char)('a' + colNum);
char G = (char)('1' + rowNum);
int rowNumK = k/8;
int colNumK = k%8;
char T = (char)('a' + colNumK);
char U = (char)('1' + rowNumK);
list = list + F + G + T + U + ",";
}
theBoard[k] = moveSquare[0];
theBoard[i] = 'k';
}
}
return list;
} // End black king moves.
//---------------------------------------------------------------------
......@@ -1268,6 +1325,63 @@ string Moves::bishopMoves(string boardPositions, int i) {
return list;
} // End white queen moves.
string Moves::kingMoves(string boardPositions, int i) {
string list = "";
vector <int> theseMoves;
string moveSquare;
string theBoard = boardPositions;
bool turn = true;
int rowNum = i/8;
int colNum = i%8;
if (rowNum > 0) {
if (theBoard[i-8] == '-' || islower(theBoard[i-8])) {
theseMoves.push_back(i-8);}
if (colNum > 0) {
if (theBoard[i-9] == '-' || islower(theBoard[i-9])) {
theseMoves.push_back(i-9);}}
if (colNum < 7) {
if (theBoard[i-7] == '-' || islower(theBoard[i-7])) {
theseMoves.push_back(i-7);}}}
if (rowNum < 7) {
if (theBoard[i+8] == '-' || islower(theBoard[i+8])) {
theseMoves.push_back(i+8);}
if (colNum < 7) {
if (theBoard[i+9] == '-' || islower(theBoard[i+9])) {
theseMoves.push_back(i+9);}}
if (colNum > 0) {
if (theBoard[i+7] == '-' || islower(theBoard[i+7])) {
theseMoves.push_back(i+7);}}}
if (colNum < 7) {
if (theBoard[i+1] == '-' || islower(theBoard[i+1])) {
theseMoves.push_back(i+1);}}
if (colNum > 0) {
if (theBoard[i-1] == '-' || islower(theBoard[i-1])) {
theseMoves.push_back(i-1);}}
// Need castle moves //
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
if (islower(theBoard[k]) || theBoard[k] == '-') {
moveSquare = theBoard[k];
theBoard[k] = 'K';
theBoard[i] = '-';
if (isKingSafe(theBoard, turn)) {
char F = (char)('a' + colNum);
char G = (char)('1' + rowNum);
int rowNumK = k/8;
int colNumK = k%8;
char T = (char)('a' + colNumK);
char U = (char)('1' + rowNumK);
list = list + F + G + T + U + ",";
}
theBoard[k] = moveSquare[0];
theBoard[i] = 'K';
}
}
return list;
} // End white king moves.
//====================================================================
string Moves::available(string boardPositions, bool whoseTurn) {
......@@ -1279,7 +1393,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'R': list+=rookMoves(boardPositions, i);break;
case 'B': list+=bishopMoves(boardPositions, i);break;
case 'Q': list+=queenMoves(boardPositions, i);break;
//case 'K': list+=kingMoves(boardPositions, i);break;
case 'K': list+=kingMoves(boardPositions, i);break;
//case 'P': list+=pawnMoves(boardPositions, i);break;
}
}} else {
......@@ -1289,7 +1403,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'r': list+=rookMovesB(boardPositions, i);break;
case 'b': list+=bishopMovesB(boardPositions, i);break;
case 'q': list+=queenMovesB(boardPositions, i);break;
//case 'k': list+=kingMovesB(boardPositions, i);break;
case 'k': list+=kingMovesB(boardPositions, i);break;
//case 'p': list+=pawnMovesB(boardPositions, i);break;
}
}}
......
......@@ -50,6 +50,10 @@ public:
string queenMovesB(string boardPositions, int i);
// white queen moves:
string queenMoves(string boardPositions, int i);
// Black king moves:
string kingMovesB(string boardPositions, int i);
// white king moves:
string kingMoves(string boardPositions, int i);
};
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment