Beispiel #1
0
    /// Position::init() initializes at startup the various arrays used to compute
    /// hash keys.
    internal static void init()
    {
        var rng = new PRNG(1070372);

        foreach (var c in Color.AllColors)
        {
            foreach (var pt in PieceType.AllPieceTypes)
            {
                for (var s = Square.SQ_A1; s <= Square.SQ_H8; ++s)
                {
                    Zobrist.psq[c, pt, s] = rng.rand();
                }
            }
        }

        foreach (var f in File.AllFiles)
        {
            Zobrist.enpassant[f] = rng.rand();
        }

        for (var cr = (int) CastlingRight.NO_CASTLING; cr <= (int) CastlingRight.ANY_CASTLING; ++cr)
        {
            Zobrist.castling[cr] = 0;
            var b = Bitboard.Create((ulong) cr);
            while (b != 0)
            {
                var k = Zobrist.castling[1 << Utils.pop_lsb(ref b)];
                Zobrist.castling[cr] ^= (k != 0 ? k : rng.rand());
            }
        }

        Zobrist.side = rng.rand();
        Zobrist.exclusion = rng.rand();
    }