C# chess castle check test in INT using unity

Functionally everything works on the chess board except the chess check during castle tester in the vector. It is like it doesn’t write the rule into pseudoLegalMove. Can a vector work for this type of thing? I am new C# and i’m learning and have spent days trying to fix this problem. My thoughts are I need to instead do this check in a bool or something so it writes the illegal move into pseudoLegalMove. Also everything else is working correctly…like enpassant, doublepawnpush ect. Any help from someone who has coded a chess board would be fantastic!

This is where i think the problem is..

 /// <param name="movedPiece"></param>
 /// <param name="board"></param>
 /// <returns></returns>
 public Vector2[] GetAllLegalMoves(Piece movedPiece, Board board)  //STACK OVERFLOW this is where i think the problem is?
 {
     Vector2[] pseudoLegalMoves = GetAllPseudoLegalMoves(movedPiece, board);
     Vector2 piecePos = movedPiece.GetVec();
     Piece king = movedPiece.white ? board.whiteKing : board.blackKing;
     if (king != null)
     {
         Piece[] currentGrid = board.grid;         //gets board grid
         Piece[] testGrid = new Piece[currentGrid.Length];   //gets king piece
         Vector2 kingPos = king.GetVec();               // gets king piece
         for (int i = 0; i < pseudoLegalMoves.Length; i++) 
         {
             Vector2 pseudoLegalMove = pseudoLegalMoves[i];        //its like this doesn't write the illegal king move into the rules here or something


             if (pseudoLegalMove == legalMovesEndMarker) { break; }
             else
             {

                 Array.Copy(currentGrid, testGrid, currentGrid.Length);

                 board.MoveGridPieceVec(piecePos, pseudoLegalMove, testGrid);
                 Piece PawnThatDidADoublePush = null;
                 if (movedPiece.type == "pawn" && (Mathf.Abs(movedPiece.x - (int)pseudoLegalMove.x) > 1))
                 {
                     PawnThatDidADoublePush = movedPiece;
                 }
                 Vector2 threatenedPos = movedPiece.type != "king" ? kingPos : pseudoLegalMove;
                 if (isKingInCheck(threatenedPos, testGrid, board, PawnThatDidADoublePush, movedPiece.white)) { pseudoLegalMoves[i] = legalMovesIgnoreMarker; }
                

             }
         }

     }
     return pseudoLegalMoves;

 }
 // if (!isKingInCheck(threatenedPos.x, threatenedPos.y, opponentPiece.type, opponentPiece.x, opponentPseudoLegalMove.x, opponentPseudoLegalMove.y, movedPiece.white))

this is where it checks pseudolegalmove is checked to allow the castle to happen

        public int MoveLegalCheck(Piece movedPiece, int x, int y, Board board, Vector2[] legalMoves)
        {
            int result = 0;
            Piece targetPiece = board.GetPiece(x, y);
            Vector2 move = new Vector2(x, y);
            bool legal = false;
            foreach (Vector2 legalMove in legalMoves)
            {
                if (legalMove != legalMovesIgnoreMarker)
                {
                    if (legalMove == legalMovesEndMarker) break;
                    if (move == legalMove) { legal = true; break; }
                }
            }
            if (legal)
            {
                if (targetPiece != null) { targetPiece._Capture(); result = 2; } else { result = 1; }

                if (movedPiece.type == "pawn" && movedPiece.x != x && board.GetPiece(x, y) == null)//EN PASSANT
                {
                    board.PawnThatDidADoublePushLastRound._Capture();
                    result = 2;
                }

                                if (movedPiece.type == "king" && Mathf.Abs(x - movedPiece.x) == 2) //CASTLING
                                {
                                    int dir = Mathf.Min(x, movedPiece.x) == x ? -1 : 1;
                                    Piece rookCastle = dir == 1 ? board.GetPiece(7, y) : board.GetPiece(0, y);
                                    rookCastle._SetPosition(x + (dir * -1), y);

                                }

                if (movedPiece.type == "pawn" && Mathf.Abs(y - movedPiece.y) == 2)
                {
                    board.PawnThatDidADoublePushLastRound = movedPiece; //NOTICE, to have it be synced I also do the same check in the Piece refresh function (won't be synced for those who join right after this move, but it's fine)
                }
                else
                {
                    board.PawnThatDidADoublePushLastRound = null;
                }
                movedPiece.hasMoved = true;
                movedPiece._SetPosition(x, y);

                return result;
            }
            else
            {
                movedPiece._SetPosition(movedPiece.x, movedPiece.y);
                return 0;
            }
        }

i can post more if needed..didnt want to spam or something….the whole board is like 6 scripts so

chessboard problem

I’ve tried multiple changes little changes…adding if then infront of the castle command just no luck. i dont know a lot about int and vectors…but something tells me i need to do the castle check in a bool in order to write into the pseudolegal moves….or am i wrong….any guidance in the right direction would help 100% and thanks in advance!

New contributor

CharlesRyann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật