aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 09cb4d1b1b9df824151231345eef67a34269ae9f (plain)
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
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>

#include "board/board.hpp"
#include "misc.hpp"
#include "uci.hpp"
#include "zobrist.hpp"

static void perft(int argc, char *argv[]) {
  if (argc != 4 || std::string(argv[1]) != "perft") {
    std::cout << "Usage: ./mono\n";
    std::cout << "       ./mono perft <non-negative depth> <fen>\n";
    exit(1);
  }

  int depth = -1;
  try {
    depth = std::stoi(argv[2]);
  } catch (const std::exception &) {
    std::cout << "info string usage: ./mono perft <non-negative depth>\n";
    exit(1);
  }

  if (depth < 0) {
    std::cout << "info string usage: ./mono perft <non-negative depth>\n";
    exit(1);
  }

  std::string fen = argv[3];

  auto start = std::chrono::steady_clock::now();

  Game game = initBoard(fen, nullptr);
  uint64_t count = MoveGenTest(depth, &game);

  auto end = std::chrono::steady_clock::now();
  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
                .count();
  std::ostringstream oss;
  oss << "{\"ms\": " << ms << ", \"result\": " << count << "}";

  std::cout << oss.str() << "\n";
}

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

  if (argc == 4) {
    perft(argc, argv);
    return 0;
  }

  std::cout << engine_info();
  Uci();
  return 0;
}