Exemplo n.º 1
0
        public static GameState LoadFromPTN(string ptn)
        {
            var database = TakEngine.Notation.TakPGN.LoadFromString(ptn);

            TakEngine.Notation.GameRecord _gameRecord = new TakEngine.Notation.GameRecord();
            _gameRecord = database.Games[0];
            var game = GameState.NewGame(_gameRecord.BoardSize);

            BoardPosition[] normalPositions = new BoardPosition[game.Size * game.Size];
            for (int i = 0; i < normalPositions.Length; i++)
            {
                normalPositions[i] = new BoardPosition(i % game.Size, i / game.Size);
            }

            foreach (var notation in _gameRecord.MoveNotations)
            {
                List <IMove> _tempMoveList = new List <IMove>();
                TakAI.EnumerateMoves(_tempMoveList, game, normalPositions);
                var move = notation.MatchLegalMove(_tempMoveList);
                if (null == move)
                {
                    throw new ApplicationException("Illegal move: " + notation.Text);
                }
                move.MakeMove(game);
                game.Ply++;
            }
            return(game);
        }
Exemplo n.º 2
0
        private void miFileOpen_Click(object sender, EventArgs e)
        {
            if (dlgOpen.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            try
            {
                var database = TakEngine.Notation.TakPGN.LoadFromFile(dlgOpen.FileName);
                if (database.Games.Count != 1)
                {
                    throw new ApplicationException("File must contain exactly 1 game");
                }
                _gameRecord     = database.Games[0];
                _game           = GameState.NewGame(_gameRecord.BoardSize);
                _ai             = new TakAI(_game.Size);
                _evaluator      = new TakAI.Evaluator(_game.Size);
                _boardView.Game = _game;

                foreach (var notation in _gameRecord.MoveNotations)
                {
                    _tempMoveList.Clear();
                    TakAI.EnumerateMoves(_tempMoveList, _game, _ai.NormalPositions);
                    var move = notation.MatchLegalMove(_tempMoveList);
                    if (null == move)
                    {
                        throw new ApplicationException("Illegal move: " + notation.Text);
                    }
                    move.MakeMove(_game);
                    _movesOfNotation[notation] = move;
                    _navigating = true;
                    if (_historyForm != null)
                    {
                        _historyForm.AddPly(notation.Text);
                    }
                    _navigating = false;
                    _game.Ply++;
                }
                _fileName = dlgOpen.FileName;
                PrepareTurn();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Failed to open file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void LoadFromDatabase(TakEngine.Notation.DatabaseRecord database)
        {
            if (database.Games.Count != 1)
            {
                throw new ApplicationException("File must contain exactly 1 game");
            }
            _gameRecord     = database.Games[0];
            _game           = GameState.NewGame(_gameRecord.BoardSize);
            _ai             = new TakAI_V4(_game.Size);
            _evaluator      = _ai.Evaluator;
            _boardView.Game = _game;

            foreach (var notation in _gameRecord.MoveNotations)
            {
                ProcessMove(notation: notation);
            }
            _fileName = dlgOpen.FileName;
            PrepareTurn();
        }