public override int Move(int[] positionXY, bool isActuallyMoving) { int distanceX = Math.Abs(XPosition - positionXY[0]); int distanceY = Math.Abs(YPosition - positionXY[1]); if ((positionXY[0] < 0 || positionXY[0] > 7) || (positionXY[1] < 0 || positionXY[1] > 7)) { return(4); } if ((distanceX != 0 && distanceY != 0) && (distanceX != distanceY)) { return(1); } int validationReturn = 0; if (distanceX == distanceY) { validationReturn = Bishop.PieceInWay(this, positionXY, distanceX, distanceY, true); } else { validationReturn = Rook.ValidRookMove((distanceX == 0) ? distanceY : distanceX, (distanceX == 0) ? positionXY[1] : positionXY[0], (distanceX != 0), this, true); } if (validationReturn == 0) { if (isActuallyMoving) { UpdateBoard(positionXY); } } return(validationReturn); }
public List <string> GetAvailableMoves(bool isQueen) { List <string> availibleMoves = new List <string>(); //int xIter = 0; //int yIter = 0; //for (int x = XPosition; x < 8; x++) //{ // xIter++; // for (int y = YPosition; y < 8; y++) // { // yIter++; // if (xIter == yIter) // { // if () // { // availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ y + 1}"); // } // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x < 8; x++) //{ // xIter++; // for (int y = YPosition; y >= 0; y--) // { // yIter++; // if (xIter == yIter) // { // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x >= 0; x--) //{ // xIter++; // for (int y = YPosition; y < 8; y++) // { // yIter++; // if (xIter == yIter) // { // } // } //} //xIter = 0; //yIter = 0; //for (int x = XPosition; x >= 0; x--) //{ // xIter++; // for (int y = YPosition; y >= 0; y--) // { // yIter++; // if (xIter == yIter) // { // } // } //} for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (Math.Abs(x - XPosition) == Math.Abs(y - YPosition)) { int checkMovement = Move(new int[] { x, y }, false); if (checkMovement == 0 || checkMovement == 6) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ Math.Abs(y - 8) }"); } } } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck && !isQueen) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in availibleMoves) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Bishop((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { availibleMoves.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!availibleMoves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(availibleMoves); }
public override List <string> GetAvailableMoves() { Rook tempRook = new Rook(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition); List <string> rookMoves = tempRook.GetAvailableMoves(true); Bishop tempBishop = new Bishop(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition); List <string> bishopMoves = tempBishop.GetAvailableMoves(true); List <string> moves = new List <string>(); foreach (string move in rookMoves) { moves.Add(move); } foreach (string move in bishopMoves) { if (!moves.Contains(move)) { moves.Add(move); } } bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1; if (inCheck) { List <string> remove = new List <string>(); int xPos = XPosition; int yPos = YPosition; foreach (string move in moves) { Piece tempPiece = ChessController.Board.GetPieceAt(move); Piece currentPieceClone = new Queen((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos); //BUG: Pawn promotes if can block or take to last row XPosition = xPos; YPosition = yPos; Move(ChessController.ConvertToXY(move), true); int[] isKingInCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite); if (isKingInCheck[2] == 1) { remove.Add(move); } ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone; ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece; } foreach (string move in remove) { moves.Remove(move); } XPosition = xPos; YPosition = yPos; } if (!moves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }")) { moves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"); } return(moves); }