Ejemplo n.º 1
0
        /// <summary>
        /// Creates a key that can be used to return an actual "Move" from the "MoveOrganizer"
        /// This method is also responsible for raising the Pawn promotion events.
        /// </summary>
        /// <param name="from">Where to move from.</param>
        /// <param name="to">Where to move to.</param>
        /// <returns>Key matching the requested move.</returns>
        private MoveIdentifier CreateMoveIdentifier(Square from, Square to)
        {
            MoveIdentifier result;
              result.From = from;
              result.To = to;
              result.PromotionPiece = Piece.None;

              if (Board.Rank(to) == 7 && m_currentGame.Board[from] == Piece.WhitePawn)
              {
            result.PromotionPiece = Piece.WhiteQueen;
            if (m_currentGame.Moves.Find(result) == null)
            {
              result.PromotionPiece = Piece.None;
            }
            else if (WhitePawnPromoted != null)
            {
              PromotionEventArgs promotionArgs = new PromotionEventArgs(PromotionPiece.Queen);
              WhitePawnPromoted(this, promotionArgs);
              switch (promotionArgs.PromotionPiece)
              {
            case PromotionPiece.Bishop:
              result.PromotionPiece = Piece.WhiteBishop;
              break;

            case PromotionPiece.Knight:
              result.PromotionPiece = Piece.WhiteKnight;
              break;

            case PromotionPiece.Rook:
              result.PromotionPiece = Piece.WhiteRook;
              break;
              }
            }
              }

              if (Board.Rank(to) == 0 && m_currentGame.Board[from] == Piece.BlackPawn)
              {
            result.PromotionPiece = Piece.BlackQueen;
            if (m_currentGame.Moves.Find(result) == null)
            {
              result.PromotionPiece = Piece.None;
            }
            else if (BlackPawnPromoted != null)
            {
              PromotionEventArgs promotionArgs = new PromotionEventArgs(PromotionPiece.Queen);
              BlackPawnPromoted(this, promotionArgs);
              switch (promotionArgs.PromotionPiece)
              {
            case PromotionPiece.Bishop:
              result.PromotionPiece = Piece.BlackBishop;
              break;

            case PromotionPiece.Knight:
              result.PromotionPiece = Piece.BlackKnight;
              break;

            case PromotionPiece.Rook:
              result.PromotionPiece = Piece.BlackRook;
              break;
              }
            }
              }

              return result;
        }
Ejemplo n.º 2
0
 private void HandleWhitePawnPromotedEvent(object sender, PromotionEventArgs e)
 {
     e.PromotionPiece = PawnPromotionDialog.ShowPawnPromotionDialog(this);
 }
Ejemplo n.º 3
0
 static void chess_WhitePawnPromoted(object sender, PromotionEventArgs e)
 {
     e.PromotionPiece = promotion;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a key that can be used to return an actual "Move" from the "MoveOrganizer"
        /// This method is also responsible for raising the Pawn promotion events.
        /// </summary>
        /// <param name="from">Where to move from.</param>
        /// <param name="to">Where to move to.</param>
        /// <returns>Key matching the requested move.</returns>
        private MoveIdentifier CreateMoveIdentifier(Square from, Square to)
        {
            MoveIdentifier result;

            result.From           = from;
            result.To             = to;
            result.PromotionPiece = Piece.None;

            if (Board.Rank(to) == 7 && m_currentGame.Board[from] == Piece.WhitePawn)
            {
                result.PromotionPiece = Piece.WhiteQueen;
                if (m_currentGame.Moves.Find(result) == null)
                {
                    result.PromotionPiece = Piece.None;
                }
                else if (WhitePawnPromoted != null)
                {
                    PromotionEventArgs promotionArgs = new PromotionEventArgs(PromotionPiece.Queen);
                    WhitePawnPromoted(this, promotionArgs);
                    switch (promotionArgs.PromotionPiece)
                    {
                    case PromotionPiece.Bishop:
                        result.PromotionPiece = Piece.WhiteBishop;
                        break;

                    case PromotionPiece.Knight:
                        result.PromotionPiece = Piece.WhiteKnight;
                        break;

                    case PromotionPiece.Rook:
                        result.PromotionPiece = Piece.WhiteRook;
                        break;
                    }
                }
            }

            if (Board.Rank(to) == 0 && m_currentGame.Board[from] == Piece.BlackPawn)
            {
                result.PromotionPiece = Piece.BlackQueen;
                if (m_currentGame.Moves.Find(result) == null)
                {
                    result.PromotionPiece = Piece.None;
                }
                else if (BlackPawnPromoted != null)
                {
                    PromotionEventArgs promotionArgs = new PromotionEventArgs(PromotionPiece.Queen);
                    BlackPawnPromoted(this, promotionArgs);
                    switch (promotionArgs.PromotionPiece)
                    {
                    case PromotionPiece.Bishop:
                        result.PromotionPiece = Piece.BlackBishop;
                        break;

                    case PromotionPiece.Knight:
                        result.PromotionPiece = Piece.BlackKnight;
                        break;

                    case PromotionPiece.Rook:
                        result.PromotionPiece = Piece.BlackRook;
                        break;
                    }
                }
            }

            return(result);
        }