public void MovePiece(ChessPiece[,] board, int[] start, int[] end) { board[end[0], end[1]] = board[start[0], start[1]]; board[start[0], start[1]] = new Space(); }
/// <summary> /// Moves a King left/right 2 squares, while moving a Rook to the right/left of the King. /// Describes the actions of king-side-castle. /// Print out where the pieces moved too, in plain english. /// </summary> /// <param name="square1">The starting point of the king</param> /// <param name="square2">The end point for the king.</param> /// <param name="square3">The starting point of the Rook.</param> /// <param name="square4">The end point for the Rook.</param> public void KingSideCastle(string square1, string square2, string square3, string square4) { startMove = GrabPiece(square1[0], square1[1]); endMove = GrabPiece(square2[0], square2[1]); Board[endMove[0], endMove[1]] = Board[startMove[0], startMove[1]]; Board[startMove[0], startMove[1]] = new Space(); startMove = GrabPiece(square3[0], square3[1]); endMove = GrabPiece(square4[0], square4[1]); Board[endMove[0], endMove[1]] = Board[startMove[0], startMove[1]]; Board[startMove[0], startMove[1]] = new Space(); Console.WriteLine("King has moved from " + square1 + " to " + square2 + ", rook moved from " + square3 + " to " + square4 + "."); }
/// <summary> /// Creates a board of empty board squares and pieces to there rightful location and color. /// </summary> public void SetBoard() { //Sets Black & White Pieces Board[0, 4] = new King('d');//Kings Board[7, 4] = new King('l');//Kings Board[0, 3] = new Queen('d');//Queens Board[7, 3] = new Queen('l');//Queens for (int x = 2; x < 6; x+=3) { Board[0, x] = new Bishop('d');//Black Bishops Board[7, x] = new Bishop('l');//White Bishops } for (int x = 1; x < 7; x+=5) { Board[0, x] = new Knight('d');//Black Knight Board[7, x] = new Knight('l');//White Knight } for (int x = 0; x < 9; x+=7) { Board[0, x] = new Rook('d');//Black Rooks Board[7, x] = new Rook('l');//White Rooks } for (int x = 0; x < 8; x++) { Board[1, x] = new Pawn('d');//Black Pawns Board[6, x] = new Pawn('l');//White Pawns } //Empty squares for (int x = 0; x < 8; ++x) { for (int y = 0; y < 8; y++) { if (Board[x, y] == null) { Board[x, y] = new Space(); } } } }
/// <summary> /// Moves a piece from it's start location to the desired location and captures /// the piece. /// Prints out where the piece moved too, in plain english. /// </summary> /// <param name="square1">The starting point of the piece.</param> /// <param name="square2">The end point for the piece.</param> public void CapturePiece(string square1, string square2) { startMove = GrabPiece(square1[0], square1[1]); endMove = GrabPiece(square2[0], square2[1]); Board[endMove[0], endMove[1]] = Board[startMove[0], startMove[1]]; Board[startMove[0], startMove[1]] = new Space(); Console.WriteLine("The piece at " + square1 + " captured the piece at and moved to " + square2 + "."); }