Пример #1
0
        /// <summary>
        /// 局面のハッシュキーを取得
        /// </summary>
        /// <param name="position"></param>
        /// <param name="gikouBook"></param>
        /// <returns></returns>
        public static long ComputeKey(SPosition position, GikouBook gikouBook)
        {
            long key = 0;

            SPosition pos = (SPosition)position.Clone();

            // 後手番であれば、将棋盤を180度反転して、先手番として扱う
            if (pos.Turn == PlayerColor.White)
            {
                pos.Flip();
            }

            // 盤上の駒
            int gikout_sq = 0;

            foreach (var sq in squareTable)
            {
                key       += gikouBook.HashSeeds.GetPsq((int)pos.GetPiece(sq), gikout_sq);
                gikout_sq += 1;
            }

            // 持ち駒
            foreach (PlayerColor color in new PlayerColor[] { PlayerColor.Black, PlayerColor.White })
            {
                for (int pt = 1; pt < SPosition.HandMax; pt++)
                {
                    for (int n = pos.GetHand(color, (PieceType)pt); n > 0; n--)
                    {
                        key += gikouBook.HashSeeds.GetHand((int)color, pt);
                    }
                }
            }

            return(key);
        }
Пример #2
0
        /// <summary>
        /// SPositionからApery用のハッシュキーを取得
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        private static ulong GetKey(SPosition pos)
        {
            ulong key = 0;

            // 盤上の駒
            for (AperySquare ap = AperySquare.I9; ap < AperySquare.SquareNum; ap++)
            {
                int sq = Square.Make(ap.FileOf(), ap.RankOf());

                Piece piece = pos.GetPiece(sq);

                if (piece != Piece.NoPiece)
                {
                    int index = (int)piece.ConvAperyPiece();

                    key ^= AperyBook.ZobPiece[index][(int)ap];
                }
            }

            // 持ち駒
            for (PieceType pt = PieceType.FU; pt < PieceType.King; pt++)
            {
                int num = pos.GetHand(pos.Turn, pt);

                key ^= AperyBook.ZobHand[(int)pt - 1][num];
            }

            if (pos.Turn == PlayerColor.White)
            {
                key ^= AperyBook.ZobTurn;
            }

            return(key);
        }
Пример #3
0
        /// <summary>
        /// SPositionからApery用のハッシュキーを取得
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        private static ulong GetKey(SPosition pos)
        {
            ulong key = 0;

            // 盤上の駒
            for (AperySquare ap = AperySquare.I9; ap < AperySquare.SquareNum; ap++)
            {
                int sq = Square.Make(ap.FileOf(), ap.RankOf());

                Piece piece = pos.GetPiece(sq);

                if (piece != Piece.NoPiece)
                {
                    int index = (int)piece.ConvAperyPiece();

                    key ^= AperyBook.ZobPiece[index][(int)ap];
                }
            }

            // 持ち駒
            for (PieceType pt = PieceType.FU; pt < PieceType.King; pt++)
            {
                int num = pos.GetHand(pos.Turn, pt);

                key ^= AperyBook.ZobHand[(int)pt - 1][num];
            }

            if (pos.Turn == PlayerColor.White)
            {
                key ^= AperyBook.ZobTurn;
            }

            return key;
        }