Commit f12f3b26 authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

Basic pawn moves, sans en passant

parent d1aa2008
......@@ -863,6 +863,62 @@ string Moves::bishopMovesB(string boardPositions, int i) {
}
return list;
} // End black king moves.
string Moves::pawnMovesB(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;
int k = i - 16;
if (rowNum == 6) {
// The standard catch for moving two spaces forward.
if (theBoard[i-8] == '-' && theBoard[i-16] == '-') {
theseMoves.push_back(k);
}
}
// The standard catch for moving one space forward.
k = i - 8;
if (theBoard[k] == '-') {
theseMoves.push_back(k);
}
k = i - 9;// Attacking to the left and down.
if (colNum > 0 && isupper(theBoard[k])) {
theseMoves.push_back(k);
}
k = i - 7;// Attacking to the right and down.
if (colNum < 7 && isupper(theBoard[k])) {
theseMoves.push_back(k);
}
// End boring pawn moves.
// Need en passant moves //
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
if (isupper(theBoard[k]) || theBoard[k] == '-') {
moveSquare = theBoard[k];
theBoard[k] = 'p';
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] = 'p';
}
}
return list;
} // End black pawn moves.
//---------------------------------------------------------------------
......@@ -1382,6 +1438,62 @@ string Moves::bishopMoves(string boardPositions, int i) {
return list;
} // End white king moves.
string Moves::pawnMoves(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 k = i + 16;
cout << rowNum << endl;
if (rowNum == 1) {
// The standard catch for moving two spaces forward.
if (theBoard[i+8] == '-' && theBoard[i+16] == '-') {
theseMoves.push_back(k);
}
}
// The standard catch for moving one space forward.
k = i + 8;
if (theBoard[k] == '-') {
theseMoves.push_back(k);
}
k = i + 7;// Attacking to the left and up.
if (colNum > 0 && islower(theBoard[k])) {
theseMoves.push_back(k);
}
k = i + 9;// Attacking to the right and up.
if (colNum < 7 && islower(theBoard[k])) {
theseMoves.push_back(k);
}
// End boring pawn moves.
// Need en passant 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] = 'P';
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] = 'P';
}
}
return list;
} // End white pawn moves.
//====================================================================
string Moves::available(string boardPositions, bool whoseTurn) {
......@@ -1394,7 +1506,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'B': list+=bishopMoves(boardPositions, i);break;
case 'Q': list+=queenMoves(boardPositions, i);break;
case 'K': list+=kingMoves(boardPositions, i);break;
//case 'P': list+=pawnMoves(boardPositions, i);break;
case 'P': list+=pawnMoves(boardPositions, i);break;
}
}} else {
for (int i = 0; i < 64; i++) {
......@@ -1404,7 +1516,7 @@ string Moves::available(string boardPositions, bool whoseTurn) {
case 'b': list+=bishopMovesB(boardPositions, i);break;
case 'q': list+=queenMovesB(boardPositions, i);break;
case 'k': list+=kingMovesB(boardPositions, i);break;
//case 'p': list+=pawnMovesB(boardPositions, i);break;
case 'p': list+=pawnMovesB(boardPositions, i);break;
}
}}
//Debugging only //
......
......@@ -54,7 +54,10 @@ public:
string kingMovesB(string boardPositions, int i);
// white king moves:
string kingMoves(string boardPositions, int i);
// Black pawn moves:
string pawnMovesB(string boardPositions, int i);
// white pawn moves:
string pawnMoves(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