Exemplo n.º 1
0
        /// <summary>
        /// SBookをAperyBookに変換して保存する
        /// </summary>
        /// <param name="book"></param>
        /// <param name="filename"></param>
        public static void ExportApery(this SBook book, string filename)
        {
            // 初期局面の出力
            AperyBook aperyBook = new AperyBook();
            SPosition position = new SPosition();
            book.ClearCount();
            int cnt = 0;

            foreach (SBookState state in book.BookStates)
            {
                if (state.Position != string.Empty)
                {
                    // 局面が入っている場合
                    Sfen.PositionFromString(position, state.Position);
                }

                // 指し手出力
                if (state.Count == 0 && ((state.Id == 0) || (state.Position != string.Empty)))
                {
                    WriteMoves(state, position, aperyBook);
                }

                cnt++;
            }

            aperyBook.Save(filename);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 指し手の出力
        /// </summary>
        /// <param name="bookstate"></param>
        /// <param name="position"></param>
        /// <param name="aperyBook"></param>
        private static void WriteMoves(SBookState bookstate, SPosition position, AperyBook aperyBook)
        {
            if (bookstate == null)
            {
                return;
            }

            if (bookstate.Count != 0)
            {
                return; // 既に出力した
            }

            bookstate.Count++;

            foreach (SBookMove move in bookstate.Moves)
            {
                if (move.Weight != 0)
                {
                    aperyBook.Add(GetKey(position), move.ConvFromToPro(), move.Weight);
                }

                MoveData moveData = move.GetMoveData();

                position.Move(moveData);

                // 再帰呼び出し
                WriteMoves(move.NextState, position, aperyBook);

                position.UnMove(moveData, null);
            }
        }