Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        public static SBook ImportYaneuraOu(string filename)
        {
            SBook book = new SBook();

            try
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;

                    SPosition pos = new SPosition();

                    book.Add(pos, null, 0, 0, 0); // 平手初期局面をいれる

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("sfen") || line.StartsWith("startpos") || line.StartsWith("position"))
                        {
                            Sfen.ReadNotation(pos, line);
                        }
                        else if (line.StartsWith("#") || line.StartsWith("//"))
                        {
                            // コメント
                        }
                        else
                        {
                            string[] str_array = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            if (str_array.Length >= 5)
                            {
                                MoveData move = Sfen.ParseMove(pos, str_array[0]);

                                if (move.Piece == Piece.NoPiece || pos.GetPiece(move.ToSquare).ColorOf() == move.Piece.ColorOf())
                                {
                                    Debug.WriteLine("bb");
                                }

                                if (move != null && move.MoveType.IsMoveWithoutPass())
                                {
                                    int weight;
                                    int depth = 0;
                                    int value = 0;

                                    int.TryParse(str_array[2], out value);
                                    int.TryParse(str_array[3], out depth);

                                    if (int.TryParse(str_array[4], out weight))
                                    {
                                        // 指し手の追加
                                        book.Add(pos, move, weight, value, depth);
                                    }
                                }
                            }
                        }
                    }
                }

                // idの付け直し
                book.SetIds();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(book);
        }
Beispiel #4
0
        public static SBook ImportYaneuraOu(string filename)
        {
            SBook book = new SBook();

            try
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;

                    SPosition pos = new SPosition();

                    book.Add(pos, null, 0, 0, 0); // 平手初期局面をいれる

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("sfen") || line.StartsWith("startpos") || line.StartsWith("position"))
                        {
                            Sfen.ReadNotation(pos, line);
                        }
                        else if (line.StartsWith("#") || line.StartsWith("//"))
                        {
                            // コメント
                        }
                        else
                        {
                            string[] str_array = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            if (str_array.Length >= 5)
                            {
                                MoveData move = Sfen.ParseMove(pos, str_array[0]);

                                if (move.Piece == Piece.NoPiece || pos.GetPiece(move.ToSquare).ColorOf() == move.Piece.ColorOf())
                                {
                                    Debug.WriteLine("bb");
                                }

                                if (move != null && move.MoveType.IsMoveWithoutPass())
                                {
                                    int weight;
                                    int depth = 0;
                                    int value = 0;

                                    int.TryParse(str_array[2], out value);
                                    int.TryParse(str_array[3], out depth);

                                    if (int.TryParse(str_array[4], out weight))
                                    {
                                        // 指し手の追加
                                        book.Add(pos, move, weight, value, depth);
                                    }
                                }
                            }
                        }
                    }
                }

                // idの付け直し
                book.SetIds();

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return book;
        }