public void GetCastlingRights_Should_ReturnCorrectValues(string fenString, ChessCastling expectedForWhite, ChessCastling expectedForBlack)
        {
            //	Arrange
            SUT           board;
            ChessCastling actualWhite;
            ChessCastling actualBlack;

            //	Act
            board       = new SUT(fenString);
            actualWhite = board.GetCastlingRights(ChessColor.White);
            actualBlack = board.GetCastlingRights(ChessColor.Black);

            //	Assert
            Assert.AreEqual(expectedForWhite, actualWhite);
            Assert.AreEqual(expectedForBlack, actualBlack);
        }
        public void Constructor_Should_InitializeWithGivenPosition(string expectedFen,
                                                                   string expectedSide,
                                                                   ChessCastling expectedCastlingForWhite,
                                                                   ChessCastling expectedCastlingForBlack)
        {
            //	Arrange
            SUT board = new SUT(expectedFen);

            //	Act
            string fen = board.GetFEN();

            //	Assert
            Assert.AreEqual(expectedFen, fen);
            Assert.AreEqual(expectedSide, board.Turn == ChessColor.White ? "w" : "b");
            Assert.AreEqual(expectedCastlingForWhite, board.GetCastlingRights(ChessColor.White));
            Assert.AreEqual(expectedCastlingForBlack, board.GetCastlingRights(ChessColor.Black));
        }
Esempio n. 3
0
        public void Constructor_Should_Initialize(string rank1, string rank2, string rank3, string rank4, string rank5, string rank6, string rank7, string rank8, string turn, string castling,
                                                  string enpassant, string halfMove, string moves, ChessCastling expectedCastlingForWhite, ChessCastling expectedCastlingForBlack)
        {
            //	Arrange
            SUT fenObj = new SUT($"{rank1}/{rank2}/{rank3}/{rank4}/{rank5}/{rank6}/{rank7}/{rank8} {turn} {castling} {enpassant} {halfMove} {moves}");

            //	Assert
            Assert.AreEqual(rank1.Trim(), fenObj.Ranks[0]);
            Assert.AreEqual(rank2.Trim(), fenObj.Ranks[1]);
            Assert.AreEqual(rank3.Trim(), fenObj.Ranks[2]);
            Assert.AreEqual(rank4.Trim(), fenObj.Ranks[3]);
            Assert.AreEqual(rank5.Trim(), fenObj.Ranks[4]);
            Assert.AreEqual(rank6.Trim(), fenObj.Ranks[5]);
            Assert.AreEqual(rank7.Trim(), fenObj.Ranks[6]);
            Assert.AreEqual(rank8.Trim(), fenObj.Ranks[7]);

            Assert.AreEqual(expectedCastlingForWhite, fenObj.CastlingForWhite);
            Assert.AreEqual(expectedCastlingForBlack, fenObj.CastlingForBlack);
            Assert.AreEqual(enpassant.Trim(), fenObj.EnPassant);
            Assert.AreEqual(int.Parse(halfMove), fenObj.HalfMoveCount);
            Assert.AreEqual(int.Parse(moves), fenObj.MoveCount);
            Assert.AreEqual(turn.Trim() == "w"? ChessColor.White: ChessColor.Black, fenObj.Turn);
        }
Esempio n. 4
0
    // initialize game start state
    public void Init()
    {
        // bit board state init
        pieceBB[WhitePBB] = 0x000000000000FFFF;
        pieceBB[BlackPBB] = 0xFFFF000000000000;
        pieceBB[WhiteKingPBB] = 0x0000000000000010;
        pieceBB[BlackKingPBB] = 0x1000000000000000;
        pieceBB[WhiteQueenPBB] = 0x0000000000000008;
        pieceBB[BlackQueenPBB] = 0x0800000000000000;
        pieceBB[WhiteRookPBB] = 0x0000000000000081;
        pieceBB[BlackRookPBB] = 0x8100000000000000;
        pieceBB[WhiteBishopPBB] = 0x0000000000000024;
        pieceBB[BlackBishopPBB] = 0x2400000000000000;
        pieceBB[WhiteKnightPBB] = 0x0000000000000042;
        pieceBB[BlackKnightPBB] = 0x4200000000000000;
        pieceBB[WhitePawnPBB] = 0x000000000000FF00;
        pieceBB[BlackPawnPBB] = 0x00FF000000000000;

        emptyBB = 0x0000FFFFFFFF0000;
        occupiedBB = 0xFFFF00000000FFFF;

        currEnPassantTrgSq = new ChessEnPassant() {
            enpassantCapturSqBB = 0
        };

        currCastlingState = new ChessCastling() {

            CastlingWKSide = CastlingState.eCastling_Temporary_Disable_State,
            CastlingWQSide = CastlingState.eCastling_Temporary_Disable_State,
            CastlingBKSide = CastlingState.eCastling_Temporary_Disable_State,
            CastlingBQSide = CastlingState.eCastling_Temporary_Disable_State
        };
    }
Esempio n. 5
0
    public void CopyFrom( ChessBitBoard bitBoard )
    {
        for( int i=0; i<NumPieceBB; ++i ) {
            pieceBB[i] = bitBoard.pieceBB[i];
        }

        emptyBB = bitBoard.emptyBB;
        occupiedBB = bitBoard.occupiedBB;

        currCastlingState = bitBoard.currCastlingState;
        currEnPassantTrgSq = bitBoard.currEnPassantTrgSq;
    }
Esempio n. 6
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();
    }