Commit ae1b45a7 authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

Fixed at 2 ply.

parent da70b185
......@@ -129,7 +129,7 @@ vector<string> sepVect = split(boardPositions, ' ');
if ((sepVect[k].at(0)-sepVect[k].at(2)) == 1){
m_theBoard[first+1] = '-';
}}
cout << "EN PASSANT" << endl;
//cout << "EN PASSANT" << endl;
}
if (m_theBoard[second] == 'P' && sepVect[k].at(1) == '5'){
if ((sepVect[k].at(3)-sepVect[k].at(1)) == 1){
......@@ -140,7 +140,7 @@ vector<string> sepVect = split(boardPositions, ' ');
if ((sepVect[k].at(0)-sepVect[k].at(2)) == 1){
m_theBoard[first-1] = '-';
}}
cout << "EN PASSANT" << endl;
//cout << "EN PASSANT" << endl;
}
}// End checking en passant.
......@@ -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
......
......@@ -1633,8 +1633,7 @@ string Moves::available(string boardPositions, bool whoseTurn, bool isPass, char
*/
}
string Moves::plyMove(string boardPositions, bool whoseTurn, bool isPass, char enPass, int plyMoves){
plyMoves--;
string Moves::nonPlyMove(string boardPositions, bool whoseTurn, bool isPass, char enPass){
string candidateList = Moves::available(boardPositions, whoseTurn, isPass, enPass);
string chosenMove = "";
int currentEval = 0;
......@@ -1658,8 +1657,7 @@ string Moves::plyMove(string boardPositions, bool whoseTurn, bool isPass, char e
boardPositions[second] = boardPositions[first];
boardPositions[first] = '-';
moveEval = evaluations.getEval(boardPositions);
cout <<"info depth " << plyMoves << " score cp "<< moveEval << " pv " << boardPositions << endl;
//cout << "Move eval: " << chosenMove << " eval " << moveEval << " places " << boardPositions << endl;
//cout <<"info depth " << "9" << " score cp "<< moveEval << " pv " << boardPositions << endl;
if (whoseTurn){
// White's turn, higher is better.
if ( moveEval > bestEval ) {
......@@ -1679,12 +1677,42 @@ string Moves::plyMove(string boardPositions, bool whoseTurn, bool isPass, char e
bestEval = moveEval;
}
}
boardPositions[first] = firstPieceHolder;
boardPositions[second] = secondPieceHolder;
} // End candidate list moves.
} else {
// candidate list is 0.... game over.
}
//cout << " second move " << chosenMove << endl;
return chosenMove;
}
string Moves::plyMove(string boardPositions, bool whoseTurn, bool isPass, char enPass, int plyMoves){
plyMoves--;
string candidateList = Moves::available(boardPositions, whoseTurn, isPass, enPass);
string chosenMove = "";
int currentEval = evaluations.getEval(boardPositions);
if (candidateList.size() > 0){
//int moveEval = 0;
int bestEval = currentEval;
if (whoseTurn){bestEval-=10000;} else {bestEval+=10000;}
//cout << "current eval " << bestEval << endl;
for (int a = 0; a < 4; a++) {
chosenMove += candidateList[(0)+a];
}
for (int e = 0; unsigned(e) < (candidateList.size()/5); e++){
string proposedMove = "";
for (int a = 0; a < 4; a++) {
proposedMove += candidateList[(5*e)+a];
}
int first =((proposedMove.at(0) - 'a' + 1) + (((proposedMove.at(1) - '1') * 8) - 1));
int second =((proposedMove.at(2) - 'a' + 1) + (((proposedMove.at(3) - '1') * 8) - 1));
char firstPieceHolder = boardPositions[first];
char secondPieceHolder = boardPositions[second];
boardPositions[second] = boardPositions[first];
boardPositions[first] = '-';
try {
if (plyMoves > 0){
whoseTurn = !whoseTurn;
string nextMove = plyMove(boardPositions, whoseTurn, isPass, enPass, plyMoves);
whoseTurn = !whoseTurn;
string nextMove = nonPlyMove(boardPositions, !whoseTurn, isPass, enPass);
int third =((nextMove.at(0) - 'a' + 1) + (((nextMove.at(1) - '1') * 8) - 1));
int fourth =((nextMove.at(2) - 'a' + 1) + (((nextMove.at(3) - '1') * 8) - 1));
char thirdPieceHolder = boardPositions[third];
......@@ -1692,29 +1720,56 @@ string Moves::plyMove(string boardPositions, bool whoseTurn, bool isPass, char e
boardPositions[fourth] = boardPositions[third];
boardPositions[third] = '-';
int newMoveEval = evaluations.getEval(boardPositions);
//cout << "info Move eval: " << chosenMove << " eval " << moveEval << " places " << boardPositions << endl;
cout <<"info depth " << plyMoves << " score cp "<< newMoveEval << " pv " << proposedMove << " comment " << boardPositions << endl;
if (whoseTurn){
// White's turn, higher is better.
if ( newMoveEval > bestEval ) {
chosenMove = proposedMove;
bestEval = newMoveEval;
} else if ( newMoveEval == bestEval && (int)time(0)%2 == 0) {
chosenMove = proposedMove;
bestEval = newMoveEval;
}
chosenMove = proposedMove; //cout << "chosen " << chosenMove << endl;
bestEval = newMoveEval;
} else if ( newMoveEval == bestEval && (int)time(0)%2 == 0) {
chosenMove = proposedMove; //cout << "chosen " << chosenMove << endl;
bestEval = newMoveEval;}
} else {
// Black's turn, lower is better.
if ( newMoveEval < bestEval ) {
chosenMove = proposedMove;
chosenMove = proposedMove; //cout << "chosen " << chosenMove << endl;
bestEval = newMoveEval;
} else if ( newMoveEval == bestEval && (int)time(0)%2 == 0) {
chosenMove = proposedMove; //cout << "chosen " << chosenMove << endl;
bestEval = newMoveEval;
} else if ( newMoveEval == bestEval && (int)time(0)%2 == 0) {
chosenMove = proposedMove;
bestEval = newMoveEval;
}
}
}
//if (plyMoves > 1 ) {
//string nextPlyMove = plyMove(boardPositions, whoseTurn, isPass, enPass, plyMoves-1);
//int fifth =((nextMove.at(0) - 'a' + 1) + (((nextMove.at(1) - '1') * 8) - 1));
//int sixth =((nextMove.at(2) - 'a' + 1) + (((nextMove.at(3) - '1') * 8) - 1));
//char fifthPieceHolder = boardPositions[fifth];
//char sixthPieceHolder = boardPositions[sixth];
//boardPositions[fourth] = boardPositions[fifth];
//boardPositions[fifth] = '-';
//int newPlyEval = evaluations.getEval(boardPositions);
//if (whoseTurn){
//// White's turn, higher is better.
//if ( newPlyEval > bestEval ) {
//bestEval = newPlyEval; cout << "evalChosen " << bestEval << endl;
//} else if ( newPlyEval == bestEval && (int)time(0)%2 == 0) {
//bestEval = newPlyEval; cout << "evalChosen " << bestEval << endl;
//}
//} else {
//// Black's turn, lower is better.
//if ( newPlyEval < bestEval ) {
//bestEval = newPlyEval; cout << "evalChosen " << bestEval << endl;
//} else if ( newPlyEval == bestEval && (int)time(0)%2 == 0) {
//bestEval = newPlyEval; cout << "evalChosen " << bestEval << endl;
//}
//}
//boardPositions[fifth] = fifthPieceHolder;
//boardPositions[sixth] = sixthPieceHolder;
//} // end more ply moves.
boardPositions[third] = thirdPieceHolder;
boardPositions[fourth] = fourthPieceHolder;
}
} catch (...) {
cout << " Exception " << endl;
} // End try/catch block
......
......@@ -34,6 +34,9 @@ public:
// Weighted move, considering ply.
string plyMove(string boardPositions, bool whoseTurn, bool isPass, char enPass, int plyMoves);
// Weighted move, non-ply.
string nonPlyMove(string boardPositions, bool whoseTurn, bool isPass, char enPass);
// Is the king safe?
bool isKingSafe(string boardPositions, bool whoseTurn);
......
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