示例#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);
        }