Example #1
0
 public EngineOptionsMessage(EngineOptions options = null, Action <IDictionary <string, string> > callback = null) : base()
 {
     EngineOptionsVM = new EngineOptionsViewModel(options, callback);
 }
Example #2
0
        private void ProcessEngineOutput(EngineCommand command, string[] outputLines)
        {
            string errorMessage       = "";
            string invalidMoveMessage = "";

            foreach (string line in outputLines)
            {
                if (line.StartsWith("err"))
                {
                    errorMessage = line.Substring(line.IndexOf(' ') + 1);
                }
                else if (line.StartsWith("invalidmove"))
                {
                    invalidMoveMessage = line.Substring(line.IndexOf(' ') + 1);
                }
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                throw new EngineException(errorMessage);
            }

            if (!string.IsNullOrWhiteSpace(invalidMoveMessage))
            {
                throw new InvalidMoveException(invalidMoveMessage);
            }

            string firstLine = "";
            string lastLine  = "";

            if (null != outputLines && outputLines.Length > 0)
            {
                firstLine = outputLines[0];
                lastLine  = outputLines[outputLines.Length - 2]; // ignore the ok line
            }

            // Update other properties
            switch (command)
            {
            case EngineCommand.Board:
            case EngineCommand.NewGame:
            case EngineCommand.Play:
            case EngineCommand.Pass:
            case EngineCommand.Undo:
                Board = !string.IsNullOrWhiteSpace(firstLine) ? new ViewerBoard(firstLine) : null;
                break;

            case EngineCommand.ValidMoves:
                ValidMoves = !string.IsNullOrWhiteSpace(firstLine) ? new MoveSet(firstLine) : null;
                break;

            case EngineCommand.BestMove:
                // Update the target move (and potentially auto-play it)
                ProcessBestMove(lastLine, true);
                TryStopTimedCommand();
                break;

            case EngineCommand.History:
                BoardHistory = !string.IsNullOrWhiteSpace(firstLine) ? new BoardHistory(firstLine) : null;
                break;

            case EngineCommand.Options:
                string[] optionLines = new string[outputLines.Length - 1];
                Array.Copy(outputLines, optionLines, optionLines.Length);
                EngineOptions.ParseEngineOptionLines(optionLines);
                break;

            case EngineCommand.Info:
            case EngineCommand.Help:
            default:
                break;
            }
        }