Example #1
0
    void OnMove(ushort move)
    {
        int moveToIndex       = (move >> 7) & 127;
        int capturedPieceCode = Board.boardArray [moveToIndex];         // get capture piece code

        if (capturedPieceCode == 0)
        {
            AudioSource.PlayClipAtPoint(moveAudio, Vector3.zero, 1f);
        }
        else
        {
            AudioSource.PlayClipAtPoint(captureAudio, Vector3.zero, 1f);
        }

        Board.MakeMove(move, true);

        if (OnMoveMade != null)
        {
            OnMoveMade(whiteToPlay, move);
        }

        whiteToPlay = !whiteToPlay;

        // detect mate/stalemate
        if (moveGenerator.PositionIsMate())
        {
            GameOver(((whiteToPlay) ? -1 : 1), Definitions.ResultType.Checkmate);              // player is mated
        }
        else if (moveGenerator.PositionIsStaleMate())
        {
            GameOver(0, Definitions.ResultType.Stalemate);              // player is mated
        }
        else if (moveGenerator.InsuffientMatingMaterial())
        {
            GameOver(0, Definitions.ResultType.InsufficientMaterial);
        }
        else
        {
            if (whitePlayerType == PlayerType.AI && blackPlayerType == PlayerType.AI)
            {
                StartCoroutine(RequestMoveCoroutine(.15f));                   // force delay between moves when two AI are playing
            }
            else
            {
                RequestMove();
            }
        }
    }