public static Board ToJohnChessGame(LichessGame game)
        {
            var board = Board.NewStandardBoard();

            foreach (var uciMove in game.UCIMoves)
            {
                var move = DetermineMove(board, uciMove);
                board = board.PerformMove(move);
            }

            return(board);
        }
Esempio n. 2
0
        public async Task <LichessGame> GetTrainingPuzzleAsync(int puzzleNumber)
        {
            string url  = string.Format(PUZZLE_BASE, puzzleNumber.ToString());
            string html = await GetHtmlContentAsync(url);

            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);
            var scripts      = htmlDoc.DocumentNode.Descendants("script");
            var validScripts = (from s in scripts
                                where LichessPuzzleRegex.IsMatch(s.InnerText)
                                select s.InnerText);

            string  javaScriptCode = validScripts.First();
            string  puzzleVal      = jsJsonParser.GetJsonFromJsScriptVariable(javaScriptCode, "lichess");
            dynamic json           = JObject.Parse(puzzleVal);

            return(LichessGame.FromDynamicPuzzleJson(json));
        }
Esempio n. 3
0
        public static LichessGame FromDynamicPuzzleJson(dynamic json)
        {
            var game  = json.puzzle.data.game;
            var parts = game.treeParts;

            var lichess = new LichessGame();

            lichess.Clock       = game.clock.ToString();
            lichess.StartingPly = (int)json.puzzle.data.puzzle.initialPly;
            foreach (var p in parts)
            {
                if (p.uci != null)
                {
                    string uci = p.uci.ToString();
                    lichess.UCIMoves.Add(new UCIChessMove(uci));
                }
                if (lichess.UCIMoves.Count >= lichess.StartingPly)
                {
                    break;
                }
            }
            return(lichess);
        }