Beispiel #1
0
    public List <Vector2> CheckLegalMoves(Board boardClone, List <Vector2> currentLegalMoves)
    {
        List <Vector2> newLegalMoves   = new List <Vector2>();
        Board          boardCopy       = DeepCopy.Copy(boardClone);
        bool           wasBlackinCheck = KingInCheck.IsBlackInCheck();
        bool           wasWhiteinCheck = KingInCheck.IsWhiteInCheck();


        int   selectedPiece = boardClone.GetActivePieces().IndexOf(this);
        Piece selectedCopy  = boardCopy.GetActivePieces()[selectedPiece];


        Debug.Log("Current legal moves are: ");
        foreach (Vector2 move in currentLegalMoves)
        {
            //When checkMove is false, the current teams king is not in check and the move is valid
            if (selectedCopy.CheckMove(boardCopy, move) == false)
            {
                newLegalMoves.Add(move);
            }
        }

        KingInCheck.SetBlackCheck(wasBlackinCheck);
        KingInCheck.SetWhiteCheck(wasWhiteinCheck);


        return(newLegalMoves);
    }
Beispiel #2
0
    public void UpdateBoardThreat(Piece testPiece, Vector2 testMove)
    {
        List <Piece> activePieces = new List <Piece>();

        activePieces.AddRange(GetActivePieces());
        Vector2 originalPosition = Vector2.down;
        Piece   tempRemovedPiece = new Piece();


        if (testPiece != null)
        {
            originalPosition = testPiece.GetPiecePosition();


            if (IsOccupied(testMove))
            {
                tempRemovedPiece = GetPieceAt(testMove);
                activePieces.Remove(tempRemovedPiece);
            }

            testPiece.SetPosition(testMove);
            Mark(testMove, testPiece);
            UnMark(originalPosition);
        }

        for (int row = BoardConstants.BOARD_MINIMUM; row <= BoardConstants.BOARD_MAXIMUM; row++)
        {
            for (int column = BoardConstants.BOARD_MINIMUM; column <= BoardConstants.BOARD_MAXIMUM; column++)
            {
                GetSquare(row, column).setBlackThreat(false);
                GetSquare(row, column).setWhiteThreat(false);
            }
        }

        KingInCheck.SetBlackCheck(false);
        KingInCheck.SetWhiteCheck(false);

        foreach (Piece inPlay in activePieces)
        {
            foreach (Vector2 moves in inPlay.LegalMoves(this))
            {
                if (inPlay.GetTeam() == Teams.BLACK_TEAM)
                {
                    squares[(int)moves.x, (int)moves.y].setBlackThreat(true);
                    //GetSquare(moves).setBlackThreat(true);
                    if (GetSquare(moves).isSquareOccupied())
                    {
                        if (GetSquare(moves).GetPiece().GetType() == typeof(King) && (GetSquare(moves).getBlackThreat() == true))
                        {
                            KingInCheck.SetWhiteCheck(true);
                        }
                    }
                }
                else
                {
                    squares[(int)moves.x, (int)moves.y].setWhiteThreat(true);
                    //GetSquare(moves).setWhiteThreat(true);
                    if (GetSquare(moves).isSquareOccupied())
                    {
                        if (GetSquare(moves).GetPiece().GetType() == typeof(King) && (GetSquare(moves).getWhiteThreat() == true))
                        {
                            KingInCheck.SetBlackCheck(true);
                        }
                    }
                }
            }
        }
        if (testPiece != null)
        {
            testPiece.SetPosition(originalPosition);
            UnMark(testMove);
            Mark(originalPosition, testPiece);
            if (IsOccupied((int)testMove.x, (int)testMove.y))
            {
                activePieces.Add(tempRemovedPiece);
            }
        }
    }