示例#1
0
        public GameState MoveWithoutValidation(Move move)
        {
            Piece        pieceToMove = this.GetPiece(move.Start);
            List <Piece> newPieces   = new List <Piece>(this.Pieces);
            MoveActions  moveActions = pieceToMove.Move(this, move);

            foreach (var pieceRemoveAction in moveActions.PieceRemoveActions)
            {
                newPieces.Remove(pieceRemoveAction.Piece);
            }

            foreach (var pieceMoveAction in moveActions.PieceMoveActions)
            {
                Piece piece = pieceMoveAction.Piece;
                newPieces.Remove(piece);
                newPieces.Add(PieceFactory.CreatePiece(pieceMoveAction.Goal, piece.Type, piece.Color, piece.MoveCount + 1));
            }

            foreach (var piecePromotionAction in moveActions.PiecePromotionActions)
            {
                Piece piece = piecePromotionAction.Piece;
                newPieces.Remove(piece);
                newPieces.Add(PieceFactory.CreatePiece(piecePromotionAction.Goal, piecePromotionAction.PromotionType, piece.Color, piece.MoveCount + 1));
            }

            return(new GameState(newPieces, this.NextToMove.Enemy(), move));
        }
示例#2
0
        public virtual MoveActions Move(GameState gameState, Move move)
        {
            MoveActions moveActions = new MoveActions();

            if (move.Promotion == null)
            {
                moveActions.AddPieceMoveAction(new PieceMoveAction(this, move.Goal));
            }
            else
            {
                moveActions.AddPiecePromotionAction(new PiecePromotionAction(this, move.Goal, move.Promotion.Value));
            }

            if (gameState.IsOccupiedByEnemy(move.Goal, this.Color))
            {
                moveActions.AddPieceRemoveAction(new PieceRemoveAction(gameState.GetPiece(move.Goal)));
            }

            return(moveActions);
        }