2 * Copyright (c) 2018. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.hedgefish;
19 import org.hedgecode.chess.uci.CommandExecutor;
20 import org.hedgecode.chess.uci.Engine;
21 import org.hedgecode.chess.uci.EngineException;
22 import org.hedgecode.chess.uci.EngineRunner;
23 import org.hedgecode.chess.uci.Transmitter;
24 import org.hedgecode.chess.uci.UCIConstants;
25 import org.hedgecode.chess.uci.annotation.CommandDirection;
28 * Hedgefish UCI Engine Runner.
30 * @author Dmitry Samoshin aka gotty
32 public final class HedgefishEngineRunner implements EngineRunner {
34 private HedgefishEngine engine;
35 private boolean isRunning;
37 HedgefishEngineRunner() {
38 engine = new HedgefishEngine();
43 public Engine init() throws EngineException {
45 throw new EngineException("uci.engine.already.run");
50 public void run(final CommandExecutor commandExecutor) throws EngineException {
52 throw new EngineException("uci.engine.already.run");
54 Thread engineThread = new Thread(
58 Transmitter<HedgefishCommand> engineTransmitter = engine.transmitter();
59 while (engineTransmitter.isActive()) {
60 if (engineTransmitter.hasCommand()) {
61 HedgefishCommand command = engineTransmitter.transmitCommand();
64 CommandDirection.FROM_ENGINE,
71 UCIConstants.TERMINATE,
72 CommandDirection.FROM_ENGINE,