Example #1
0
        public static WcfGrid InitWcfGrid(Random random, IntentionGrid grid, TilesetConfiguration TilesConfig)
        {
            var WcfGrid = new WcfGrid(random);

            WcfGrid.Init(grid.Width, grid.Height, 1, TilesConfig.MainDistinct.Select(x => (IOpinionatedItem)x).ToList());
            List <WcfVector> shape = WcfVector.GetCross3dShape();

            WcfGrid.SetInfluenceShape(shape);
            WcfGrid.handlePropagation(WcfGrid.SuperPositions[WcfGrid.Width / 2, WcfGrid.Height / 2, 0]);
            return(WcfGrid);
        }
Example #2
0
        public void InitWcfGrid(int?seed = null)
        {
            if (seed != null)
            {
                _random = new Random(seed.Value);
            }
            else
            {
                _random = null;
            }
            if (_random == null)
            {
                _grid = new WcfGrid();
            }
            else
            {
                _grid = new WcfGrid(_random);
            }
            _grid.Init(_levelWidth, _levelHeight, 1, _wfcTiles);
            List <WcfVector> shape = WcfVector.GetCross3dShape();

            _grid.SetInfluenceShape(shape);
        }
Example #3
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;
            }
        }
Example #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);
            }
        }