Commit 77bdc11d authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

Added ability to move through UCI!

parent 40e396d8
......@@ -123,3 +123,17 @@ string Board::getBoard()
printBoard += " " + m_turnCount;
return printBoard;
}
string Board::moveBoard() {
string printBoard = "";
for (int i = 0; i < 64; i++){
printBoard = printBoard + m_theBoard[i];
}
return printBoard;
}
bool Board::getTurn() {
return m_whitesTurn;
}
......@@ -29,6 +29,10 @@ public:
void setup(string boardPositions);
string getBoard();
string moveBoard();
bool getTurn();
};
......
......@@ -18,6 +18,7 @@
#include <string>
#include <sstream>
#include "Board.h"
#include "Moves.h"
using namespace std;
string engineName = "picoEngine A01";
......@@ -25,6 +26,8 @@ string inputString = "";
bool runProgram = true;
bool styleRandom = false;
Board board;
Moves movePick;
string engineMove = "";
void inputUCI()
......@@ -69,6 +72,9 @@ void inputUCINewGame()
void inputGo()
{
cout << "Going...." << endl;
engineMove = "";
engineMove = movePick.bestMove(board.moveBoard(), board.getTurn(), styleRandom);
cout << "bestmove " + engineMove << endl;
}
void inputQuit()
{
......
File added
......@@ -397,17 +397,19 @@ string Moves::nightMovesB(string boardPositions, int i) {
theBoard[k] = 'n';
theBoard[i] = '-';
if (isKingSafe(theBoard, turn)) {
char F = (char)('a' + colNum) + (char)(rowNum);
char F = (char)('a' + colNum);
char G = (char)('1' + rowNum);
int rowNumK = k/8;
int colNumK = k%8;
char T = (char)('a' + colNumK) + (char)(rowNumK);
list = list + F + T + ",";
char T = (char)('a' + colNumK);
char U = (char)('1' + rowNumK);
list = list + F + G + T + U + ",";
}
theBoard[k] = moveSquare[0];
theBoard[i] = 'n';
}
}
cout << list << endl;
return list;
} // End black knight moves.
......@@ -461,22 +463,24 @@ string Moves::nightMoves(string boardPositions, int i) {
theBoard[k] = 'N';
theBoard[i] = '-';
if (isKingSafe(theBoard, turn)) {
char F = (char)('a' + colNum) + (char)(rowNum);
char F = (char)('a' + colNum);
char G = (char)('1' + rowNum);
int rowNumK = k/8;
int colNumK = k%8;
char T = (char)('a' + colNumK) + (char)(rowNumK);
list = list + F + T + ",";
char T = (char)('a' + colNumK);
char U = (char)('1' + rowNumK);
list = list + F + G + T + U + ",";
}
theBoard[k] = moveSquare[0];
theBoard[i] = 'N';
}
}
cout << list << endl;
return list;
} // End white knight moves.
string Moves::available(string boardPositions, bool whoseTurn) {
string list = "";
string list = "";
if (whoseTurn){
for (int i = 0; i < 64; i++) {
switch (boardPositions[i]) {
......@@ -498,7 +502,8 @@ string list = "";
//case 'p': list+=pawnMovesB(i);break;
}
}}
//Debugging only // Log.i("WJH", list);
//Debugging only //
cout << list << endl;
return list;
/*
* The list is in this format 1234,
......@@ -507,3 +512,20 @@ string list = "";
* followed by a comma.
*/
}
string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom){
string candidateList = Moves::available(boardPositions, whoseTurn);
string chosenMove = "";
if (candidateList.size() > 0){
//if (styleRandom) {
srand((int)time(0) + candidateList.size());
int r = (rand() % (candidateList.size()/5));
for (int a = 0; a < 4; a++) {
chosenMove += candidateList[(5*r)+a];
}
//} else {
//}
}
return chosenMove;
}
......@@ -28,6 +28,9 @@ public:
// All available moves.
string available(string boardPositions, bool whoseTurn);
// Best move.
string bestMove(string boardPositions, bool whoseTurn, bool styleRandom);
// Is the king safe?
bool isKingSafe(string boardPositions, bool whoseTurn);
......
File added
File added
No preview for this file type
File deleted
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