-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuci.cpp
More file actions
77 lines (68 loc) · 2.39 KB
/
Copy pathuci.cpp
File metadata and controls
77 lines (68 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "uci.h"
using namespace std;
bool isWhiteTurn = false;
void UCI::applyMove(Board& board, const string& moveStr) {
int startSquare = board.algebraicToIndex(moveStr.substr(0, 2));
int endSquare = board.algebraicToIndex(moveStr.substr(2, 2));
int piece = board.getPieceAt(startSquare);
int capturedPiece = board.getPieceAt(endSquare);
int pieceType = piece & 7;
int capturedPieceType = (capturedPiece & 7);
char promotion = '-';
if (pieceType == 5 && startSquare == 60 && (endSquare == 62 || endSquare == 58)) {
promotion = 'C';
}
if (moveStr.length() > 4) {
promotion = toupper(moveStr[4]);
}
Move move(isWhiteTurn, pieceType, startSquare, endSquare, capturedPieceType, promotion);
board.make_move(move);
isWhiteTurn = !isWhiteTurn;
}
void UCI::uciLoop() {
Board board;
string startpos_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
board.setupGameFromFEN(startpos_fen);
string line;
while (getline(cin, line)) {
istringstream iss(line);
string token;
iss >> token;
if (token == "uci") {
cout << "id name Ocra" << endl;
cout << "id author Devansh Soni" << endl;
cout << "uciok" << endl;
} else if (token == "isready") {
cout << "readyok" << endl;
} else if (token == "ucinewgame") {
board.setupGameFromFEN(startpos_fen);
} else if (token == "position") {
string fen_string;
iss >> token;
if (token == "startpos") {
fen_string = startpos_fen;
board.setupGameFromFEN(fen_string);
}
string moveStr;
while (iss >> moveStr) {
// cout << moveStr;
applyMove(board, moveStr);
}
} else if (token == "go") {
int depth = 7;
string go_token;
while(iss >> go_token) {
if (go_token == "depth") {
iss >> depth;
}
}
Move bestMove = board.search(depth);
cout << "bestmove " << board.indexToAlgebraic(bestMove.startSquare)
<< board.indexToAlgebraic(bestMove.endSquare) << endl;
board.make_move(bestMove);
} else if (token == "quit") {
break;
}
board.printGame();
}
}