Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <cstdio>
- #include <cassert>
- #include "xbrd.hpp"
- #include "prto.hpp"
- int XBRD_Parse(char str[200])
- {
- char str2[200], str3[200];
- if (!strcmp(str, "xboard")) {
- return 1;
- }
- if (!strcmp(str, "protover")) {
- printf("feature done=0\n");
- printf("feature ping=0\n");
- printf("feature setboard=1\n");
- printf("feature playother=1\n");
- printf("feature san=0\n");
- printf("feature usermove=0\n");
- printf("feature time=1\n");
- printf("feature draw=1\n");
- printf("feature sigint=0\n");
- printf("feature sigterm=0\n");
- printf("feature reuse=1\n");
- printf("feature analyze=0\n");
- printf("feature myname=\"Magic Chess 1.6\"\n");
- printf("feature variants=\"normal\"\n");
- printf("feature colors=0\n");
- printf("feature ics=0\n");
- printf("feature name=0\n");
- printf("feature pause=0\n");
- printf("feature nps=0\n");
- printf("feature debug=1\n");
- printf("feature memory=0\n");
- printf("feature smp=0\n");
- printf("feature egt=\"\"\n");
- printf("feature done=1\n");
- return 1;
- }
- if (!strcmp(str, "quit")) {
- exit(0);
- }
- if (!strcmp(str, "?")) {
- abortFlag = true;
- return 2;
- }
- if (!strcmp(str, "time"))
- sscanf(str, "time %d", searchTime);
- if (!strcmp(str, "go")) {
- printf("tellall I can't play as white :(\n");
- printf("telluser I can't play as white :(\n");
- printf("resign\n");
- return 3;
- }
- if (!strcmp(str, "d")) {
- PrintBoard();
- return 4;
- }
- /* THIS IS THE PROBLEM AREA */
- if (!strcmp(str, "setboard")) {
- sscanf(str, "setboard %s", str2);
- int j = 0;
- for (int i = 63; i > 0; i--) {
- switch (str2[j]) {
- case '/':
- j++;
- break;
- case 'r':
- piece[i] = ROOK;
- color[i] = BLACK;
- j++;
- break;
- case 'n':
- piece[i] = KNIGHT;
- color[i] = BLACK;
- j++;
- break;
- case 'b':
- piece[i] = BISHOP;
- color[i] = BLACK;
- j++;
- break;
- case 'q':
- piece[i] = QUEEN;
- color[i] = BLACK;
- j++;
- break;
- case 'k':
- piece[i] = KING;
- color[i] = BLACK;
- j++;
- break;
- case 'p':
- piece[i] = PAWN;
- color[i] = BLACK;
- j++;
- break;
- case 'P':
- piece[i] = PAWN;
- color[i] = WHITE;
- j++;
- break;
- case 'K':
- piece[i] = KING;
- color[i] = WHITE;
- j++;
- break;
- case 'Q':
- piece[i] = QUEEN;
- color[i] = WHITE;
- j++;
- break;
- case 'B':
- piece[i] = BISHOP;
- color[i] = WHITE;
- j++;
- break;
- case 'N':
- piece[i] = KNIGHT;
- color[i] = WHITE;
- j++;
- break;
- case 8:
- i += 8;
- j++;
- break;
- case 7:
- i += 7;
- j++;
- break;
- case 6:
- i += 6;
- j++;
- break;
- case 5:
- i += 5;
- j++;
- break;
- case 4:
- i += 4;
- j++;
- break;
- case 3:
- i += 3;
- j++;
- break;
- case 2:
- i += 2;
- j++;
- break;
- case 1:
- i++;
- j++;
- break;
- default:
- assert(false);
- break;
- }
- j++;
- switch (str2[j]) {
- case 'w':
- side = WHITE;
- break;
- case 'b':
- side = BLACK;
- break;
- default:
- assert(false);
- break;
- }
- j++;
- for (i = 0; i != 1;) { // only way I can think of for a breakable loop
- switch (str2[j]) {
- case 'K':
- j++;
- break;
- case 'Q':
- j++;
- break;
- case 'k':
- j++;
- break;
- case 'q':
- j++;
- break;
- case '-':
- j++;
- i++;
- break;
- default:
- j++;
- i++;
- break;
- }
- }
- for (i = 0; i != 1;) {
- switch (str2[j]) {
- case '-':
- j++;
- break;
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- case 'g':
- case 'h':
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- j++;
- break;
- default:
- j++;
- break;
- }
- }
- }
- return 2;
- /* END PROBLEM AREA */
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement