Commit df3e306f authored by AlaskaLinuxUser's avatar AlaskaLinuxUser

picoEngine can choose to en passant

parent fe1f7404
......@@ -150,14 +150,14 @@ vector<string> sepVect = split(boardPositions, ' ');
if ((sepVect[k].at(1)-sepVect[k].at(3)) == 2){
m_enPassant = true;
m_enPasPawn = sepVect[k].at(2);
// cout << "EN PASSANT enabled " << m_enPasPawn << endl;
cout << "EN PASSANT enabled " << m_enPasPawn << endl;
}
}
if (m_theBoard[second] == 'P'){
if ((sepVect[k].at(3)-sepVect[k].at(1)) == 2){
m_enPassant = true;
m_enPasPawn = sepVect[k].at(2);
// cout << "EN PASSANT enabled " << m_enPasPawn << endl;
cout << "EN PASSANT enabled " << m_enPasPawn << endl;
}
}
// End EN PASSANT enabled
......@@ -238,3 +238,15 @@ bool Board::getTurn() {
return m_whitesTurn;
}
bool Board::getIsPassent() {
return m_enPassant;
}
char Board::getEnPassent() {
return m_enPasPawn;
}
......@@ -33,6 +33,10 @@ public:
string moveBoard();
bool getTurn();
bool getIsPassent();
char getEnPassent();
};
......
......@@ -73,7 +73,7 @@ void inputGo()
{
cout << "Going...." << endl;
engineMove = "";
engineMove = movePick.bestMove(board.moveBoard(), board.getTurn(), styleRandom);
engineMove = movePick.bestMove(board.moveBoard(), board.getTurn(), styleRandom, board.getIsPassent(), board.getEnPassent());
cout << "bestmove " + engineMove << endl;
}
void inputQuit()
......
......@@ -897,7 +897,7 @@ string Moves::bishopMovesB(string boardPositions, int i) {
return list;
} // End black king moves.
string Moves::pawnMovesB(string boardPositions, int i) {
string Moves::pawnMovesB(string boardPositions, int i, bool isPass, char enPass) {
string list = "";
vector <int> theseMoves;
string moveSquare;
......@@ -928,8 +928,25 @@ string Moves::bishopMovesB(string boardPositions, int i) {
theseMoves.push_back(k);
}
// End boring pawn moves.
// Need en passant moves //
if (isPass){
if (i > 23 && i < 32) {
int passedPawn = 8;
if (enPass == 'a'){ passedPawn = 0; }
else if (enPass == 'b'){ passedPawn = 1; }
else if (enPass == 'c'){ passedPawn = 2; }
else if (enPass == 'd'){ passedPawn = 3; }
else if (enPass == 'e'){ passedPawn = 4; }
else if (enPass == 'f'){ passedPawn = 5; }
else if (enPass == 'g'){ passedPawn = 6; }
else if (enPass == 'h'){ passedPawn = 7; }
if (passedPawn - colNum == 1) {
theseMoves.push_back(i-7);
}
if (colNum - passedPawn == 1) {
theseMoves.push_back(i-9);
}
}}// End en passant moves
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
......@@ -1504,7 +1521,7 @@ string Moves::bishopMoves(string boardPositions, int i) {
return list;
} // End white king moves.
string Moves::pawnMoves(string boardPositions, int i) {
string Moves::pawnMoves(string boardPositions, int i, bool isPass, char enPass) {
string list = "";
vector <int> theseMoves;
string moveSquare;
......@@ -1534,8 +1551,26 @@ string Moves::bishopMoves(string boardPositions, int i) {
theseMoves.push_back(k);
}
// End boring pawn moves.
// Need en passant moves //
//if (m_enPassant){cout << "en passant flagged" << endl;
if (isPass){
if (i > 31 && i < 40) {
int passedPawn = 8;
if (enPass == 'a'){ passedPawn = 0; }
else if (enPass == 'b'){ passedPawn = 1; }
else if (enPass == 'c'){ passedPawn = 2; }
else if (enPass == 'd'){ passedPawn = 3; }
else if (enPass == 'e'){ passedPawn = 4; }
else if (enPass == 'f'){ passedPawn = 5; }
else if (enPass == 'g'){ passedPawn = 6; }
else if (enPass == 'h'){ passedPawn = 7; }
if (passedPawn - colNum == 1) {
theseMoves.push_back(i+9);
}
if (colNum - passedPawn == 1) {
theseMoves.push_back(i+7);
}
}}// End en passant moves
for(int l=0; (unsigned)l<theseMoves.size();l++) {
int k = theseMoves[l];
......@@ -1561,7 +1596,7 @@ string Moves::bishopMoves(string boardPositions, int i) {
//====================================================================
string Moves::available(string boardPositions, bool whoseTurn) {
string Moves::available(string boardPositions, bool whoseTurn, bool isPass, char enPass) {
string list = "";
if (whoseTurn){
for (int i = 0; i < 64; i++) {
......@@ -1571,7 +1606,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, isPass, enPass);break;
}
}} else {
for (int i = 0; i < 64; i++) {
......@@ -1581,7 +1616,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, isPass, enPass);break;
}
}}
//Debugging only //
......@@ -1595,8 +1630,8 @@ string Moves::available(string boardPositions, bool whoseTurn) {
*/
}
string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom){
string candidateList = Moves::available(boardPositions, whoseTurn);
string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom, bool isPass, char enPass){
string candidateList = Moves::available(boardPositions, whoseTurn, isPass, enPass);
string chosenMove = "";
if (candidateList.size() > 0){
//if (styleRandom) {
......
......@@ -26,10 +26,10 @@ private:
public:
// All available moves.
string available(string boardPositions, bool whoseTurn);
string available(string boardPositions, bool whoseTurn, bool isPass, char enPass);
// Best move.
string bestMove(string boardPositions, bool whoseTurn, bool styleRandom);
string bestMove(string boardPositions, bool whoseTurn, bool styleRandom, bool isPass, char enPass);
// Is the king safe?
bool isKingSafe(string boardPositions, bool whoseTurn);
......@@ -55,9 +55,9 @@ public:
// white king moves:
string kingMoves(string boardPositions, int i);
// Black pawn moves:
string pawnMovesB(string boardPositions, int i);
string pawnMovesB(string boardPositions, int i, bool isPass, char enPass);
// white pawn moves:
string pawnMoves(string boardPositions, int i);
string pawnMoves(string boardPositions, int i, bool isPass, char enPass);
};
No preview for this file type
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