Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Napoleon - uci.cpp

uci.cpp

Caricato da: Crybot
Scarica il programma completo

  1. #include "uci.h"
  2. #include <iostream>
  3. #include <string>
  4. #include "search.h"
  5. #include "fenstring.h"
  6. #include "board.h"
  7. #include "stopwatch.h"
  8. #include "benchmark.h"
  9.  
  10. namespace Napoleon
  11. {
  12.     using namespace std;
  13.  
  14.     Board Uci::board;
  15.     thread Uci::search;
  16.  
  17.     void Uci::Start()
  18.     {
  19.         SendCommand<Command::Generic>("--------Napoleon Engine--------");
  20.         cout.setf(ios::unitbuf);// Make sure that the outputs are sent straight away to the GUI
  21.  
  22.         string line;
  23.         string cmd;
  24.         while(getline(cin, line))
  25.         {
  26.             istringstream stream(line);
  27.             stream >> cmd;
  28.  
  29.             if (cmd == "uci")
  30.             {
  31.                 SendCommand<Command::Generic>("id name Napoleon");
  32.                 SendCommand<Command::Generic>("id author Crybot");
  33.                 SendCommand<Command::Generic>("uciok");
  34.             }
  35.             else if (cmd == "quit")
  36.             {
  37.                 SendCommand<Command::Generic>("Bye Bye");
  38.                 break;
  39.             }
  40.             else if (cmd == "isready")
  41.             {
  42.                 SendCommand<Command::Generic>("readyok");
  43.             }
  44.             else if (cmd == "ucinewgame")
  45.             {
  46.                 board.Table.Clear();
  47.             }
  48.             else if (cmd == "stop")
  49.             {
  50.                 Search::StopThinking();
  51.             }
  52.             else if (cmd == "position")
  53.             {
  54.                 Move move;
  55.                 string token;
  56.                 stream >> token;
  57.  
  58.                 if (token == "startpos")
  59.                 {
  60.                     board.LoadGame();
  61.                     stream >> token;
  62.                 }
  63.                 else if (token == "fen")
  64.                 {
  65.                     string fen;
  66.                     while (stream >> token && token != "moves")
  67.                         fen += token + " ";
  68.  
  69.                     board.LoadGame(fen);
  70.                 }
  71.  
  72.                 while (stream >> token && !(move = board.ParseMove(token)).IsNull())
  73.                 {
  74.                     board.MakeMove(move);
  75.                 }
  76.             }
  77.             else if (cmd == "go")
  78.             {
  79.                 if (Search::Task == Stop)
  80.                     go(stream);
  81.             }
  82.         }
  83.     }
  84.  
  85.     void Uci::go(istringstream& stream)
  86.     {
  87.         string token;
  88.         Search::MoveTime = false;
  89.  
  90.         while(stream >> token)
  91.         {
  92.             if (token == "wtime") stream >> Search::Time[PieceColor::White];
  93.             else if (token == "btime") stream >> Search::Time[PieceColor::Black];
  94.             else if (token == "infinite") Search::Task = Infinite;
  95.             else if (token == "movetime")
  96.             {
  97.                 stream >> Search::ThinkTime;
  98.                 Search::MoveTime = true;
  99.             }
  100.         }
  101.  
  102.         search = thread(Search::StartThinking, ref(board));
  103.         search.detach();
  104.     }
  105.  
  106. }