int main() { int computer_side; char s[256]; int m; printf("\n"); printf("Tom Kerrigan's Simple Chess Program (TSCP)\n"); printf("version 1.81, 2/5/03\n"); printf("Copyright 1997 Tom Kerrigan\n"); printf("\n"); printf("\"help\" displays a list of commands.\n"); printf("\n"); init_hash(); init_board(); open_book(); gen(); computer_side = EMPTY; max_time = 1 << 25; max_depth = 4; for (;;) { if (side == computer_side) { /* computer's turn */ /* think about the move and make it */ think(1); if (!pv[0][0].u) { printf("(no legal moves)\n"); computer_side = EMPTY; continue; } printf("Computer's move: %s\n", move_str(pv[0][0].b)); makemove(pv[0][0].b); ply = 0; gen(); print_result(); continue; } /* get user input */ printf("tscp> "); if (scanf("%s", s) == EOF) return 0; if (!strcmp(s, "on")) { computer_side = side; continue; } if (!strcmp(s, "off")) { computer_side = EMPTY; continue; } if (!strcmp(s, "st")) { scanf("%d", &max_time); max_time *= 1000; max_depth = 32; continue; } if (!strcmp(s, "sd")) { scanf("%d", &max_depth); max_time = 1 << 25; continue; } if (!strcmp(s, "undo")) { if (!hply) continue; computer_side = EMPTY; takeback(); ply = 0; gen(); continue; } if (!strcmp(s, "new")) { computer_side = EMPTY; init_board(); gen(); continue; } if (!strcmp(s, "d")) { print_board(); continue; } if (!strcmp(s, "bench")) { computer_side = EMPTY; bench(); continue; } if (!strcmp(s, "bye")) { printf("Share and enjoy!\n"); break; } if (!strcmp(s, "xboard")) { xboard(); break; } if (!strcmp(s, "help")) { printf("on - computer plays for the side to move\n"); printf("off - computer stops playing\n"); printf("st n - search for n seconds per move\n"); printf("sd n - search n ply per move\n"); printf("undo - takes back a move\n"); printf("new - starts a new game\n"); printf("d - display the board\n"); printf("bench - run the built-in benchmark\n"); printf("bye - exit the program\n"); printf("xboard - switch to XBoard mode\n"); printf("Enter moves in coordinate notation, e.g., e2e4, e7e8Q\n"); continue; } /* maybe the user entered a move? */ m = parse_move(s); if (m == -1 || !makemove(gen_dat[m].m.b)) printf("Illegal move.\n"); else { ply = 0; gen(); print_result(); } } close_book(); return 0; }
int main() { char line[256]; char args[4][64]; /* It mainly calls ComputerThink(maxdepth) to calculate to desired ply */ char s[256]; int from; int dest; int i; hashRndInit(); startgame (); maxDepth = 6; /* Max depth to search */ MOVE moveBuf[200]; MOVE theBest; int movecnt; /* Belka */ puts (" \n Kitteneitor version June 5th 2013 by Emilio Diaz \n =================================================\n\n"); puts (" Help overview:"); puts (" making a move: e.g. e2e4, c7c5, a7a8q, e1g1 etc."); puts (" d ............ displaying current board"); puts (" on ........... forcing the engine to move"); puts (" sd <n> ....... setting depth to <n> plies"); puts (" undo ......... taking back last move (ply)"); puts (" quit ......... quit console application \n\n"); /* Belka */ side = WHITE; computerSide = BLACK; /* Human is white side */ hdp = 0; /* Current move order */ for (;;) { fflush (stdout); if (side == computerSide) { /* Computer's turn */ theBest = ComputerThink (maxDepth); if (theBest.type_of_move > 8) printf ("type of move the best %d \n", theBest.type_of_move); makeMove (theBest); /* Just the move without pawn crown */ printf("move %c%d%c%d", 'a' + COL(theBest.from), 8 - ROW(theBest.from), 'a' + COL(theBest.dest), 8 - ROW(theBest.dest)); /* Check whether it's a crown */ switch (theBest.type_of_move) { case MOVE_TYPE_PROMOTION_TO_QUEEN: printf("q\n"); break; case MOVE_TYPE_PROMOTION_TO_ROOK: printf("r\n"); break; case MOVE_TYPE_PROMOTION_TO_BISHOP: printf("b\n"); break; case MOVE_TYPE_PROMOTION_TO_KNIGHT: printf("n\n"); break; default: printf("\n"); } /* end switch */ printBoard (); printf ("Castle rights: %d\n", castle); fflush (stdout); continue; } printf ("k> "); /* Get user input */ if (!fgets (line, 256, stdin)) return 0; if (line[0] == '\n') continue; sscanf (line, "%s", s); // if (scanf ("%s", s) == EOF) /* Shut down the program */ // return 0; if (!strcmp (s, "d")) { printBoard (); continue; } if (!strcmp (s, "test1")) { test1 (); printBoard(); continue; } if (!strcmp (s, "test2")) { test2 (); printBoard(); continue; } if (!strcmp (s, "test3")) { test3 (); printBoard(); continue; } if (!strcmp (s, "test4")) { test4 (); printBoard(); continue; } if (!strcmp (s, "test5")) { test5 (); printBoard(); continue; } if (!strcmp (s, "test6")) { test6 (); printBoard(); continue; } if (!strcmp (s, "test7")) { test7 (); printBoard(); continue; } if (!strcmp (s, "test8")) { test8 (); printBoard(); continue; } if (!strcmp (s, "test9")) { test9 (); printBoard(); continue; } if (!strcmp (s, "test10")) { test10 (); printBoard(); continue; } if (!strcmp (s, "test11")) { test11 (); printBoard(); continue; } if (!strcmp (s, "test12")) { test12 (); printBoard(); continue; } if (!strcmp (s, "test13")) { test13 (); printBoard(); continue; } if (!strcmp (s, "test14")) { test14 (); printBoard(); continue; } if (!strcmp (s, "testMoveGen")) //Belka: McKenzie test position { testMoveGen(); printBoard(); continue; } if (!strcmp (s, "testEvalSym")) //Belka: McKenzie test position { testEvalSym(); continue; } if (!strcmp (s, "countNodes")) { countNodes(); continue; } if (!strcmp (s, "testWhitePassedPawns")) { testWhitePassedPawns (); continue; } if (!strcmp (s, "testBlackPassedPawns")) { testBlackPassedPawns (); continue; } if (!strcmp (s, "testWhiteDoubledPawns")) { testWhiteDoubledPawns (); continue; } if (!strcmp (s, "testBlackDoubledPawns")) { testBlackDoubledPawns (); continue; } if (!strcmp (s, "testIsIsolatedPawnWhite")) { testIsIsolatedPawnWhite (); continue; } if (!strcmp (s, "testIsIsolatedPawnBlack")) { testIsIsolatedPawnBlack (); continue; } if (!strcmp (s, "showPawnsInfo")) { showPawnsInfo (); continue; } if (!strcmp (s, "testisSqProtectedByAPawn")) { testisSqProtectedByAPawn(); continue; } // if (!strcmp (s, "testIsSqProtectedByAKnight")) // { // testIsSqProtectedByAKnight(); // continue; // } // if (!strcmp (s, "testIsSqProtectedByABishop")) // { // testIsSqProtectedByABishop(); // continue; // } if (!strcmp (s, "testOpenCols")) { testOpenCols(); continue; } if (!strcmp (s, "undo")) { takeBack (); printBoard (); computerSide = (WHITE + BLACK) - computerSide; continue; } if (!strcmp(s,"setboard")) { strcpy(fenBuf, ""); sscanf(line, "setboard %s %s %s %s", args[0],args[1],args[2],args[3]); strcat(fenBuf, args[0]); strcat(fenBuf, args[1]); strcat(fenBuf, args[2]); strcat(fenBuf, args[3]); setBoard(fenBuf); continue; } if (!strcmp (s, "xboard")) { xboard (); return 0; } if (!strcmp (s, "on")) { computerSide = side; continue; } if (!strcmp (s, "pass")) { side = (WHITE + BLACK) - side; computerSide = (WHITE + BLACK) - side; continue; } if (!strcmp (s, "sd")) { sscanf (line, "sd %d", &maxDepth); continue; } // if (!strcmp (s, "fen")) // { // strcpy (fenstring, ""); // sscanf (linea, "fen %s %s %s %s", args[0], args[1], args[2], // args[3]); // strcat (fenstring, args[0]); // strcat (fenstring, args[1]); // strcat (fenstring, args[2]); // strcat (fenstring, args[3]); // fen (fenstring); // } if (!strcmp (s, "perft")) { sscanf (line, "perft %d", &maxDepth); clock_t start; clock_t stop; double t = 0.0; /* Start timer */ start = clock (); U64 count = perft (maxDepth); /* Stop timer */ stop = clock (); t = (double) (stop - start) / CLOCKS_PER_SEC; // printf ("nodes = %'llu\n", count); printf ("nodes = %8" PRId64 "\n", count); // Belka printf ("time = %.2f s\n", t); continue; } if (!strcmp (s, "quit")) { printf ("Good bye!\n"); return 0; } /* Maybe the user entered a move? */ from = s[0] - 'a'; from += 8 * (8 - (s[1] - '0')); dest = s[2] - 'a'; dest += 8 * (8 - (s[3] - '0')); ply = 0; movecnt = genMoves (side, moveBuf); /* Loop through the moves to see whether it's legal */ for (i = 0; i < movecnt; i++) if (moveBuf[i].from == from && moveBuf[i].dest == dest) { /* Promotion move? */ if (piece[from] == PAWN && (dest < 8 || dest > 55)) { switch (s[4]) { case 'q': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_QUEEN; break; case 'r': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_ROOK; break; case 'b': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_BISHOP; break; case 'n': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_KNIGHT; break; default: puts("Promoting to a McGuffin..., I'll give you a queen"); moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_QUEEN; } } if (!makeMove (moveBuf[i])) { takeBack (); printf ("Illegal move.\n"); } break; } printBoard (); } }