Exemple #1
0
  @Test
  public void testDebug() throws IOException {
    String[] commands = {"debug", "debug on", "debug off", "debug abc"};
    UciProtocol protocol = createUciProtocol(commands);

    IEngineCommand command = protocol.receive();
    assertEquals(EngineInitializeRequestCommand.class, command.getClass());

    // "debug"
    command = protocol.receive();
    assertEquals(EngineDebugCommand.class, command.getClass());
    assertEquals(true, ((EngineDebugCommand) command).toggle);

    // "debug on"
    command = protocol.receive();
    assertEquals(EngineDebugCommand.class, command.getClass());
    assertEquals(false, ((EngineDebugCommand) command).toggle);
    assertEquals(true, ((EngineDebugCommand) command).debug);

    // "debug off"
    command = protocol.receive();
    assertEquals(EngineDebugCommand.class, command.getClass());
    assertEquals(false, ((EngineDebugCommand) command).toggle);
    assertEquals(false, ((EngineDebugCommand) command).debug);

    try {
      command = protocol.receive();
      fail();
    } catch (IOException e) {
    }
  }
Exemple #2
0
  @Test
  public void testBasic() throws IOException {
    String[] commands = {""};
    UciProtocol protocol = createUciProtocol(commands);

    IEngineCommand command = protocol.receive();
    assertEquals(EngineInitializeRequestCommand.class, command.getClass());

    try {
      command = protocol.receive();
      fail();
    } catch (IOException e) {
    }
  }
Exemple #3
0
  @Test
  public void testSetOption() throws IOException {
    String[] commands = {
      "setoption",
      "setoption name",
      "setoption name Clear Hash",
      "setoption name Clear   Hash",
      "setoption name Clear Hash value",
      "setoption name Clear Hash value 5",
      "setoption name Clear Hash value 5 4 3 2 1"
    };
    UciProtocol protocol = createUciProtocol(commands);

    IEngineCommand command = protocol.receive();
    assertEquals(EngineInitializeRequestCommand.class, command.getClass());

    // "setoption name Clear Hash"
    command = protocol.receive();
    assertEquals(EngineSetOptionCommand.class, command.getClass());
    assertEquals("Clear Hash", ((EngineSetOptionCommand) command).name);
    assertEquals(null, ((EngineSetOptionCommand) command).value);

    // "setoption name Clear   Hash"
    command = protocol.receive();
    assertEquals(EngineSetOptionCommand.class, command.getClass());
    assertEquals("Clear   Hash", ((EngineSetOptionCommand) command).name);
    assertEquals(null, ((EngineSetOptionCommand) command).value);

    // "setoption name Clear Hash value 5"
    command = protocol.receive();
    assertEquals(EngineSetOptionCommand.class, command.getClass());
    assertEquals("Clear Hash", ((EngineSetOptionCommand) command).name);
    assertEquals("5", ((EngineSetOptionCommand) command).value);

    // "setoption name Clear Hash value 5 4 3 2 1"
    command = protocol.receive();
    assertEquals(EngineSetOptionCommand.class, command.getClass());
    assertEquals("Clear Hash", ((EngineSetOptionCommand) command).name);
    assertEquals("5 4 3 2 1", ((EngineSetOptionCommand) command).value);

    try {
      command = protocol.receive();
      fail();
    } catch (IOException e) {
    }
  }
Exemple #4
0
  @Test
  public void testGo() throws IOException {
    String[] commands = {
      "go",
      "go searchmoves",
      "go searchmoves a2a3",
      "go searchmoves t2a9",
      "go ponder",
      "go wtime",
      "go wtime 100",
      "go wtime abc",
      "go btime",
      "go btime 100",
      "go btime abc",
      "go winc",
      "go winc 50",
      "go winc abc",
      "go binc",
      "go binc 50",
      "go binc abc",
      "go movestogo",
      "go movestogo 20",
      "go movestogo abc",
      "go depth",
      "go depth 5",
      "go depth abc",
      "go nodes",
      "go nodes 1000",
      "go nodes abc",
      "go mate",
      "go mate 4",
      "go mate abc",
      "go movetime",
      "go movetime 1000",
      "go movetime abc",
      "go infinite"
    };
    UciProtocol protocol = createUciProtocol(commands);

    IEngineCommand command = protocol.receive();
    assertEquals(EngineInitializeRequestCommand.class, command.getClass());

    // "go"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());

    // "go searchmoves a2a3"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(1, ((EngineStartCalculatingCommand) command).getSearchMoveList().size());
    assertEquals(
        new GenericMove(GenericPosition.a2, GenericPosition.a3),
        ((EngineStartCalculatingCommand) command).getSearchMoveList().get(0));

    // "go ponder"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(true, ((EngineStartCalculatingCommand) command).getPonder());

    // "go wtime 100"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(
        100, ((EngineStartCalculatingCommand) command).getClock(GenericColor.WHITE).longValue());

    // "go btime 100"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(
        100, ((EngineStartCalculatingCommand) command).getClock(GenericColor.BLACK).longValue());

    // "go winc 50"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(
        50,
        ((EngineStartCalculatingCommand) command)
            .getClockIncrement(GenericColor.WHITE)
            .longValue());

    // "go binc 50"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(
        50,
        ((EngineStartCalculatingCommand) command)
            .getClockIncrement(GenericColor.BLACK)
            .longValue());

    // "go movestogo 20"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(20, ((EngineStartCalculatingCommand) command).getMovesToGo().intValue());

    // "go depth 5"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(5, ((EngineStartCalculatingCommand) command).getDepth().intValue());

    // "go nodes 1000"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(1000, ((EngineStartCalculatingCommand) command).getNodes().longValue());

    // "go mate 4"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(4, ((EngineStartCalculatingCommand) command).getMate().intValue());

    // "go movetime 1000"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(1000, ((EngineStartCalculatingCommand) command).getMoveTime().longValue());

    // "go infinite"
    command = protocol.receive();
    assertEquals(EngineStartCalculatingCommand.class, command.getClass());
    assertEquals(true, ((EngineStartCalculatingCommand) command).getInfinite());

    try {
      command = protocol.receive();
      fail();
    } catch (IOException e) {
    }
  }
Exemple #5
0
  @Test
  public void testPosition() throws IOException {
    String[] commands = {
      "position",
      "position startpos",
      "a b c d position startpos",
      "a b c d position startpos moves a2a3",
      "a b c d position startpos x y z",
      "a b c d position startpos moves",
      "a b c d position fen",
      "a b c d position fen x y z",
      "a b c d position fen moves",
      "a b c d position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
      "a b c d position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves a4a5",
      "a b c d position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves xa10"
    };
    UciProtocol protocol = createUciProtocol(commands);

    IEngineCommand command = protocol.receive();
    assertEquals(EngineInitializeRequestCommand.class, command.getClass());

    // "position startpos"
    command = protocol.receive();
    assertEquals(EngineAnalyzeCommand.class, command.getClass());
    assertEquals(
        new GenericBoard(GenericBoard.STANDARDSETUP), ((EngineAnalyzeCommand) command).board);
    assertTrue(((EngineAnalyzeCommand) command).moveList.isEmpty());

    // "a b c d position startpos"
    command = protocol.receive();
    assertEquals(EngineAnalyzeCommand.class, command.getClass());
    assertEquals(
        new GenericBoard(GenericBoard.STANDARDSETUP), ((EngineAnalyzeCommand) command).board);
    assertTrue(((EngineAnalyzeCommand) command).moveList.isEmpty());

    // "a b c d position startpos moves a2a3"
    command = protocol.receive();
    assertEquals(EngineAnalyzeCommand.class, command.getClass());
    assertEquals(
        new GenericBoard(GenericBoard.STANDARDSETUP), ((EngineAnalyzeCommand) command).board);
    assertEquals(1, ((EngineAnalyzeCommand) command).moveList.size());
    assertEquals(
        new GenericMove(GenericPosition.a2, GenericPosition.a3),
        ((EngineAnalyzeCommand) command).moveList.get(0));

    // "a b c d position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
    command = protocol.receive();
    assertEquals(EngineAnalyzeCommand.class, command.getClass());
    assertEquals(
        new GenericBoard(GenericBoard.STANDARDSETUP), ((EngineAnalyzeCommand) command).board);
    assertTrue(((EngineAnalyzeCommand) command).moveList.isEmpty());

    // "a b c d position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves a4a5"
    command = protocol.receive();
    assertEquals(EngineAnalyzeCommand.class, command.getClass());
    assertEquals(
        new GenericBoard(GenericBoard.STANDARDSETUP), ((EngineAnalyzeCommand) command).board);
    assertEquals(1, ((EngineAnalyzeCommand) command).moveList.size());
    assertEquals(
        new GenericMove(GenericPosition.a4, GenericPosition.a5),
        ((EngineAnalyzeCommand) command).moveList.get(0));

    try {
      command = protocol.receive();
      fail();
    } catch (IOException e) {
    }
  }