void OnMove(bool whiteMoved, ushort move)
    {
        if (relinquishUserScrollbarControlNextMove)
        {
            relinquishUserScrollbarControlNextMove = false;
            userControllingScrollbar = false;
        }

        if (whiteMoved)
        {
            fullGamePGN              += (BoardGround.GetFullMoveCount() + 1) + ". " + PGNReaderGround.NotationFromMove(move);
            moveNumberUI.text        += (BoardGround.GetFullMoveCount() + 1) + ". \n";
            moveNotationWhiteUI.text += PGNReaderGround.NotationFromMove(move) + "\n";
        }
        else
        {
            fullGamePGN += " " + PGNReaderGround.NotationFromMove(move) + " ";
            moveNotationBlackUI.text += PGNReaderGround.NotationFromMove(move) + "\n";

            if (BoardGround.GetFullMoveCount() > 14)
            {
                int size = -30 * (BoardGround.GetFullMoveCount() - 14);
                contentBounds.offsetMin = new Vector2(contentBounds.offsetMin.x, size);
                contentBounds.offsetMax = new Vector2(contentBounds.offsetMax.x, 0);
            }
        }
    }
Exemple #2
0
    static void ProcessFiles(string[] files, int minGameLengthPly, int recordToPly)
    {
        BoardGround.SetPositionFromFen(DefinitionsGround.startFen);

        // Read pgns and convert to opening book dictionary
        for (int fileIndex = 0; fileIndex < files.Length; fileIndex++)
        {
            StreamReader  reader = new StreamReader(files[fileIndex]);
            List <string> pgns   = new List <string>();

            // split text into array of pgn strings
            bool readingPGN         = false;
            int  pgnIndex           = -1;
            bool finishedReadingPGN = false;
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine() + " ";
                if (line.Contains("["))                   // comment line
                {
                    finishedReadingPGN = false;
                    readingPGN         = false;
                    continue;
                }
                else if (!finishedReadingPGN)
                {
                    for (int charIndex = 0; charIndex < line.Length; charIndex++)
                    {
                        if (!readingPGN && line[charIndex] == '1')
                        {
                            readingPGN = true;
                            pgns.Add("");
                            pgnIndex++;
                        }
                        if (readingPGN)
                        {
                            pgns[pgnIndex] += line[charIndex] + "";
                            if (pgns[pgnIndex].Split('.').Length * 2 > recordToPly)                               // only record the first n moves for opening book
                            {
                                finishedReadingPGN = true;
                                break;
                            }
                        }
                    }
                }
            }

            reader.Close();

            // get moves from pgn files
            for (int i = 0; i < pgns.Count; i++)
            {
                string pgn = pgns[i];

                if (pgn.Split('.').Length * 2 < minGameLengthPly)                   // don't record games that were shorter than minGameLengthPly. This is to avoid games where an opening distaster occured
                {
                    continue;
                }

                List <string> moveStrings = PGNReaderGround.MoveStringsFromPGN(pgn);
                List <ushort> moves       = PGNReaderGround.MovesFromPGN(pgn);

                for (int j = 0; j < moves.Count; j++)
                {
                    if (!book.ContainsKey(BoardGround.zobristKey))
                    {
                        keys.Add(BoardGround.zobristKey);
                        book.Add(BoardGround.zobristKey, new List <ushort>());
                    }
                    if (!book[BoardGround.zobristKey].Contains(moves[j]))
                    {
                        book[BoardGround.zobristKey].Add(moves[j]);
                    }
                    BoardGround.MakeMove(moves[j]);
                }
                for (int k = moves.Count - 1; k >= 0; k--)
                {
                    BoardGround.UnmakeMove(moves[k]);
                }
            }
        }
    }