Пример #1
45
  @Test
  public void testProtocolBestMoveCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    // 1. Test
    ProtocolBestMoveCommand command =
        new ProtocolBestMoveCommand(
            new GenericMove(GenericPosition.a2, GenericPosition.a3),
            new GenericMove(GenericPosition.d3, GenericPosition.e5));
    protocol.send(command);

    // 2. Test
    command = new ProtocolBestMoveCommand(null, null);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));

    // 1. Test
    String line = input.readLine();
    assertEquals("bestmove a2a3 ponder d3e5", line);

    // 2. Test
    line = input.readLine();
    assertEquals("bestmove nomove", line);

    assertNull(input.readLine());
  }
Пример #2
0
  @Test
  public void testProtocolInformationCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInformationCommand command = new ProtocolInformationCommand();
    command.setDepth(8);
    command.setMaxDepth(20);
    command.setCentipawns(400);
    command.setCurrentMove(new GenericMove(GenericPosition.a2, GenericPosition.a3));
    command.setCurrentMoveNumber(30);
    command.setHash(50);
    command.setNps(300);
    command.setTime(3000);
    command.setNodes(5000);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals(
        "info depth 8 seldepth 20 score cp 400 currmove a2a3 currmovenumber 30 hashfull 50 nps 300 time 3000 nodes 5000",
        line);
    assertNull(input.readLine());
  }
Пример #3
0
  @Test
  public void testProtocolInitializeAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInitializeAnswerCommand command =
        new ProtocolInitializeAnswerCommand("My Engine", "The Author");
    command.addOption(new Option("Hash", "spin", "16", "4", "64", null));
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("id name My Engine", line);
    line = input.readLine();
    assertEquals("id author The Author", line);
    line = input.readLine();
    assertEquals("option name Hash type spin default 16 min 4 max 64", line);
    line = input.readLine();
    assertEquals("uciok", line);
    assertNull(input.readLine());
  }
Пример #4
0
  @Test
  public void testProtocolReadyAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolReadyAnswerCommand command = new ProtocolReadyAnswerCommand("does not matter");
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("readyok", line);
    assertNull(input.readLine());
  }