Beispiel #1
0
            protected override Value Apply(Value protocol, Value state, Value vector)
            {
                long  flag = 1;
                Value data = Value.Nil;

                while (flag != 0)
                {
                    var app = new Application
                    {
                        Func = new Application
                        {
                            Func     = protocol,
                            Argument = state,
                        },
                        Argument = vector,
                    };

                    Console.WriteLine($"App = {app.Force()}");

                    var t0 = (Pair)app.Force();
                    flag = ((Integer)t0.First.Force()).Val;
                    var t1 = (Pair)t0.Second.Force();
                    state = Modem.Demodulate(Modem.Modulate(t1.First.Force()));
                    var t2 = (Pair)t1.Second.Force();
                    data = t2.First.Force();

                    Console.WriteLine("\n\n\n\n\n\n");
                    Console.WriteLine($"Flag = {flag}");
                    Console.WriteLine($"State = {state}");
                    Console.WriteLine($"Data = {data}");

                    if (flag != 0)
                    {
                        var reply = Sender.Send(data).Result;
                        Console.WriteLine($"Reply = {reply}");
                        vector = reply;
                    }
                }

                return(new Pair
                {
                    First = state,
                    Second = data,
                });
            }
Beispiel #2
0
        static void Main(string[] args)
        {
            var mode    = args[0];
            var payload = args[1];

            if (mode == "mod")
            {
                Console.WriteLine(Sender.BitsToString(Modem.Modulate(ParseData(payload))));
            }
            else if (mode == "dem")
            {
                Console.WriteLine(Modem.Demodulate(Sender.StringToBits(payload)));
            }
            else
            {
                throw new Exception($"Unknown mode {mode}");
            }
        }
Beispiel #3
0
        public static async Task <Value> Send(Value value)
        {
            using var httpClient   = new HttpClient();
            httpClient.BaseAddress = new Uri("https://icfpc2020-api.testkontur.ru/aliens/send?apiKey=911f0ee2b60c4fe8a7048b89dc69b7de");

            var requestContent = new StringContent(BitsToString(Modem.Modulate(value)), Encoding.UTF8, MediaTypeNames.Text.Plain);

            using var response = await httpClient.PostAsync("", requestContent);

            if (!response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.StatusCode);
            }

            var responseString = await response.Content.ReadAsStringAsync();

            return(Modem.Demodulate(StringToBits(responseString)));
        }