Ejemplo n.º 1
0
        /* Create a MovementStyle object which takes as argument a piece and generates
        The valid directions that piece can move in and the valid lengths of the
        movement rays in each of those directions*/
        public MovementStyle(Piece piece)
        {
            this.dirs = new List<Tuple<int, int>>();

            switch (piece.Val)
            {
                case EGamePieces.WhitePawn:
                    createWhitePawnMovement(piece);
                    break;
                case EGamePieces.BlackPawn:
                    createBlackPawnMovement(piece);
                    break;
                case EGamePieces.WhiteRook:
                case EGamePieces.BlackRook:
                    createRookMovement();
                    break;
                case EGamePieces.WhiteKnight:
                case EGamePieces.BlackKnight:
                    createKnightMovement();
                    break;
                case EGamePieces.WhiteBishop:
                case EGamePieces.BlackBishop:
                    createBishopMovement();
                    break;
                case EGamePieces.WhiteQueen:
                case EGamePieces.BlackQueen:
                    createQueenMovement();
                    break;
                case EGamePieces.WhiteKing:
                case EGamePieces.BlackKing:
                    createKingMovement();
                    break;
                default:
                    throw new ArgumentException($"Piece value provided to CaptureStyle invalid {piece.Val}");
            }
        }
Ejemplo n.º 2
0
 /* Make a thread safe invoke on the viewRef in order to use it as the parent argument
 to showDialog for the promotion selection form. This is called by Move includes pawn promotion. */
 private void PromotionSelectionPopup(ref FormedMove move, Piece mvPiece)
 {
     if (this.viewRef.InvokeRequired)
     {
         PromotionSelectionPopupCallback d = new PromotionSelectionPopupCallback(PromotionSelectionPopup);
         this.viewRef.Invoke(d, new object[] { move, mvPiece });
     }
     else
     {
         EGamePieces promotionPiece;
         EGamePieces promotionPieceDefault;
         View.PromotionSelection promotionSelection = new View.PromotionSelection(mvPiece);
         promotionPieceDefault = promotionSelection.DefaultPiece; // (queen)
         // remove the ability to x close the dialog before a piece is selected
         promotionSelection.ControlBox = false;
         if (promotionSelection.ShowDialog(this.viewRef) == System.Windows.Forms.DialogResult.OK)
         {
             promotionPiece = promotionSelection.SelectedPiece;
             promotionSelection.Dispose();
             move.PromotionSelection = promotionPiece;
         }
         else
             move.PromotionSelection = promotionPieceDefault;
     }
 }
Ejemplo n.º 3
0
 /* This constructor is used when a tile is made without a piece ready to be placed on it.
 If the piece's value hasn't yet been determined or the tile is intended to be empty. */
 public Tile()
 {
     this.piece = null;
 }
Ejemplo n.º 4
0
 /* This constructor usually used when a tile is a made with a piece ready to be placed on it.
 This is the constructor used during the ChessPosition.Setup method where the board is populated. */
 public Tile(Piece piece)
 {
     this.piece = piece;
 }
Ejemplo n.º 5
0
 /* Takes a location and a piece value and updates the tile at that location with
 this new piece value.
 This method is overridden by the ChessPositionModel which adds a BoardChanged event. */
 protected virtual void updatePosWithPiece(Tuple<int, int> location, Piece newPiece)
 {
     int row = location.Item1;
     int col = location.Item2;
     Board[row, col].piece = newPiece;
 }
Ejemplo n.º 6
0
 /* Returns a ChessPosition object which is a deep copy of this one. Since this method is
 also inherited by the ChessPositionModel, if the CPM produces this object it will be a
 deep copy of the ChessPositionModel object as if it were a ChessPosition. (CPM minus handlers etc).
 This function will be used during evaluation in the king check phase, and will also be used during
 the move search of the ai function. */
 public ChessPosition getChessPositionCopy()
 {
     int dimCopy = Size;
     // deep copy the board manually //
     Tile[,] boardCopy = new Tile[dimCopy, dimCopy];
     for (int j = 0; j < dimCopy; j ++)
     {
         for (int k = 0; k < dimCopy; k ++)
         {
             Tile tileCopy = new Tile();
             if (!Board[j,k].IsEmpty())
             {
                 Piece piece = Board[j, k].piece;
                 EGamePieces val = piece.Val;
                 bool mv = piece.MovedOnce;
                 Piece pieceCopy = new Piece(val);
                 pieceCopy.MovedOnce = mv;
                 tileCopy.piece = pieceCopy;
             }
             boardCopy[j, k] = tileCopy;
         }
     }
     // copy rest of ChessPosition properties
     Player playerCopy = new Player(this.Player.PlayerValue);
     Dictionary<char, bool> castleCopy = new Dictionary<char, bool>(Castle);
     Tuple<int, int> enPassantSqCopy = (EnPassantSq == null) ? null : Tuple.Create(EnPassantSq.Item1, EnPassantSq.Item2);
     int halfmoveClockCopy = HalfMoveClock;
     List<EGamePieces> piecesCapdCopy = new List<EGamePieces>(PiecesCapd);
     // create and return the copy
     ChessPosition cpCopy = new ChessPosition(dimCopy, boardCopy, playerCopy, castleCopy, enPassantSqCopy, halfmoveClockCopy, piecesCapdCopy);
     return cpCopy;
 }
Ejemplo n.º 7
0
        /* pawn moves 'advancing' forward only
        in all cases of pawn movement(when piece.MovedOnce = true), except for the first
        the calling code will only consider the first position in the
        movement ray generated from this style.
        So this movement style creates the Set of pawn moves, but pawn moves after its
        first only consider a subset of this style. */
        private void createBlackPawnMovement(Piece piece)
        {
            this.dirs.Add(Tuple.Create(+1, 0));

            this.maxIterations = 2;
        }
Ejemplo n.º 8
0
 /* Same as the ChessPosition implementation but this also fires the
 BoardChanged event since this is the singleton ChessPositionModel which is bound to the View. */
 protected override void updatePosWithPiece(Tuple<int,int> location, Piece newPiece)
 {
     int row = location.Item1;
     int col = location.Item2;
     this.Board[row, col].piece = newPiece;
     // finally fire the BoardChanged event!
     // EventArgs could be the tile coordinates which have changed
     BoardChangedEventArgs e = new BoardChangedEventArgs();
     e.Add(location);
     OnBoardChanged(e);
 }