Ejemplo n.º 1
0
 public void TestDemodulate()
 {
     foreach (var cs in Cases)
     {
         Assert.Equal(ToBits(cs.Ans), Modem.Modulate(Modem.Demodulate(Modem.Modulate(cs.Val))));
     }
 }
Ejemplo n.º 2
0
        public InteractResponse Post(InteractRequest data)
        {
            var state =
                string.IsNullOrEmpty(data.state)
                    ? Value.Nil
                    : Modem.Demodulate(Sender.StringToBits(data.state));
            var coords = new Pair
            {
                First = new Integer {
                    Val = data.point[0]
                },
                Second = new Integer {
                    Val = data.point[1]
                },
            };

            var res = env.Eval(
                "ap ap ap interact galaxy $1 $2",
                state,
                coords);

            return(new InteractResponse
            {
                state = Sender.BitsToString(Modem.Modulate(res.GetFirst())),
                boards = GetBoard(res.GetSecond()).ToList(),
            });

            IEnumerable <List <int[]> > GetBoard(Value val)
            {
                while (val.Force() != Value.Nil)
                {
                    var board  = new Board(val.GetFirst());
                    var pixels = board.Pixels
                                 .Select(it => new[] { it.X, it.Y })
                                 .ToList();
                    yield return(pixels);

                    val = val.GetSecond();
                }
            }
        }