Exemple #1
0
        public bool AddBorder(Room room)
        {
            bool result;

            for (var x = 0; x < _grid.Width; x++)
            {
                for (var y = 0; y < _grid.Height; y++)
                {
                    if (!(x == 0 || y == 0 || x == _grid.Width - 1 || y == _grid.Height - 1))
                    {
                        continue;
                    }
                    var thisPoint = new Point(x, y);
                    if (room.portals.Any(p => p.point == thisPoint))
                    {
                        continue;
                    }


                    _grid.SuperPositions[x, y, 0].CollapseToItems(_borderTiles.Select(i => i.Id).ToList(), true);
                    result = _grid.handlePropagation(_grid.SuperPositions[x, y, 0]);
                    if (!result)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #2
0
 private static void AddDoor(WcfGrid grid, IOpinionatedItem doorItem, int doorwayY)
 {
     //grid.SuperPositions[0, 5, 0].Uncollapse();
     //grid.SuperPositions[grid.Width-1, 5, 0].Uncollapse();
     grid.SuperPositions[0, doorwayY, 0].CollapseToItem(doorItem.Id);
     grid.handlePropagation(grid.SuperPositions[0, doorwayY, 0]);
     grid.SuperPositions[grid.Width - 1, doorwayY, 0].CollapseToItem(doorItem.Id);
     grid.handlePropagation(grid.SuperPositions[grid.Width - 1, doorwayY, 0]);
 }
Exemple #3
0
 private static void AddPath(WcfGrid grid, List <OpinionatedItem <Bitmap> > hTraverse, int doorwayY)
 {
     for (var x = 2; x < grid.Width - 2; x++)
     {
         grid.SuperPositions[x, doorwayY, 0].CollapseToItems(hTraverse.Select(i => i.Id).ToList(), true);
         grid.handlePropagation(grid.SuperPositions[x, doorwayY, 0]);
     }
 }
Exemple #4
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);
        }
Exemple #5
0
 private static void AddBorder(WcfGrid grid, IOpinionatedItem borderElement, int doorwayY)
 {
     for (var x = 0; x < grid.Width; x++)
     {
         for (var y = 0; y < grid.Height; y++)
         {
             if (x > 0 && x < grid.Width - 1 && y > 0 && y < grid.Height - 1)
             {
                 continue;
             }
             if (y == doorwayY)
             {
                 continue;
             }
             grid.SuperPositions[x, y, 0].CollapseToItem(borderElement.Id);
             var result = grid.handlePropagation(grid.SuperPositions[x, y, 0]);
         }
     }
 }
Exemple #6
0
        public bool AddBorder(Room room)
        {
            //NOT AFFECTED BY BORDER WIDTH!
            bool result = true;

            for (var x = 0; x < _grid.Width; x++)
            {
                for (var y = 0; y < _grid.Height; y++)
                {
                    if (!(x == 0 || y == 0 || x == _grid.Width - 1 || y == _grid.Height - 1))
                    {
                        continue;
                    }
                    var thisPoint = new Point(x, y);

                    //should technically be moved to add path
                    if (room.portals.Any(p => p.point == thisPoint))
                    {
                        var portals    = room.portals.Where(p => p.point == thisPoint);
                        var directions = portals.Select(p => p.direction).Distinct();
                        if (directions.Where(d => d.X == 0).Count() == 0)
                        {
                            //horizontal
                            _grid.SuperPositions[x, y, 0].CollapseToItems(_hEntranceTiles.Select(i => i.Id).ToList(), true);
                            result = result && _grid.handlePropagation(_grid.SuperPositions[x, y, 0]);
                        }
                        else if (directions.Where(d => d.Y == 0).Count() == 0)
                        {
                            //vertical
                            _grid.SuperPositions[x, y, 0].CollapseToItems(_vEntranceTiles.Select(i => i.Id).ToList(), true);
                            result = result && _grid.handlePropagation(_grid.SuperPositions[x, y, 0]);
                        }
                        else
                        {
                            //intersectional
                            _grid.SuperPositions[x, y, 0].CollapseToItems(_cornerIntersectionTiles.Select(i => i.Id).ToList(), true);
                            result = result && _grid.handlePropagation(_grid.SuperPositions[x, y, 0]);
                        }
                        continue;
                    }

                    //skip ones next to entrances...
                    if (room.portals.Any(p =>
                                         p.point == new Point(thisPoint.X + 1, thisPoint.Y) ||
                                         p.point == new Point(thisPoint.X - 1, thisPoint.Y) ||
                                         p.point == new Point(thisPoint.X, thisPoint.Y + 1) ||
                                         p.point == new Point(thisPoint.X, thisPoint.Y + 2)
                                         ))
                    {
                        continue;
                    }

                    _grid.SuperPositions[x, y, 0].CollapseToItems(_borderTiles.Select(i => i.Id).ToList(), true);

                    result = _grid.handlePropagation(_grid.SuperPositions[x, y, 0]);
                    if (!result)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #7
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);
        }