Exemplo n.º 1
0
        //unused now because there is a running total of totalWorth
        public int getTotalWorth()
        {
            //Player has negative score. Is there any point including the kings here? They will always cancel
            return(BitOps.BitCountWegner(BP) * Constants.VALUE_PAWN +
                   BitOps.BitCountWegner(BN) * Constants.VALUE_KNIGHT +
                   BitOps.BitCountWegner(BB) * Constants.VALUE_BISHOP +
                   BitOps.BitCountWegner(BR) * Constants.VALUE_ROOK +
                   BitOps.BitCountWegner(BQ) * Constants.VALUE_QUEEN +
                   BitOps.BitCountWegner(BK) * Constants.VALUE_KING -

                   BitOps.BitCountWegner(WP) * Constants.VALUE_PAWN -
                   BitOps.BitCountWegner(WN) * Constants.VALUE_KNIGHT -
                   BitOps.BitCountWegner(WB) * Constants.VALUE_BISHOP -
                   BitOps.BitCountWegner(WR) * Constants.VALUE_ROOK -
                   BitOps.BitCountWegner(WQ) * Constants.VALUE_QUEEN -
                   BitOps.BitCountWegner(WK) * Constants.VALUE_KING);
        }
Exemplo n.º 2
0
        public static void initmagicmoves()
        {
            int i;

            //for bitscans :
            //initmagicmoves_bitpos64_database[(x*0x07EDD5E59A4E28C2UL)>>58]
            int[] initmagicmoves_bitpos64_database = new int[64] {
                63, 0, 58, 1, 59, 47, 53, 2,
                60, 39, 48, 27, 54, 33, 42, 3,
                61, 51, 37, 40, 49, 18, 28, 20,
                55, 30, 34, 11, 43, 14, 22, 4,
                62, 57, 46, 52, 38, 26, 32, 41,
                50, 36, 17, 19, 29, 10, 13, 21,
                56, 45, 25, 31, 35, 16, 9, 12,
                44, 24, 15, 8, 23, 7, 6, 5
            };

        #if PERFECT_MAGIC_HASH
            for (i = 0; i < 1428; i++)
            {
                magicmovesbdb[i] = 0UL;
            }
            for (i = 0; i < 4900; i++)
            {
                magicmovesrdb[i] = 0UL;
            }
        #endif

            //Bishops
            for (i = 0; i < 64; i++)
            {
                int[]  squares    = new int[64];
                int    numsquares = 0;
                UInt64 temp       = magicmoves_b_mask[i];

                while (temp != 0UL)
                {
                    int bitCount = BitOps.BitCountWegner(temp);
                    squares[numsquares++] = bitCount;
                    BitOps.BitScanForwardReset(ref temp);
                    //UInt64 bit = temp & -temp;
                    //squares[numsquares++] = initmagicmoves_bitpos64_database[(bit * 0x07EDD5E59A4E28C2UL) >> 58];
                    //temp ^= bit;
                }

                for (temp = 0; temp < (1UL << numsquares); temp++)
                {
                    UInt64 tempocc = initmagicmoves_occ(squares, numsquares, temp);

                                #if !PERFECT_MAGIC_HASH
                        #if !VARIABLE_SHIFT
                    magicmovesbdb[squares[i], Convert.ToInt32((tempocc * magicmoves_b_magics[squares[i]]) >> 55)] = initmagicmoves_Bmoves(i, tempocc);
                        #else
                    magicmovesbdb[squares[i], Convert.ToInt32((tempocc * magicmoves_b_magics[squares[i]]) >> magicmoves_b_shift[squares[i]])] = initmagicmoves_Bmoves(i, tempocc);
                        #endif
                        #else
                    UInt64 moves = initmagicmoves_Bmoves(i, tempocc);

                        #if !VARIABLE_SHIFT
                    UInt64 index = ((tempocc * magicmoves_b_magics[i]) >> 55);
                        #else
                    UInt64 index = ((tempocc * magicmoves_b_magics[i]) >> magicmoves_b_shift[square]);
                        #endif

                    for (ushort j = 0; j < 1428; j++)
                    {
                        if (~magicmovesbdb[j] != 0UL)
                        {
                            magicmovesbdb[j] = moves;
                            magicmoves_b_indices[i, Convert.ToInt32(index)] = j;
                            break;
                        }
                        else if (magicmovesbdb[j] == moves)
                        {
                            magicmoves_b_indices[i, Convert.ToInt32(index)] = j;
                            break;
                        }
                    }
                    #endif
                }
            }

            //Rooks
            for (i = 0; i < 64; i++)
            {
                int[]  squares    = new int[64];
                int    numsquares = 0;
                UInt64 temp       = magicmoves_r_mask[i];

                while (temp != 0UL)
                {
                    int bitCount = BitOps.BitCountWegner(temp);
                    squares[numsquares++] = bitCount;
                    BitOps.BitScanForwardReset(ref temp);
                    //UInt64 bit = temp & -temp;
                    //squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2UL)>>58];
                    //temp^=bit;
                }

                for (temp = 0; temp < (1UL << numsquares); temp++)
                {
                    UInt64 tempocc = initmagicmoves_occ(squares, numsquares, temp);

                                #if !PERFECT_MAGIC_HASH
                        #if !VARIABLE_SHIFT
                    magicmovesrdb[squares[i], Convert.ToInt32((tempocc * magicmoves_r_magics[squares[i]]) >> 52)] = initmagicmoves_Rmoves(i, tempocc);
                                    #else
                    magicmovesrdb[squares[i], Convert.ToInt32((tempocc * magicmoves_r_magics[squares[i]]) >> magicmoves_r_shift[squares[i]])] = initmagicmoves_Rmoves(i, tempocc);
                        #endif
                        #else
                    UInt64 moves = initmagicmoves_Rmoves(i, tempocc);

                        #if !VARIABLE_SHIFT
                    UInt64 index = (((tempocc) * magicmoves_r_magics[i]) >> 52);
                        #else
                    UInt64 index = (((tempocc) * magicmoves_r_magics[i]) >> magicmoves_r_shift[squares[i]]);
                        #endif

                    for (ushort j = 0; j < 4900; j++)
                    {
                        if (~magicmovesrdb[j] != 0UL)
                        {
                            magicmovesrdb[j] = moves;
                            magicmoves_r_indices[i, Convert.ToInt32(index)] = j;
                            break;
                        }
                        else if (magicmovesrdb[j] == moves)
                        {
                            magicmoves_r_indices[i, Convert.ToInt32(index)] = j;
                            break;
                        }
                    }
#endif
                }
            }
        }