/// <summary> /// 局面追加 /// </summary> public void Add(SPosition pos, MoveData moveData, int weight, int value, int depth) { string key = pos.PositionToString(1); SBookState state = this.GetBookState(key); if (state == null) { // 現在の局面がない場合 state = new SBookState(); state.Games = 1; state.WonBlack = 0; state.WonWhite = 0; state.Position = key; this.books.Add(key, state); this.BookStates.Add(state); } if (moveData != null) { pos.Move(moveData); string next_key = pos.PositionToString(1); SBookState next_state = this.GetBookState(next_key); pos.UnMove(moveData, null); if (next_state == null) { next_state = new SBookState(); next_state.Games = 1; next_state.WonBlack = 0; next_state.WonWhite = 0; next_state.Position = next_key; this.books.Add(next_key, next_state); this.BookStates.Add(next_state); } SBookMove m = new SBookMove(moveData, next_state); SBookMove move = state.GetMove(m); if (move == null) { // 指し手が無い場合は追加 m.Weight = weight; m.Value = value; m.Depth = depth; state.AddMove(m); // next_stateのPositionをクリアする next_state.Position = string.Empty; move = m; } } }
private static void ReadGikouBook(SBook book, GikouBook gbook ,SPosition pos) { long key = ExportGikouBook.ComputeKey(pos, gbook); SBookState state = book.GetBookState(pos.PositionToString(1)); if (state != null && state.Moves.Count != 0) { // すでに登録されてる? return; } // 局面登録 book.Add(pos, null, 0, 0, 0); List<GikouBookEntry> entrys = gbook.GetEntry(key); if (entrys != null) { foreach (GikouBookEntry en in entrys) { MoveData move = ConvertMove(pos.Turn, en.Move); book.Add(pos, move, (int)en.Frequency, en.Score, 1); } foreach (GikouBookEntry en in entrys) { MoveData move = ConvertMove(pos.Turn, en.Move); pos.Move(move); ReadGikouBook(book, gbook, pos); pos.UnMove(move, null); } } }
private static void ReadGikouBook(SBook book, GikouBook gbook, SPosition pos) { long key = ExportGikouBook.ComputeKey(pos, gbook); SBookState state = book.GetBookState(pos.PositionToString(1)); if (state != null && state.Moves.Count != 0) { // すでに登録されてる? return; } // 局面登録 book.Add(pos, null, 0, 0, 0); List <GikouBookEntry> entrys = gbook.GetEntry(key); if (entrys != null) { foreach (GikouBookEntry en in entrys) { MoveData move = ConvertMove(pos.Turn, en.Move); book.Add(pos, move, (int)en.Frequency, en.Score, 1); } foreach (GikouBookEntry en in entrys) { MoveData move = ConvertMove(pos.Turn, en.Move); pos.Move(move); ReadGikouBook(book, gbook, pos); pos.UnMove(move, null); } } }
/// <summary> /// 指し手の出力 /// </summary> /// <param name="bookstate"></param> /// <param name="position"></param> /// <param name="aperyBook"></param> private static void WriteMoves(SBookState bookstate, SPosition position, StreamWriter wr, int depth) { if (bookstate == null) { return; } if (bookstate.Count != 0) { return; // 既に出力した } int count = 0; foreach (SBookMove move in bookstate.Moves) { if (move.Weight != 0) { count++; } } bookstate.Count++; if (count != 0) { // 局面の出力 wr.WriteLine("sfen " + position.PositionToString(depth)); foreach (SBookMove move in bookstate.Moves) { if (move.Weight != 0) { // 指し手の出力 MoveData moveData = move.GetMoveData(); string next_str = "none"; SBookMove next_move = GetNextMove(move.NextState); if (next_move != null) { MoveData nextMoveData = next_move.GetMoveData(); next_str = Sfen.MoveToString(nextMoveData); } wr.WriteLine("{0} {1} {3} {4} {2}", Sfen.MoveToString(moveData), next_str, move.Weight, move.Value, move.Depth); } } } foreach (SBookMove move in bookstate.Moves) { // 指し手の出力 MoveData moveData = move.GetMoveData(); if (position.Move(moveData)) { // 再帰呼び出し WriteMoves(move.NextState, position, wr, depth + 1); position.UnMove(moveData, null); } } }
/// <summary> /// 指し手の出力 /// </summary> /// <param name="bookstate"></param> /// <param name="position"></param> /// <param name="aperyBook"></param> private static void WriteMoves(SBookState bookstate, SPosition position, StreamWriter wr, int depth) { if (bookstate == null) { return; } if (bookstate.Count != 0) { return; // 既に出力した } int count = 0; foreach (SBookMove move in bookstate.Moves) { if (move.Weight != 0) { count++; } } bookstate.Count++; if (count != 0) { // 局面の出力 wr.WriteLine("sfen " + position.PositionToString(depth)); foreach (SBookMove move in bookstate.Moves) { if (move.Weight != 0) { // 指し手の出力 MoveData moveData = move.GetMoveData(); string next_str = "none"; SBookMove next_move = GetNextMove(move.NextState); if (next_move != null) { MoveData nextMoveData = next_move.GetMoveData(); next_str = Sfen.MoveToString(nextMoveData); } wr.WriteLine("{0} {1} {3} {4} {2}", Sfen.MoveToString(moveData), next_str, move.Weight, move.Value, move.Depth); } } } foreach (SBookMove move in bookstate.Moves) { // 指し手の出力 MoveData moveData = move.GetMoveData(); position.Move(moveData); // 再帰呼び出し WriteMoves(move.NextState, position, wr, depth + 1); position.UnMove(moveData, null); } }