public IToken Apply(IToken arg) { if (Protocol == null) { return(new InteractOperator(arg)); } if (State == null) { return(new InteractOperator(Protocol, arg)); } var Vector = AlienMessageParser.Reduce(arg); var p1 = AlienMessageParser.Reduce(Protocol.Apply(State)); var p2 = AlienMessageParser.Reduce(p1.Apply(Vector)); var flag = p2.Car().AsValue(); var newState = IToken.Dem(p2.Cdr().Car().Mod()); var data = p2.Cdr().Cdr().Car(); if (flag != 0) { var s = new SendOperator(); var v = s.Apply(data); return(new InteractOperator(Protocol, newState).Apply(v)); } AlienMessageParser.lastInteractResult = data; Debug.Assert(p2.Cdr().Cdr().Cdr() is NilOperator); return(new InteractOperator(Protocol, newState)); }
public IToken Apply(IToken token) { if (!Uri.TryCreate("https://icfpc2020-api.testkontur.ru/aliens/send", UriKind.Absolute, out var serverUri)) { throw new InvalidOperationException(); } using var httpClient = new HttpClient { BaseAddress = serverUri }; var message = token.Mod(); var requestContent = new StringContent(message, Encoding.UTF8, MediaTypeNames.Text.Plain); using var response = httpClient.PostAsync("?apiKey=f01dd9315e064ba388e0402d128a23f2", requestContent).Result; if (!response.IsSuccessStatusCode) { throw new InvalidOperationException(); } var responseString = response.Content.ReadAsStringAsync().Result; return(IToken.Dem(responseString)); }
public void ConsNilNil() { Assert.That(IToken.Dem("110000").ToString(), Is.EqualTo("cons [nil] [nil]")); }
public void ConsBigResponse() { Assert.That(IToken.Dem("1101100001110111110010011111001010000").ToString(), Is.EqualTo("cons [1] [cons [20372] [nil]]")); }