Example #1
0
 public void SetPiecesDefaultState()
 {
     if (Pieces.FirstOrDefault().Color == Color.White)
     {
         Pieces.Clear();
         Pieces.Add(new Piece(new Point(1, 5), Color.White));
         Pieces.Add(new Piece(new Point(3, 5), Color.White));
         Pieces.Add(new Piece(new Point(5, 5), Color.White));
         Pieces.Add(new Piece(new Point(7, 5), Color.White));
         Pieces.Add(new Piece(new Point(0, 6), Color.White));
         Pieces.Add(new Piece(new Point(2, 6), Color.White));
         Pieces.Add(new Piece(new Point(4, 6), Color.White));
         Pieces.Add(new Piece(new Point(6, 6), Color.White));
         Pieces.Add(new Piece(new Point(1, 7), Color.White));
         Pieces.Add(new Piece(new Point(3, 7), Color.White));
         Pieces.Add(new Piece(new Point(5, 7), Color.White));
         Pieces.Add(new Piece(new Point(7, 7), Color.White));
     }
     else
     {
         Pieces.Clear();
         Pieces.Add(new Piece(new Point(0, 0), Color.Blue));
         Pieces.Add(new Piece(new Point(2, 0), Color.Blue));
         Pieces.Add(new Piece(new Point(4, 0), Color.Blue));
         Pieces.Add(new Piece(new Point(6, 0), Color.Blue));
         Pieces.Add(new Piece(new Point(1, 1), Color.Blue));
         Pieces.Add(new Piece(new Point(3, 1), Color.Blue));
         Pieces.Add(new Piece(new Point(5, 1), Color.Blue));
         Pieces.Add(new Piece(new Point(7, 1), Color.Blue));
         Pieces.Add(new Piece(new Point(0, 2), Color.Blue));
         Pieces.Add(new Piece(new Point(2, 2), Color.Blue));
         Pieces.Add(new Piece(new Point(4, 2), Color.Blue));
         Pieces.Add(new Piece(new Point(6, 2), Color.Blue));
     }
 }
        /// <summary>
        /// Removes piece on the specified position (if possible).
        /// </summary>
        /// <param name="position">The piece position.</param>
        public void RemovePiece(Position position)
        {
            var existingPiece = Pieces.FirstOrDefault(p => p.Position == position);

            if (existingPiece != null)
            {
                Pieces.Remove(existingPiece);
            }
        }
        public override bool IsMoveAllowed()
        {
            if (!IsNotOccupied() && Pieces.FirstOrDefault() is BarricadePiece)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        internal void MovePiece(Piece pieceToMove, BoardPosition pos)
        {
            var piece = Pieces.FirstOrDefault(p => p.Position == pos);

            if (piece != null)
            {
                // There is a piece, we take it making sure that a piece does not take one of the same side is the pieces responsibility
                Remove(piece);
            }

            // Now the square is empty (if it was not already, so move the piece there)
            pieceToMove.Position = pos;
        }
Example #5
0
        public void Move(string pieceToMove, string locationToMove)
        {
            try
            {
                var piece = Pieces.FirstOrDefault(p => p.Id == pieceToMove);

                if (!(piece.GetType() == typeof(Pieces.Knight)))
                {
                    leaps.CheckForPiecesBetween(pieceToMove, locationToMove);
                }

                piece.Move(board.Squares[locationToMove]);
            }
            catch (NullReferenceException)
            {
                throw new InvalidMoveException($"Player does not have a piece on {locationToMove}");
            }
        }
 /// <summary>
 /// Gets a piece on the specified position.
 /// </summary>
 /// <param name="position">The piece position.</param>
 /// <returns>The piece on the specified position (or null if field is empty).</returns>
 public FriendlyPiece GetPiece(Position position)
 {
     return(Pieces.FirstOrDefault(p => p.Position == position));
 }
Example #7
0
 public ISquarePiece GetPiece(int x, int y)
 {
     return(Pieces.FirstOrDefault(p => p.Position.x == x && p.Position.y == y));
 }
Example #8
0
 public ChessPiece GetPiece(int rank, int file)
 => Pieces.FirstOrDefault(p => p.Rank == rank && p.File == file);
Example #9
0
 /// <summary>
 /// Returns a piece of the board
 /// </summary>
 /// <param name="_col">Column of the coordinate</param>
 /// <param name="_row">Row of the coordinate</param>
 /// <returns></returns>
 public Piece SearchPieces(int _col, int _row)
 {
     Classes.Pieces.Piece currentPrice = Pieces.FirstOrDefault(x => x.Coordinates.Row == _row && x.Coordinates.Column == _col);
     return(currentPrice);
 }
Example #10
0
 public Piece GetPiece(int rowNumber, int columnNumber)
 {
     return(Pieces.FirstOrDefault(p => p.RowNumber == rowNumber && p.ColumnNumber == columnNumber));
 }
Example #11
0
 public ChessPieceViewModel GetRemovedPiece(Coordinate coordinate)
 {
     return(Pieces.FirstOrDefault(p => p.RemovePending && p.Coordinate.X == coordinate.X && p.Coordinate.Y == coordinate.Y));
 }
Example #12
0
 public Piece GetPiece(BoardPosition pos) => Pieces.FirstOrDefault(p => p.Position == pos);
Example #13
0
 public Piece GetKing(PlayerColor color)
 {
     return(Pieces.FirstOrDefault(p => p is King && p.Color == color) as King);
 }
Example #14
0
 public Piece CollisionDetection(Piece pieceToMove) => Pieces.FirstOrDefault(p => p.Equals(pieceToMove) && p != pieceToMove && !p.Completed);