Пример #1
0
        public void Remove(Piece piece)
        {
            _pieces.Remove(piece);
            WhitePieces.Remove(piece);
            BlackPieces.Remove(piece);

            OnPropertyChanged("Pieces");
            OnPropertyChanged("WhitePieces");
            OnPropertyChanged("BlackPieces");
        }
Пример #2
0
 public void RemovePieceAt(Position position)
 {
     foreach (Piece piece in WhitePieces)
     {
         if (piece.Position == position)
         {
             WhitePieces.Remove(piece);
             return;
         }
     }
     foreach (Piece piece in BlackPieces)
     {
         if (piece.Position == position)
         {
             BlackPieces.Remove(piece);
             return;
         }
     }
 }
Пример #3
0
        //
        // Summary:
        //     Make the move, this also includes catching a possible piece in the process.
        //
        // Parameters:
        //   origin:
        //     The piece that will make its move.
        //
        //   target:
        //     The position of the final destination of the Piece origin.
        public void MakeMovement(Piece origin, BoardPosition target)
        {
            TwoDimensionsArrayPosition originArrPos = origin.BoardPosition.ToArrayPosition(Board.Height);
            TwoDimensionsArrayPosition targetArrPos = target.ToArrayPosition(Board.Height);

            // If the target results in a capture
            if (Math.Abs(originArrPos.Row - targetArrPos.Row) >= 2)
            {
                // The 'P' represents a piece, not a Pawn itself or a Dame, and the 'E' an enemy piece.
                //
                // 4---1
                // -E-E-
                // --P--
                // -E-E-
                // 3---2

                TwoDimensionsArrayPosition piece2BCapPos;
                // Locate and set the position of the piece to be captured
                if ((originArrPos.Column - targetArrPos.Column) <= -2) // NE && SE
                {
                    if ((originArrPos.Row - targetArrPos.Row) >= 2)    // NE (1)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row + 1, targetArrPos.Column - 1);
                    }
                    else // SE (2)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row - 1, targetArrPos.Column - 1);
                    }
                }
                else // SW && NW
                {
                    if ((originArrPos.Row - targetArrPos.Row) <= -2) // SW (3)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row - 1, targetArrPos.Column + 1);
                    }
                    else // NW (4)
                    {
                        piece2BCapPos = new TwoDimensionsArrayPosition(targetArrPos.Row + 1, targetArrPos.Column + 1);
                    }
                }


                if (TurnPlayer == Team.Red)
                {
                    WhitePieces.Remove(Board.TakePiece(piece2BCapPos));
                }
                else
                {
                    RedPieces.Remove(Board.TakePiece(piece2BCapPos));
                }

                // Take the origin from the board and place it in the target
                Board.PlacePiece(Board.TakePiece(origin.BoardPosition), target);
            }
            else
            {
                // Take the origin from the board and place it in the target
                Board.PlacePiece(Board.TakePiece(origin.BoardPosition), target);
            }

            // If the Red pawn or a White pawn is in its promotion area it'll be promoted
            switch (Board.Pieces(target))
            {
            case Pawn _ when Board.Pieces(target).Team == Team.Red && target.Row == 1:
            case Pawn _ when Board.Pieces(target).Team == Team.White && target.Row == 10:
                Promotion(Board.Pieces(target) as Pawn);

                break;
            }
        }