public bool IsPawn(PieceBase piece) { if (piece != null) { return(piece.GetType() == typeof(Pawn)); } return(false); }
// pone un flag en el peon para avisar que puede ser comido y anota el turno public void UpDateEnPassant(int y1, int y2, PieceBase piece, Board board) { if (piece.GetType() == typeof(Pawn) && Math.Abs(y2 - y1) == 2) { piece.EnPassantAllowed = true; piece.EnPassantTurnNumber = board.TurnNumber; } }
//imposibilita enrocar, una vez que se mueve el rey o las torres public void CastlingChanges(int x1, int y1, int x2, int y2, PieceBase piece) { if (piece.GetType() == typeof(King) && piece.CanCastling) { piece.CanCastling = false; } if (piece.GetType() == typeof(Rook) && x1 == 0 && y1 == 0) { Board.P1LRookCanCastling = false; } if (piece.GetType() == typeof(Rook) && x1 == 7 && y1 == 0) { Board.P1RRookCanCastling = false; } if (piece.GetType() == typeof(Rook) && x1 == 0 && y1 == 7) { Board.P2LRookCanCastling = false; } if (piece.GetType() == typeof(Rook) && x1 == 7 && y1 == 7) { Board.P2RRookCanCastling = false; } }
/// <summary> /// Guarda en una lista las jugadas, pero lo tengo que rever /// </summary> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <param name="piece1"></param> /// <param name="player1"></param> public void WriteMove(int x1, int y1, int x2, int y2, PieceBase piece1, bool player1, Board board) { if (player1 == board.Turn) // para escribir el numero de la jugada { movement = movement.Insert(pointer, "."); movement = movement.Insert(pointer, board.FullMoveNumber.ToString()); pointer += board.FullMoveNumber.ToString().Length + 1; } movement = movement.Insert(pointer++, " "); if (piece1.GetType() == typeof(Pawn) && IsPawnCapturing(x1, x2)) //peon comiendo { movement = movement.Insert(pointer++, columnLetters[x1]); } movement = movement.Insert(pointer++, " "); if (piece1.GetType() == typeof(Bishop)) { movement = movement.Insert(pointer++, "B"); } if (piece1.GetType() == typeof(Knight)) { movement = movement.Insert(pointer++, "N"); } if (piece1.GetType() == typeof(Queen)) { movement = movement.Insert(pointer++, "Q"); } if (piece1.GetType() == typeof(Rook)) { movement = movement.Insert(pointer++, "R"); } if (piece1.GetType() == typeof(King)) { if (piece1.ShortCastling) { movement = movement.Insert(pointer, "0-0"); pointer += 3; return; } if (piece1.ShortCastling) { movement = movement.Insert(pointer, "0-0-0"); pointer += 5; return; } movement = movement.Insert(pointer++, "K"); } movement = movement.Insert(pointer++, columnLetters[x2]); movement = movement.Insert(pointer++, (y2).ToString()); if (player1 != board.Turn) // guarda la jugada completa { stackFullPlay.Push(movement); pointer = 0; //Console.WriteLine("--------- Esta fue la jugada: " + movement); movement = ""; } }
public void UndoRookCastling(int x1, int y1, int x2, Board board) { PieceBase piece = board.GetPiece(x1, y1); if (piece != null && piece.GetType() == typeof(King) && Math.Abs(x2 - x1) == 2) { if (x1 > x2) { board.Move(x2 + 1, y1, 0, y1); } if (x1 < x2) { board.Move(x2 - 1, y1, 7, y1); } } }
public bool LogicMove(int x1, int y1, int x2, int y2, Board board) { if (IsInRange(x1, y1, x2, y2)) { PieceBase piece = board.GetPiece(x1, y1); if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board)) { //es Knight if (piece.GetType() == typeof(Knight)) { if (board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); return(true); } if (!board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); return(true); } } else //no es Knight { if (board.IsEmpty(x2, y2) && !IsCastling(x1, y1, x2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board) && !board.IsPawn(x1, y1)) { if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && IsDiagonalEmpty(x1, y1, x2, y2, board)) || IsLineEmpty(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); CastlingChanges(x1, y1, x2, y2, piece); return(true); } } if (!board.IsEmpty(x2, y2) && !IsAlly(x1, y1, x2, y2, board) && !IsCastling(x1, y1, x2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board) && !board.IsPawn(x1, y1)) { if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && IsDiagonalEmpty(x1, y1, x2, y2, board)) || IsLineEmpty(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); CastlingChanges(x1, y1, x2, y2, piece); return(true); } } if (board.IsEmpty(x2, y2) && IsCastling(x1, y1, x2, board) && CanCastling(x1, y1, x2, board)) { board.Move(x1, y1, x2, y2); piece.CanCastling = false; MoveRookCastling(x1, y1, x2, board); return(true); } if (IsPawn(piece) && IsPawnCapturing(x1, x2) && !board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); if (Promoting(y2)) { board.Promotion(x2, y2, board.Turn); } return(true); } if (IsPawn(piece) && IsPawnCapturing(x1, x2) && EnPassant(x1, y1, x2, y2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.RemoveCapturePassant(x1, y1, x2, y2); board.Move(x1, y1, x2, y2); return(true); } if (IsPawn(piece) && !IsPawnCapturing(x1, x2) && board.IsEmpty(x2, y2) && IsLineEmpty(x1, y1, x2, y2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); UpDateEnPassant(y1, y2, piece, board); if (Promoting(y2)) { board.Promotion(x2, y2, board.Turn); } return(true); } } } } return(false); }