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.uci;
19 import java.util.List;
21 import org.hedgecode.chess.uci.annotation.CommandDirection;
22 import org.hedgecode.chess.uci.command.OptionParams;
23 import org.hedgecode.chess.uci.command.OptionType;
28 * @author Dmitry Samoshin aka gotty
30 public class AcceptorStub implements Acceptor {
32 private static final String LOG_TO_FORMAT = ">> %s %s";
33 private static final String LOG_FROM_FORMAT = "<< %s %s";
35 private CommandExecutor commandExecutor;
40 public void init(CommandExecutor executor) {
41 commandExecutor = executor;
47 UCIConstants.UCI, CommandDirection.TO_ENGINE, null
49 log(CommandDirection.TO_ENGINE, UCIConstants.UCI, null);
53 public void id(String params) {
54 log(CommandDirection.FROM_ENGINE, UCIConstants.ID, params);
58 public void uciOK(String params) {
59 log(CommandDirection.FROM_ENGINE, UCIConstants.UCI_OK, params);
61 UCIConstants.IS_READY, CommandDirection.TO_ENGINE, null
63 log(CommandDirection.TO_ENGINE, UCIConstants.IS_READY, null);
67 public void readyOK(String params) {
68 log(CommandDirection.FROM_ENGINE, UCIConstants.READY_OK, params);
70 UCIConstants.QUIT, CommandDirection.TO_ENGINE, null
72 log(CommandDirection.TO_ENGINE, UCIConstants.QUIT, null);
76 public void setOption(String name) {
78 CommandDirection.FROM_ENGINE,
82 OptionParams.OPTION_NAME, name, OptionParams.OPTION_TYPE, OptionType.BUTTON.type()
88 public void setOption(String name, boolean def) {
90 CommandDirection.FROM_ENGINE,
94 OptionParams.OPTION_NAME, name, OptionParams.OPTION_TYPE, OptionType.CHECK.type(),
95 OptionParams.OPTION_DEFAULT, def
101 public void setOption(String name, int def, int min, int max) {
103 CommandDirection.FROM_ENGINE,
106 "%s %s %s %s %s %d %s %d %s %d",
107 OptionParams.OPTION_NAME, name, OptionParams.OPTION_TYPE, OptionType.SPIN.type(),
108 OptionParams.OPTION_DEFAULT, def, OptionParams.OPTION_MIN, min, OptionParams.OPTION_MAX, max
114 public void setOption(String name, String def) {
116 CommandDirection.FROM_ENGINE,
120 OptionParams.OPTION_NAME, name, OptionParams.OPTION_TYPE, OptionType.STRING.type(),
121 OptionParams.OPTION_DEFAULT, def == null ? "" : def
127 public void setOption(String name, String def, List<String> vars) {
128 StringBuilder varOptions = new StringBuilder();
129 for (String var : vars)
131 String.format("%s %s ", OptionParams.OPTION_VAR, var == null ? "" : var)
134 CommandDirection.FROM_ENGINE,
137 "%s %s %s %s %s %s %s",
138 OptionParams.OPTION_NAME, name, OptionParams.OPTION_TYPE, OptionType.COMBO.type(),
139 OptionParams.OPTION_DEFAULT, def == null ? "" : def, varOptions.toString().trim()
145 public void terminate(String params) {
146 log(CommandDirection.FROM_ENGINE, UCIConstants.TERMINATE, params);
149 private void log(CommandDirection direction, String name, String params) {
152 CommandDirection.TO_ENGINE.equals(direction)
156 params != null ? params : ""