Exemple #1
0
 public bool CollapseWcf()
 {
     return(_grid.CollapseAllRecursive());
 }
Exemple #2
0
        static void Main(string[] args)
        {
            var tl     = new OpinionatedItem <String>("┌", "┌", WcfVector.GetCross3dShape());
            var tr     = new OpinionatedItem <String>("┐", "┐", WcfVector.GetCross3dShape());
            var bl     = new OpinionatedItem <String>("└", "└", WcfVector.GetCross3dShape());
            var br     = new OpinionatedItem <String>("┘", "┘", WcfVector.GetCross3dShape());
            var h      = new OpinionatedItem <String>("-", "-", WcfVector.GetCross3dShape());
            var v      = new OpinionatedItem <String>("|", "|", WcfVector.GetCross3dShape());
            var em     = new OpinionatedItem <String>(" ", " ", WcfVector.GetCross3dShape());
            var no     = new OpinionatedItem <String>("X", "X", WcfVector.GetCross3dShape());
            var ladder = new OpinionatedItem <String>("L", "L", WcfVector.GetCross3dShape());
            var all    = new List <IOpinionatedItem> {
                tl, tr, br, bl, em, h, v, no, ladder
            };

            em.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl, em, no, v
            }, 1, 0, 0);
            em.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br, em, no, v
            }, -1, 0, 0);
            em.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr, em, no, h
            }, 0, 1, 0);
            em.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br, em, no, h
            }, 0, -1, 0);

            tl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br
            }, 1, 0, 0);
            tl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br
            }, -1, 0, 0);
            tl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br
            }, 0, 1, 0);
            tl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br
            }, 0, -1, 0);

            tr.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl
            }, 1, 0, 0);
            tr.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl
            }, -1, 0, 0);
            tr.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br
            }, 0, 1, 0);
            tr.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br
            }, 0, -1, 0);

            bl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br
            }, 1, 0, 0);
            bl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br
            }, -1, 0, 0);
            bl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr
            }, 0, 1, 0);
            bl.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr
            }, 0, -1, 0);

            br.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl
            }, 1, 0, 0);
            br.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl
            }, -1, 0, 0);
            br.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr
            }, 0, 1, 0);
            br.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr
            }, 0, -1, 0);

            h.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br, h
            }, 1, 0, 0);
            h.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl, h
            }, -1, 0, 0);
            h.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                em, tr, tl
            }, 0, 1, 0);
            h.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                em, br, bl
            }, 0, -1, 0);

            v.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl, em, no, v
            }, 1, 0, 0);
            v.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br, em, no, v
            }, -1, 0, 0);
            v.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                br, bl, v
            }, 0, 1, 0);
            v.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, tl, v
            }, 0, -1, 0);

            no.SetAcceptableInAllDirection(new List <IOpinionatedItem>()
            {
                em
            });
            no.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl, v
            }, 1, 0, 0);
            no.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br, v
            }, -1, 0, 0);
            no.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr, h
            }, 0, 1, 0);
            no.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br, h
            }, 0, -1, 0);

            ladder.SetAcceptableInAllDirection(new List <IOpinionatedItem>()
            {
                em
            });
            ladder.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, bl, v
            }, 1, 0, 0);
            ladder.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tr, br, v
            }, -1, 0, 0);
            ladder.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                tl, tr, h
            }, 0, 1, 0);
            ladder.SetAcceptableInDirection(new List <IOpinionatedItem>()
            {
                bl, br, h
            }, 0, -1, 0);
            ladder.requirements.Add(new Tuple <int, Guid, RequirementComparison>(1, h.Id, RequirementComparison.GreaterThanOrEqualTo));

            /*var tl = new OpinionatedItem<String>("_", "top-left");
             * var tr = new OpinionatedItem<String>(" ", "top-right");
             * var t = new OpinionatedItem<String>(".", "terminator");
             * tl.SetAcceptableInAllDirection(new List<IOpinionatedItem>() { tr, t, tl });
             * tr.SetAcceptableInAllDirection(new List<IOpinionatedItem>() { tr, t, tl });
             * t.SetAcceptableInAllDirection(new List<IOpinionatedItem>() { tr, t, tl });
             *
             * tl.ClearAcceptableInDirection(1, 0, 0);
             * tl.ClearAcceptableInDirection(-1, 0, 0);
             * tl.SetAcceptableInDirection(new List<IOpinionatedItem>() { tl, t }, 1, 0, 0);
             * tl.SetAcceptableInDirection(new List<IOpinionatedItem>() { tl, t }, -1, 0, 0);
             *
             * tr.ClearAcceptableInDirection(1, 0, 0);
             * tr.ClearAcceptableInDirection(-1, 0, 0);
             * tr.SetAcceptableInDirection(new List<IOpinionatedItem>() { t, tr },1,0,0);
             * tr.SetAcceptableInDirection(new List<IOpinionatedItem>() { t, tr }, -1, 0, 0);
             *
             * var wcf = new WcfGrid(0);
             * wcf.Init(10,10,1,new List<IOpinionatedItem>() { tl, tr, t });*/

            var keyVal = ' ';
            var seed   = 21;

            while (keyVal != 'Q' && keyVal != 'q')
            {
                var wcf = new WcfGrid(seed++);
                wcf.Init(20, 10, 1, all);
                List <WcfVector> shape = WcfVector.GetCross3dShape();
                wcf.SetInfluenceShape(shape);

                wcf.CollapseAllRecursive();

                wcf.PrintStatesToConsole2d();
                Console.WriteLine("Press any key to quit.");
                keyVal = Console.ReadKey().KeyChar;
            }
        }
Exemple #3
0
        public static bool ApplyIntentionToGrid(IntentionGrid grid, WcfGrid wcfGrid, TilesetConfiguration tilesconfig, iMeaningConverter converter)
        {
            for (var x = 0; x < grid.Width; x++)
            {
                for (var y = 0; y < grid.Height; y++)
                {
                    if (y == 8 && x == 7)
                    {
                        var breaka = "here";
                    }
                    var intentions = grid.Positions[x, y].Intentions;
                    if (intentions.Count != 0)
                    {
                        List <OpinionatedItem <Bitmap> > crossedTiles = new List <OpinionatedItem <Bitmap> >();
                        var firsttime = true;
                        foreach (var intention in intentions)
                        {
                            if (firsttime)
                            {
                                crossedTiles.AddRange(converter.MeaningToTiles(intention.Meaning, tilesconfig));
                                firsttime = false;
                            }
                            else
                            {
                                crossedTiles = crossedTiles.Where(c => converter.MeaningToTiles(intention.Meaning, tilesconfig).Any(n => n.Id == c.Id)).ToList();
                            }
                        }
                        if (crossedTiles.Count == 0)
                        {
                            Console.WriteLine("Crossing Tile Intentions yeilded no items!");
                        }
                        //DebugWfcPrint(crossedTiles, wcfGrid, x, y, tilesconfig.WFCdebugFolderPath);
                        wcfGrid.SuperPositions[x, y, 0].CollapseToItems(crossedTiles.Select(c => c.Id).ToList(), true);
                        if (!wcfGrid.SuperPositions[x, y, 0].slots.Any(s => !s.Collapsed))
                        {
                            Console.WriteLine("Collapse To Specific Item failed for Intentions:");
                            foreach (var meaning in intentions.Select(i => i.Meaning))
                            {
                                Console.WriteLine(" -" + meaning.ToString());
                            }
                            DebugWfcPrint(crossedTiles, wcfGrid, x, y, tilesconfig.WFCdebugFolderPath);
                        }

                        var result = wcfGrid.handlePropagation(wcfGrid.SuperPositions[x, y, 0]);

                        if (!result)
                        {
                            Console.WriteLine("WcfGrid fucke dup");
                            //throw new Exception("WcfGrid fucke dup");
                            return(false);
                        }
                    }
                }
            }

            var recurseresult = wcfGrid.CollapseAllRecursive();

            if (!recurseresult)
            {
                Console.WriteLine("WcfGrid collapse recursive fucke dup");
                //throw new Exception("WcfGrid collapse recursive fucke dup");
                return(false);
            }

            return(true);
        }
Exemple #4
0
        private static void Execute()
        {
            Bitmap tileset = Image.FromFile(ConfigurationManager.AppSettings["TilesetInput"]) as Bitmap;

            tileset = tileset.AddHorizontalMirror();
            List <List <Bitmap> > tiles = BitmapOperations.GetBitmapTiles(tileset, 5, 5);

            Bitmap hTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["hTraverseInput"]) as Bitmap;
            List <List <Bitmap> > hTraverseDbl = BitmapOperations.GetBitmapTiles(hTraverseBmp, 5, 5);
            Bitmap quickcheck = BitmapOperations.CreateBitmapFromTiles(hTraverseDbl, true);

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], quickcheck);
            List <Bitmap> hTraverse = new List <Bitmap>();

            foreach (var list in hTraverseDbl)
            {
                hTraverse.AddRange(list);
            }

            Bitmap vTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["vTraverseInput"]) as Bitmap;
            List <List <Bitmap> > vTraverseDbl = BitmapOperations.GetBitmapTiles(vTraverseBmp, 5, 5);
            List <Bitmap>         vTraverse    = new List <Bitmap>();

            foreach (var list in vTraverseDbl)
            {
                vTraverse.AddRange(list);
            }

            var distinctTiles = GetDistinctBitmaps(tiles);

            List <List <Bitmap> > distinctElements = new List <List <Bitmap> >();

            distinctElements.Add(distinctTiles);
            Bitmap tilemapWithSpacing = BitmapOperations.CreateBitmapFromTiles(distinctElements, true);

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], tilemapWithSpacing);


            var opinionatedItemsDistinct = ToOpinionatedList(distinctTiles);

            SetAcceptableItems(opinionatedItemsDistinct, tiles);

            var vTraverseOpinionated = opinionatedItemsDistinct.Where(element => vTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList();
            var hTraverseOpinionated = opinionatedItemsDistinct.Where(element => hTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList();


            for (var i = 0; i < 5; i++)
            {
                var wcf = new WcfGrid();
                wcf.Init(20, 10, 1, opinionatedItemsDistinct);
                List <WcfVector> shape = WcfVector.GetCross3dShape();
                wcf.SetInfluenceShape(shape);


                //Manual Edits
                //in and out
                AddDoor(wcf, opinionatedItemsDistinct[1], 5);
                //border
                AddBorder(wcf, opinionatedItemsDistinct[0], 5);
                //add path
                AddPath(wcf, hTraverseOpinionated, 5);


                var result = wcf.CollapseAllRecursive();
                //if (result == false)
                //continue;

                var collapsedTiles = ToTilesList(wcf);
                wcf.PrintStatesToConsole2d();

                Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles);
                BitmapOperations.SaveBitmapToFile(
                    ConfigurationManager.AppSettings["BitmapOutput"].Replace(
                        ".bmp",
                        i.ToString() + ".bmp"
                        ),
                    tilesetRedux);
            }
        }