Skip to content

Commit

Permalink
Start on UCI-communication
Browse files Browse the repository at this point in the history
  • Loading branch information
bsamseth committed Dec 28, 2015
1 parent 853b038 commit bda108f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ add_executable(tester app/testing.cpp ${SOURCES})

add_dependencies(tester engine)

add_executable(goldfish app/goldfish.cpp ${SOURCES})

add_dependencies(goldfish engine)

add_custom_target(
coverage
COMMAND cd ${PROJECT_SOURCE_DIR}/build
Expand Down
32 changes: 32 additions & 0 deletions app/goldfish.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>


#include "types.h"
#include "move.h"
#include "position.h"
#include "bitboards.h"
#include "movegen.h"
#include "uci.h"


using std::cout;
using std::endl;
using std::string;
using std::vector;
using Bitboards::prettyString;

int main(int argc, char *argv[])
{

UCI console = UCI();
console.startCommunication();

return 0;
}
23 changes: 23 additions & 0 deletions include/uci.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef UCI_H
#define UCI_H

#include "types.h"
#include "position.h"
#include "move.h"
#include "movegen.h"


class UCI {
public:
std::string ENGINE_NAME = "Goldfish";
std::string AUTHOR = "Bendik Samseth";

Position pos;

UCI();
void startCommunication();
};



#endif
68 changes: 68 additions & 0 deletions src/uci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <string>
#include <iostream>
#include <sstream>
#include <cassert>
#include <algorithm>
#include <cmath>

#include "types.h"
#include "position.h"
#include "move.h"
#include "movegen.h"
#include "uci.h"

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;

UCI::UCI() {}

void UCI::startCommunication() {
string input = "";

while (true) {
getline(cin, input);

if (input == "uci") {
// use uci, only option
cout << "id name " << ENGINE_NAME << endl;
cout << "id author " << AUTHOR << endl;

// send all options that can be set, TODO

// sent all params and is ready
cout << "uciok" << endl;

}
else if (input == "isready") {
// are we ready? Guess so.
cout << "readyok" << endl;
}

else if (input == "ucinewgame"){
// do init.
pos = Position();
}

else if (input.substr(0, 8) == "position") {
string word;
std::istringstream iss(input);
while (iss >> word) {
if (word == "position")
continue;

else if (word == "startpos")
pos.setFromFEN(STARTING_FEN);

}
}

else if (input == "print")
cout << pos.str() << endl;

else if (input == "quit")
break;
}
}

0 comments on commit bda108f

Please sign in to comment.