Esempio n. 1
0
        public void SetGameData(UciGameData data)
        {
            // TODO
            List<Position.Move> extra_moves;
            if (m_analyzer.CurrentGame.IsGameContinuation(data, out extra_moves))
            {
                if (CurrentPosition == null)
                {
                    if (!m_input_messages_processor.ExecuteCommand(
                        Factory.Instance.CreateCommand(
                            Exports.Commands.SetInitialPosition)))
                    {
                        // TODO - process the error
                        throw new Exception();
                    }
                }

                if (extra_moves != null)
                {
                    foreach (var m in extra_moves)
                    {
                        var move_desc = m.IsPromotion
                            ? GetLegalMove(new ChessboardCell(m.FromCell),
                            new ChessboardCell(m.ToCell), m.PromoteToPiece)
                            : GetLegalMove(new ChessboardCell(m.FromCell),
                            new ChessboardCell(m.ToCell));

                        if (move_desc == null)
                        {
                            // TODO - process the eror
                            throw new NotImplementedException();
                        }

                        m_input_messages_processor.ExecuteCommand(
                            Factory.Instance.CreateCommand(Exports.Commands.PlayMove,
                            move_desc));
                    }
                }
            }
            // Current game is already the same as specified by the
            // the uci data object
        }
Esempio n. 2
0
        private List<ICommand> MakeUciPositionCommands(string[] tokens,
            int first_token_index)
        {
            var game_data = new UciGameData();

            int cur_token_idx = first_token_index + 1;

            if (cur_token_idx < tokens.Length)
            {
                if (tokens[cur_token_idx] == "startpos")
                {
                    game_data.m_initial_position = Fen.InitialPosition;
                    ++cur_token_idx;
                }
                else if (tokens[cur_token_idx] == "fen")
                {
                    throw new NotImplementedException();
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }

            if (cur_token_idx < tokens.Length && tokens[cur_token_idx] == "moves")
            {
                game_data.m_moves = new List<string>(tokens.Length - cur_token_idx);
                for (int i = cur_token_idx + 1; i < tokens.Length; ++i)
                {
                    game_data.m_moves.Add(tokens[i]);
                }
            }

            return new List<ICommand>() {
                Factory.Instance.CreateCommand(Exports.Commands.SetPosition,
                game_data)
            };
        }