コード例 #1
0
ファイル: Match.cs プロジェクト: longde123/grove
        public void Start()
        {
            Game game;

            if (_p.IsSavedMatch)
            {
                game = new Game(GameParameters.Load(
                                    player1Controller: PlayerType.Human,
                                    player2Controller: PlayerType.Machine,
                                    savedGame: _p.SavedMatch.SavedGame,
                                    looser: _p.SavedMatch.Looser));

                Player1WinCount = _p.SavedMatch.Player1WinCount;
                Player2WinCount = _p.SavedMatch.Player2WinCount;
                _looser         = _p.SavedMatch.Looser;

                if (game.IsFinished)
                {
                    // if the game was saved when it was already finished
                    // do not update the score again
                    _skipNextScoreUpdate = true;
                }
            }
            else
            {
                game = new Game(GameParameters.Default(
                                    _p.Player1, _p.Player2));
            }

            var shouldPlayAnotherGame = RunGame(game);

            while (shouldPlayAnotherGame || _rematch)
            {
                if (_rematch)
                {
                    Player1WinCount = 0;
                    Player2WinCount = 0;
                    _rematch        = false;
                    _looser         = null;
                }

                game = new Game(GameParameters.Default(
                                    _p.Player1, _p.Player2));

                shouldPlayAnotherGame = RunGame(game);
            }
        }
コード例 #2
0
        public Game(GameParameters p)
        {
            ChangeTracker = new ChangeTracker();
            Stack         = new Stack();
            Turn          = new TurnInfo();
            Ai            = new SearchRunner(p.SearchParameters, this);
            Combat        = new Combat();
            Settings      = p.Settings;

            _decisionQueue = new DecisionQueue();
            _publisher     = new Publisher(changeTracker: ChangeTracker);
            _wasStopped    = new Trackable <bool>();
            _stateMachine  = new StateMachine();

            var player1 = new Player(p.Player1, p.Player1Controller);
            var player2 = new Player(p.Player2, p.Player2Controller);

            Players = new Players(player1, player2);

            _damagePreventions  = new DamagePreventions();
            _damageRedirections = new DamageRedirections();
            _namedGameModifiers = new NamedGameModifiers();
            _costModifiers      = new CostModifiers();
            _scenario           = new Scenario(this);

            if (p.IsSavedGame)
            {
                Random   = new RandomGenerator(p.SavedGame.RandomSeed);
                Recorder = new GameRecorder(this, p.SavedGame.Decisions);
            }
            else
            {
                Random   = new RandomGenerator();
                Recorder = new GameRecorder(this);
            }

            Initialize();

            if (p.IsSavedGame)
            {
                p.SavedGame.Decisions.Position = 0;

                Player looser = null;

                if (p.Looser != null)
                {
                    looser = p.Looser == 0 ? player1 : player2;
                }

                _stateMachine.Start(() =>
                {
                    if (p.RollBack > 0)
                    {
                        return((Turn.StateCount < p.SavedGame.StateCount - p.RollBack) || (_stateMachine.HasPendingDecisions));
                    }

                    return(Turn.StateCount < p.SavedGame.StateCount || Recorder.IsPlayback);
                }, skipPreGame: false, looser: looser);

                Recorder.DiscardUnloadedResults();
                _wasLoaded = true;
            }
        }