Beispiel #1
0
 private void Start()
 {
     gameMoves = PGNLoader.MovesFromPGN(pgn);
     board     = new Board();
     board.LoadStartPosition();
     boardUI = FindObjectOfType <BoardUI>();
     boardUI.UpdatePosition(board);
 }
Beispiel #2
0
        private void CreateBook()
        {
            var sw   = Stopwatch.StartNew();
            var book = new Book();

            var    reader = new StringReader(gamesFile.text);
            string pgn;
            var    board = new Board();

            while (!string.IsNullOrEmpty(pgn = reader.ReadLine()))
            {
                var moves = PGNLoader.MovesFromPGN(pgn, maxPlyToRecord);
                board.LoadStartPosition();

                for (var i = 0; i < moves.Length; i++)
                {
                    book.Add(board.ZobristKey, moves[i]);
                    board.MakeMove(moves[i]);
                }
            }

            var bookString = "";

            foreach (var bookPositionsByZobristKey in book.bookPositions)
            {
                var key          = bookPositionsByZobristKey.Key;
                var bookPosition = bookPositionsByZobristKey.Value;
                var line         = key + ":";

                var isFirstMoveEntry = true;
                foreach (var moveCountByMove in bookPosition.numTimesMovePlayed)
                {
                    var moveValue = moveCountByMove.Key;
                    var moveCount = moveCountByMove.Value;
                    if (moveCount >= minMovePlayCount)
                    {
                        if (isFirstMoveEntry)
                        {
                            isFirstMoveEntry = false;
                        }
                        else
                        {
                            line += ",";
                        }
                        line += $" {moveValue} ({moveCount})";
                    }
                }

                var hasRecordedAnyMoves = !isFirstMoveEntry;
                if (hasRecordedAnyMoves)
                {
                    bookString += line + Environment.NewLine;
                }
            }

            //string s = fastJSON.JSON.ToJSON (book);
            FileWriter.WriteToTextAsset_EditorOnly(bookFile, bookString, append);
            Debug.Log("Created book: " + sw.ElapsedMilliseconds + " ms.");

            //Book loadedBook = fastJSON.JSON.ToObject<Book> (s);
        }