Ejemplo n.º 1
0
        public void ShouldListMask()
        {
            var variable = new Var <int>();

            var list1 = VarList.Create(1, 2, 3, 4, 5);
            var list2 = VarList.Create(3, 4, 5, 6, 7);

            var target = variable <= list1.Member & !(variable <= list2.Member);

            CollectionAssert.AreEqual(new[] { 1, 2 }, target.AsEnumerable(variable).ToArray());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Running");

            var grid = new Var <Direction> [width, height];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    grid[x, y] = new Var <Direction>();
                }
            }

            var initialcoord = new Var <Coord>();

            var query = PlaceFirstCell(grid, initialcoord);

            var placedList = VarList.Create(initialcoord);

            for (int index = 0; index < 20; index++)
            {
                var coord         = new Var <Coord>();
                var newPlacedList = new Var <VarList <Coord> >();

                query = query & PlaceConnectedCell(grid, coord, placedList)
                        & placedList.Append(coord, newPlacedList);

                placedList = newPlacedList;
            }

            if (query.Succeeds())
            {
                for (int y = 0; y < height; y++)
                {
                    for (int row = 0; row < 3; row++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            var cell = grid[x, y];

                            DrawCell(row, cell);
                        }

                        Console.WriteLine();
                    }
                }
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public static Query AsString(this VarList <char> charList, Var <string> value)
        {
            return(Query.Wrap(() =>
            {
                if (value.HasValue)
                {
                    return charList <= VarList.Create(value.Value);
                }
                else
                {
                    var charVar = new Var <char>();

                    return value <= new string(charList.Member(charVar).AsEnumerable(charVar).ToArray());
                }
            }));
        }
Ejemplo n.º 4
0
        public static Var <VarList <T> > AsVarList <T>(this Query query, Var <T> resultVariable)
        {
            var resultList = new List <Var <T> >();

            foreach (var result in query)
            {
                if (resultVariable.HasValue)
                {
                    resultList.Add(resultVariable.Value);
                }
                else if (resultVariable.IsBound)
                {
                    resultList.Add(resultVariable.Dereference());
                }
                else
                {
                    resultList.Add(new Var <T>());
                }
            }

            return(VarList.Create(resultList.ToArray()));
        }
Ejemplo n.º 5
0
 public static Query Append <T>(this VarList <T> initial, Var <T> item, VarList <T> result)
 {
     return(initial.Append(VarList.Create(item), result));
 }