Exemple #1
0
        private bool ReadInPuzzleSource()
        {
            if (!File.Exists(PuzzleSourceFile))
            {
                return(ShowInstructions());
            }

            var counter = 0;
            var lines   = File.ReadLines(PuzzleSourceFile);

            Parallel.ForEach(lines, line =>
            {
                if (++counter % 1000 == 0)
                {
                    Console.Write("\r" + counter);
                }
                //if (counter > 200000)
                //   break;
                //if (counter < 220000)
                //   continue;
                var parts = line.Split(',');
                if (parts.Length != 9)
                {
                    Console.WriteLine("\nWrong Line in " + PuzzleSourceFile + ": " + line);
                    return;
                }

                var puzzleData = new PuzzleData
                {
                    ChallengeId  = parts[0],
                    WinningMoves = parts[2],
                    Comment      = parts[7],
                    Link         = parts[8]
                };
                var posNumbersign     = puzzleData.Link.LastIndexOf('#');
                puzzleData.MoveNumber = puzzleData.Link.Substring(posNumbersign + 1);
                puzzleData.Link       = puzzleData.Link.Substring(0, posNumbersign);
                lock (PuzzleSourceUrls)
                    PuzzleSourceUrls.Add(puzzleData);
            });

            return(true);
        }
Exemple #2
0
        private void SearchForUserGame(GameData game)
        {
            var foundPuzzleGame = PuzzleSourceUrls.FirstOrDefault(item => item.Link == game.Site);

            if (foundPuzzleGame != null)
            {
                Console.Write("\r          ");
                FoundGames.Add(game);
                Console.WriteLine("\nLink to the game: " + foundPuzzleGame.Link + "#" + foundPuzzleGame.MoveNumber);
                Console.WriteLine("Link to training: " + ChallengeLink + foundPuzzleGame.ChallengeId);

                foreach (var property in typeof(GameData).GetProperties())
                {
                    if (!(property.GetValue(game) is string value))
                    {
                        continue;
                    }
                    var name = property.Name.PadRight(16, ' ');
                    Console.Write("\r" + name + ": " + value + "\n");
                }
                Console.WriteLine("Comment".PadRight(16, ' ') + ": " + foundPuzzleGame.Comment);
                Console.WriteLine("Winning Moves".PadRight(16, ' ') + ": " + foundPuzzleGame.WinningMoves);
            }
        }