Exemplo n.º 1
0
    private bool IsItCheckmate(ChessSet enemySet, ChessPiece enemyKing)
    {
        if (enemySet.CheckIfAnyOfMyPiecesCanProtectKing())
        {
            return(false);
        }
        else if (enemyKing.GetPotentialMoves().Count == 0)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 2
0
    private void CheckGameState()
    {
        if (hasGameEnded)
        {
            return;
        }

        ChessSet   enemySet      = activePiece.GetMyChessSet().GetMyEnemyChessSet();
        ChessPiece enemyKing     = enemySet.GetPieceByTag("King");
        string     enemyColorTag = enemySet.GetColorTag();
        string     myColorTag    = activePiece.GetMyColorTag();
        //if(activePiece.GetMyChessSet().GetMyPlayer().tag == "Lost")
        //{
        //    hasGameEnded = true;
        //    Debug.Log($"Game over: {myColorTag} colored player flagged! {enemyColorTag} colored player won!");
        //}
        bool isCheck     = IsItCheck();
        bool isCheckmate = IsItCheckmate(enemySet, enemyKing);
        bool isRemi      = IsItRemi();
        bool isCheckFunctionArgument;
        bool isCheckmateFunctionArgument;

        if (isCheck && isCheckmate)
        {
            isCheckFunctionArgument = false;
        }
        else if (isCheck && !isCheckmate)
        {
            isCheckFunctionArgument = true;
        }
        else
        {
            isCheckFunctionArgument = false;
        }

        if (isCheck)
        {
            isCheckmateFunctionArgument = isCheckmate;
        }
        else
        {
            isCheckmateFunctionArgument = false;
        }

        hasGameEnded = false;
        if (isCheck)
        {
            Debug.Log($"Check => Attacker: {myColorTag} - Defender: {enemyColorTag}");

            if (isCheckmate)
            {
                Debug.Log($"CHECKMATE!!! => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                hasGameEnded = true;
                activePiece.GetMyChessSet().GetMyPlayer().SetMyState("Won");
                activePiece.GetMyChessSet().GetMyEnemyChessSet().GetMyPlayer().SetMyState("Lost");
                terminationString = "won by checkmate";
            }
            else
            {
                if (enemySet.CountPiecesThatAreAttackingEnemyKing() > 1)
                {
                    Debug.Log($"BLOCK ALL PIECES EXCEPT A KING! counter > 1 => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
                else if (enemySet.CheckIfAnyOfMyPiecesCanProtectKing())
                {
                    Debug.Log($"My King can be protected! counter == 1 ...BLOCK ALL PIECES THAT CANNOT PROTECT THE KING! => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
                else
                {
                    Debug.Log($"BLOCK ALL PIECES EXCEPT A KING! counter == 1 => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
            }
        }
        else if (isRemi)
        {
            Debug.Log($"REMI => Attacker: {myColorTag} - Defender: {enemyColorTag}");
            hasGameEnded = true;
            activePiece.GetMyChessSet().GetMyPlayer().SetMyState("Remi");
            activePiece.GetMyChessSet().GetMyEnemyChessSet().GetMyPlayer().SetMyState("Remi");
        }

        string winner = (hasGameEnded) ? ((isRemi) ? "None" : myColorTag) : "None";

        int gameRound = (myColorTag == "Dark") ? currentRound - 1 : currentRound;

        myScoreSheet.SetNewMove(activePiece.GetMyInitialTag(), activePiece.tag, activePiece.GetPreviousSquare().GetSquarePositionCode(),
                                activePiece.GetCurrentSquare().GetSquarePositionCode(), gameRound, isCheckFunctionArgument, isCheckmateFunctionArgument, activePiece.GetCastling("Kingside"),
                                activePiece.GetCastling("Queenside"), activePiece.DidICaptureEnemyPiece(), activePiece.HaveIJustBeenPromoted(), winner, isRemi, hasGameEnded, false, false);
    }