コード例 #1
0
ファイル: GameState.cs プロジェクト: aheitzmann/scout-chess
        /// <summary>
        /// Use to see the game state following a potential move.
        /// </summary>
        /// <param name="potentialTurn"></param>
        /// <param name="doRecycle">True to specify that the caller expects the returned
        /// IGameState to be reused upon the next call to this function. False to specify
        /// that the caller needs the returned IGameState to be unaltered by future calls
        /// to this function.</param>
        /// <returns>An IGameState representing the state that the game would
        /// be in if the given turn were applied to the current game state.</returns>
        internal IGameState SimulateMove(TurnRecord potentialTurn, bool doRecycle = true)
        {
            SimulatedGameState simulatedState = lastSimulatedState;

            if (simulatedState == null || !doRecycle)
            {
                simulatedState = new SimulatedGameState(this, potentialTurn);
            }
            else if (doRecycle)
            {
                simulatedState.Initialize(potentialTurn);
            }

            return(simulatedState);
        }
コード例 #2
0
        internal void Initialize(TurnRecord pendingTurn)
        {
            this.pendingTurn  = pendingTurn;
            this.activePieces = new Dictionary <Piece, BoardPosition>(basedOn.ActivePiecePositions);
            if (pendingTurn.Capture != null)
            {
                this.activePieces.Remove(pendingTurn.Capture.PieceCaptured);
            }

            this.activePieces[pendingTurn.Move.PieceMoved] = pendingTurn.Move.To;

            if (pendingTurn.SecondaryMove != null)
            {
                this.activePieces[pendingTurn.SecondaryMove.PieceMoved] = pendingTurn.SecondaryMove.To;
            }

            _gameInfo = new GameInformation(
                basedOn.GameInformation.GameDataStore,
                basedOn.GameInformation.FriendlyName,
                basedOn.GameInformation.GameType,
                DateTime.Now,
                basedOn.GameInformation.MoveCount + 1,
                basedOn.GameInformation.IsActive);
        }
コード例 #3
0
 internal StateChangedEventArgs(TurnRecord turnRecord, IGameState gameState)
 {
     TurnRecord = turnRecord;
     GameState  = gameState;
 }
コード例 #4
0
 internal SimulatedGameState(IGameState basedOn, TurnRecord pendingTurn)
 {
     this.basedOn = basedOn;
     Initialize(pendingTurn);
 }
コード例 #5
0
ファイル: GameState.cs プロジェクト: aheitzmann/scout-chess
        /// <summary>
        /// Modify the model state according to the specified turn.
        /// </summary>
        /// <param name="turn"></param>
        internal void ExecuteMove(TurnRecord turn, bool isUserInitiated)
        {
            Piece piece = null;

            numMoves++; // TODO: consider adding num moves to GameInfo and storing in place of Side in the saved game files.

            // If the turn record was created from a serialized game record, the piece info
            // may not be fully specified. In this case, we should fill in the missing info
            // before saving the turn record on the game history stack.
            if (turn.Move.PieceMoved == null)
            {
                turn.Move.UpdatePieceMoved(this);
            }

            if (turn.SecondaryMove != null && turn.SecondaryMove.PieceMoved == null)
            {
                turn.SecondaryMove.UpdatePieceMoved(this);
            }

            if (turn.Capture != null)
            {
                if (turn.Capture.PieceCaptured == null)
                {
                    turn.Capture.UpdatePieceCaptured(turn.Move, this);
                }
                piece = turn.Capture.PieceCaptured;
                activePiecePositions.Remove(piece);
                capturedPieces.Add(piece);
            }

            if (turn.Promotion != null)
            {
                if (turn.Promotion.PiecePromoted == null)
                {
                    turn.Promotion.UpdatePiecePromoted(turn.Move, this);
                }
                piece = turn.Promotion.PiecePromoted;
                piece.Capabilities = turn.Promotion.NewCapabilities;
            }

            piece = turn.Move.PieceMoved;
            boardState[turn.Move.From.Column, turn.Move.From.Row] = null;
            boardState[turn.Move.To.Column, turn.Move.To.Row]     = piece;
            activePiecePositions[piece] = turn.Move.To;
            piece.TurnLastMoved         = numMoves;

            if (turn.SecondaryMove != null)
            {
                piece = turn.SecondaryMove.PieceMoved ?? GetPieceAt(turn.SecondaryMove.From);
                boardState[turn.SecondaryMove.From.Column, turn.SecondaryMove.From.Row] = null;
                boardState[turn.SecondaryMove.To.Column, turn.SecondaryMove.To.Row]     = piece;
                activePiecePositions[piece] = turn.SecondaryMove.To;
                piece.TurnLastMoved         = numMoves;
            }

            history.Add(turn);
            if (isUserInitiated)
            {
                // rename and refactor
                UpdateGameInfo();
            }
            OnStateChanged(new StateChangedEventArgs(turn, this));
        }