示例#1
0
    // AI Move
    public bool AIMoveTo( ChessBoardSquare srcSquare, ChessBoardSquare trgSquare )
    {
        if( CurrTurn != UserPlayerSide ) {

            //UnityEngine.Debug.LogError( "AIMoveTo() - current turn = " + CurrTurn );
            if( srcSquare.IsBlank() == false ) {

                UnityEngine.Debug.LogError( "AIMoveTo() - no blank" );

                List<ChessMoveManager.sMove> listAiMovable = new List<ChessMoveManager.sMove>();
                bool bMoveList = ChessMoveManager.GetValidateMoveList( this, srcSquare, listAiMovable );
                if( bMoveList ) {
                    //UnityEngine.Debug.LogError( "AIMoveTo() - no blank" + " " + bMoveList );
                    ChessMoveManager.sMove aIMove = new ChessMoveManager.sMove();
                    if( IsValidAIMove( trgSquare, listAiMovable, aIMove ) ) {

                        //UnityEngine.Debug.LogError( "AIMoveTo() - IsValidAIMove()" );

                        UpdateMove( aIMove );

                        return true;
                    }
                }
            }
        }

        UnityEngine.Debug.LogError( "AIMoveTo() - !!!!" );

        return false;
    }
示例#2
0
    // interface
    public void Init( BattleChessMain chessMain, Transform[] aPieceRef, ParticleSystem selectPSystemRef, ParticleSystem movablePSystemRef )
    {
        // etc property
        CurrTurn = PlayerSide.e_White;
        UserPlayerSide = PlayerSide.e_White;
        ThinkingTime = 18000;
        nCurrHalfMove = 0;
        nCurrTotalMove = 0;

        Ready = false;

        // move
        currMove = new ChessMoveManager.sMove();
        currCastlingState = new ChessCastling() {

            CastlingWKSide = CastlingState.eCastling_Enable_State,
            CastlingWQSide = CastlingState.eCastling_Enable_State,
            CastlingBKSide = CastlingState.eCastling_Enable_State,
            CastlingBQSide = CastlingState.eCastling_Enable_State
        };

        listCurrMovable = new List<ChessMoveManager.sMove>();

        // init board
        // piece list
        listPiece = new List<ChessPiece>();
        aBoardSquare = new ChessBoardSquare[ChessData.nNumPile,ChessData.nNumRank];

        ChessPiece currPiece = null;
        for( int i=0; i<ChessData.nNumPile; i++ ){
            for( int j=0; j<ChessData.nNumRank; j++ ){

                // movable square effect Particle System
                ParticleSystem movablePiecePSystem = MonoBehaviour.Instantiate( movablePSystemRef, Vector3.zero, Quaternion.identity ) as ParticleSystem;

                if( ChessData.aStartPiecePos[i,j] == PiecePlayerType.eNone_Piece ) {

                    aBoardSquare[i,j] = new ChessBoardSquare( null, movablePiecePSystem, i, j );
                }
                else
                {
                    Vector3 currPos = new Vector3( j - 3.5f, 0.0f, i - 3.5f );

                    Transform currTransform = aPieceRef[(int)ChessData.aStartPiecePos[i,j]];
                    Transform currPieceObject = MonoBehaviour.Instantiate( currTransform, currPos, currTransform.rotation ) as Transform;

                    if( i == 0 || i == 1 ) {

                        currPiece = new ChessPiece( currPieceObject.gameObject, PlayerSide.e_White,	ChessData.aStartPiecePos[i,j] );
                        listPiece.Add( currPiece );

                        aBoardSquare[i,j] = new ChessBoardSquare( currPiece, movablePiecePSystem, i, j );
                    }
                    else if( i == 6 || i == 7 ) {

                        currPiece = new ChessPiece( currPieceObject.gameObject, PlayerSide.e_Black,	ChessData.aStartPiecePos[i,j] );
                        listPiece.Add( currPiece );

                        aBoardSquare[i,j] = new ChessBoardSquare( currPiece, movablePiecePSystem, i, j );
                    }
                }
            }
        }

        // piece coloar
        SetWhiteSidePieceColor( Color.white );
        SetBlackSidePieceColor( Color.white );

        // board material
        if( chessMain.renderer.materials.Length == 2 ) {

            matBoard1 = chessMain.renderer.materials[0];
            matBoard2 = chessMain.renderer.materials[1];

            Color rgbaWhiteBoard, rgbaBlackBoard;
            rgbaWhiteBoard = new Color( 1.0f, 1.0f, 1.0f, 1.0f );
            rgbaBlackBoard = new Color( 0.039f, 0.34f, 0.22f, 1.0f );

            SetWhiteSideBoardColor( rgbaWhiteBoard );
            SetBlackSideBoardColor( rgbaBlackBoard );
        }

        // particle effect
        selectSquare = null;
        selectPiecePSystem = MonoBehaviour.Instantiate( selectPSystemRef, Vector3.zero, Quaternion.identity ) as ParticleSystem;
        selectPiecePSystem.Stop();
    }