Beispiel #1
0
        public static void CreateHorizontalExitPath(IntentionGrid grid, int exitX, int exitY)
        {
            var circuits  = grid.GetByMeaning(Meaning.Circuit);
            var leftMost  = circuits.Select(x => x.X).Min();
            var rightMost = circuits.Select(x => x.X).Max();

            var xDir   = 0;
            var xStart = 0;
            var xStop  = leftMost;

            if (exitX <= 0)
            {
                xDir = 1;
            }
            else
            {
                xDir   = -1;
                xStart = grid.Width - 1;
                xStop  = rightMost;
            }

            for (var x = xStart; x != xStop; x += xDir)
            {
                grid.Positions[x, exitY].Intentions.Add(Intention.ExitPathIntention());
            }

            DebugPrintMeaning(grid, Meaning.ExitPath);
        }
Beispiel #2
0
        public static void CreateToggleExitDoor(IntentionGrid grid)
        {
            var tile = grid.GetByMeaning(Meaning.ExitPath).Where(t => t.X == grid.Width - 1 || t.X == 0).FirstOrDefault();

            grid.Positions[tile.X, tile.Y].Intentions.Add(Intention.ToggleDoorIntention());

            DebugPrintMeaning(grid, Meaning.ToggleDoor);
        }
 public ProcessFactory(int gridWidth, int gridHeight, string wfcDebugPath, string tilesetDebugPath)
 {
     myGrid = new IntentionGrid(gridWidth, gridHeight);
     random = new marcRandom(0);
     myTilesetConfiguration = new TilesetConfiguration(wfcDebugPath, tilesetDebugPath);
     myProcess = new T();
     myProcess.Init(random, myGrid, myTilesetConfiguration);
     _wfcDebugPath     = wfcDebugPath;
     _tilesetDebugPath = tilesetDebugPath;
 }
Beispiel #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);
        }
Beispiel #5
0
        public static void CreateToggleExitDoorButton(IntentionGrid grid, Random random)
        {
            //get a humble GroundLevel Tile
            var tiles           = grid.GetByMeaning(Meaning.GroundLevel).Where(t => grid.Positions[t.X, t.Y].Intentions.Count == 1).ToList();
            var tile            = tiles[random.Next(0, tiles.Count())];
            var buttonIntention = Intention.ButtonIntention();
            var exit            = grid.GetByMeaning(Meaning.ExitPath).Where(t => grid.Positions[t.X, t.Y].Intentions.Any(i => i.Meaning == Meaning.ToggleDoor)).First().Intentions.Where(i => i.Meaning == Meaning.ToggleDoor).First();

            buttonIntention.RelatedTileMeaning = exit;
            exit.RelatedTileMeaning            = buttonIntention;
            grid.Positions[tile.X, tile.Y].Intentions.Add(Intention.ButtonIntention());

            DebugPrintMeaning(grid, Meaning.Button);
        }
Beispiel #6
0
        public static void CreateBorder(IntentionGrid grid, Random random)
        {
            for (var y = 0; y < grid.Height; y++)
            {
                var str = "";
                for (var x = 0; x < grid.Width; x++)
                {
                    if (
                        (x == 0 || y == 0 || x == grid.Width - 1 || y == grid.Height - 1)
                        &&
                        grid.Positions[x, y].Intentions.Count() == 0
                        )
                    {
                        grid.Positions[x, y].Intentions.Add(Intention.SolidIntention());
                    }
                }
            }

            DebugPrintMeaning(grid, Meaning.Solid);
        }
Beispiel #7
0
        public static void CreateRopeSection(IntentionGrid grid, Random random)
        {
            //TODO - RANDOMIZE THIS

            //get a humble groundlevel tile
            var tiles = grid.GetByMeaning(Meaning.GroundLevel).Where(t => grid.Positions[t.X, t.Y].Intentions.Count == 1).ToList();

            //find 3 in a row
            var middle = tiles.Where(t => tiles.Any(tleft => tleft.Y == t.Y && tleft.X == t.X - 1) && tiles.Any(tright => tright.Y == t.Y && tright.X == t.X + 1)).FirstOrDefault();

            if (middle != null)
            {
                /*for(var x = middle.X -1; x <= middle.X +1; x++)
                 * {
                 *  grid.Positions[x, middle.Y].Intentions.Add(Intention.RopeIntention());
                 * }*/
                grid.Positions[middle.X, middle.Y].Intentions.Add(Intention.RopeIntention());
            }

            DebugPrintMeaning(grid, Meaning.Rope);
        }
Beispiel #8
0
 private static void DebugPrintMeaning(IntentionGrid grid, Meaning meaning)
 {
     //Debug
     Console.WriteLine(meaning.ToString() + ":  ");
     for (var y = 0; y < grid.Height; y++)
     {
         var str = "";
         for (var x = 0; x < grid.Width; x++)
         {
             if (grid.Positions[x, y].Intentions.Any(i => i.Meaning == meaning))
             {
                 str = str + "X";
             }
             else
             {
                 str = str + "-";
             }
         }
         Console.WriteLine(str);
     }
     Console.WriteLine("");
 }
Beispiel #9
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);
        }