Commit 8b7fe75e authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

Added Queen moves.

parent 6a3ab38a
......@@ -626,6 +626,186 @@ string Moves::bishopMovesB(string boardPositions, int i) {
}
return list;
} // End Bishop moves.
string Moves::queenMovesB(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;
int g = i%8;
// Up moves
bool notI = true;
int j = 1;
int vert = 8;
int k = i;
if (i < 56) {
k = i + (vert * j);
}
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
vert += 8;
if (k < 56) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
// Down moves
notI = true;
j = -1;
vert = 8;
k = i;
if (i > 7) {
k = i + (vert * j);
}
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
vert += 8;
if (k >7) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
// Right side....
notI = true;
int rj = 1;
int rk = i;
if (g < 7) {
rk = i + rj;
}
while (theBoard[rk] == '-' && notI) {
theseMoves.push_back(rk);
rj++;
if (rk%8 < 7) {
rk = i + rj;
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[rk])) {
theseMoves.push_back(rk);
} // When there is an enemy.
// Left side....
notI=true;
rj = 1;
rk = i;
if (g > 0) {
rk = i - rj;
}
while (theBoard[rk] == '-' && notI) {
theseMoves.push_back(rk);
rj++;
if (rk%8 > 0) {
rk = i - rj;
} else {
notI=false;
}
} // While it's empty.
if (isupper(theBoard[rk])) {
theseMoves.push_back(rk);
} // When there is an enemy.
if (rowNum < 7) {
// Up diagonal moves.
if (colNum < 7) {
k = i + 9;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k/8 < 7 && k%8 < 7) {
k = k + 9;
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
notI = true;
if (colNum > 0) {
k = i + 7;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 > 0 && k/8 < 7) {
k = k + 7;
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
}
if (rowNum > 0) {
// down diagonal moves.
notI = true;
if (colNum > 0) {
k = i - 9;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 > 0 && k/8 > 0) {
k = k - 9;
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
notI = true;
if (colNum < 7) {
k = i - 7;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 < 7 && k/8 > 0) {
k = k - 7;
} else {
notI = false;
}
} // While it's empty.
if (isupper(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
}
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
if (isupper(theBoard[k]) || theBoard[k] == '-') {
moveSquare = theBoard[k];
theBoard[k] = 'q';
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] = 'q';
}
}
return list;
} // End black queen moves.
//---------------------------------------------------------------------
......@@ -908,6 +1088,186 @@ string Moves::bishopMoves(string boardPositions, int i) {
return list;
} // End Bishop moves.
string Moves::queenMoves(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;
int g = i%8;
// Up moves
bool notI = true;
int j = 1;
int vert = 8;
int k = i;
if (i < 56) {
k = i + (vert * j);
}
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
vert += 8;
if (k < 56) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
// Down moves
notI = true;
j = -1;
vert = 8;
k = i;
if (i > 7) {
k = i + (vert * j);
}
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
vert += 8;
if (k >7) {
k = i + (vert * j);
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
// Right side....
notI = true;
int rj = 1;
int rk = i;
if (g < 7) {
rk = i + rj;
}
while (theBoard[rk] == '-' && notI) {
theseMoves.push_back(rk);
rj++;
if (rk%8 < 7) {
rk = i + rj;
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[rk])) {
theseMoves.push_back(rk);
} // When there is an enemy.
// Left side....
notI=true;
rj = 1;
rk = i;
if (g > 0) {
rk = i - rj;
}
while (theBoard[rk] == '-' && notI) {
theseMoves.push_back(rk);
rj++;
if (rk%8 > 0) {
rk = i - rj;
} else {
notI=false;
}
} // While it's empty.
if (islower(theBoard[rk])) {
theseMoves.push_back(rk);
} // When there is an enemy.
if (rowNum < 7) {
// Up diagonal moves.
if (colNum < 7) {
k = i + 9;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k/8 < 7 && k%8 < 7) {
k = k + 9;
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
notI = true;
if (colNum > 0) {
k = i + 7;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 > 0 && k/8 < 7) {
k = k + 7;
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
}
if (rowNum > 0) {
// down diagonal moves.
notI = true;
if (colNum > 0) {
k = i - 9;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 > 0 && k/8 > 0) {
k = k - 9;
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
notI = true;
if (colNum < 7) {
k = i - 7;
while (theBoard[k] == '-' && notI) {
theseMoves.push_back(k);
if (k%8 < 7 && k/8 > 0) {
k = k - 7;
} else {
notI = false;
}
} // While it's empty.
if (islower(theBoard[k])) {
theseMoves.push_back(k);
} // When there is an enemy.
}
}
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
if (islower(theBoard[k]) || theBoard[k] == '-') {
moveSquare = theBoard[k];
theBoard[k] = 'Q';
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] = 'Q';
}
}
return list;
} // End white queen moves.
//====================================================================
string Moves::available(string boardPositions, bool whoseTurn) {
......@@ -918,7 +1278,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'N': list+=nightMoves(boardPositions, i);break;
case 'R': list+=rookMoves(boardPositions, i);break;
case 'B': list+=bishopMoves(boardPositions, i);break;
//case 'Q': list+=queenMoves(boardPositions, i);break;
case 'Q': list+=queenMoves(boardPositions, i);break;
//case 'K': list+=kingMoves(boardPositions, i);break;
//case 'P': list+=pawnMoves(boardPositions, i);break;
}
......@@ -928,7 +1288,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'n': list+=nightMovesB(boardPositions, i);break;
case 'r': list+=rookMovesB(boardPositions, i);break;
case 'b': list+=bishopMovesB(boardPositions, i);break;
//case 'q': list+=queenMovesB(boardPositions, i);break;
case 'q': list+=queenMovesB(boardPositions, i);break;
//case 'k': list+=kingMovesB(boardPositions, i);break;
//case 'p': list+=pawnMovesB(boardPositions, i);break;
}
......
......@@ -46,6 +46,10 @@ public:
string bishopMovesB(string boardPositions, int i);
// white bishop moves:
string bishopMoves(string boardPositions, int i);
// Black queen moves:
string queenMovesB(string boardPositions, int i);
// white queen moves:
string queenMoves(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
Supports Markdown
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