Пример #1
0
    public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "chess/engine/{engineName}/ProcessText")] HttpRequestMessage req, string engineName, TraceWriter log)
    {
        log.Info($"Asked for engine {engineName}");
        var engineCommand = CommonChess.GetEngineCommand(engineName);

        log.Info($"Engine command is {engineCommand}");

        var workingDir = CommonWeb.GetWorkingDirectory(req);

        log.Info($"Working dir is {workingDir}");

        var uciText = req.Content.ReadAsStringAsync().Result;

        log.Info(uciText);

        (var outText, var errText) = CommonChess.GetEngineText(engineCommand, workingDir, uciText);

        return(req.CreateResponse(HttpStatusCode.OK, outText, "text/plain"));
    }
Пример #2
0
    public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "chess/engine/{engineName}/HumanMoves")] HttpRequestMessage req, string engineName, TraceWriter log)
    {
        log.Info($"Asked for engine {engineName}");
        var engineCommand = CommonChess.GetEngineCommand(engineName);

        log.Info($"Engine command is {engineCommand}");

        var workingDir = CommonWeb.GetWorkingDirectory(req);

        log.Info($"Working dir is {workingDir}");

        string fen1 = req.GetQueryNameValuePairs()
                      .FirstOrDefault(q => string.Compare(q.Key, "fen", true) == 0)
                      .Value;

        var candidates = CommonChess.GetHumanCandidateMoves(engineCommand, workingDir, WebUtility.UrlDecode(fen1));

        // Fetching the name from the path parameter in the request URL
        return(req.CreateResponse(HttpStatusCode.OK, candidates));
    }