public override async void GenerateMaze()
        {
            var totalVisited = 0;

            while (totalVisited < Mazes.MazeWidth * Mazes.MazeHeight - 1)
            {
                await Mazes.PaintUpdate();

                var point = Mazes.RNG.Next(Cardinal.Length) % Cardinal.Length;
                (var row, var col) = Direction(current.Row, current.Col, Cardinal[point]);

                if ((row, col) != (-1, -1))
                {
                    if (!Mazes.Cells[row, col].Visited)
                    {
                        current = Forge(current.Row, current.Col, row, col, point);
                        totalVisited++;
                    }
                    else
                    {
                        current = Mazes.Cells[row, col];
                    }
                }

                Mazes.Current = current;
            }

            await Mazes.PaintUpdate(true);
        }
Example #2
0
        public SolutionDetails <Direction> SolveMaze(string name, int algo)
        {
            SolutionDetails <Direction>    sol_det;
            Searcher <Position, Direction> s;

            if (Sol.TryGetValue(name, out sol_det))
            {
                return(sol_det);
            }
            Maze maze;

            Mazes.TryGetValue(name, out maze);
            if (maze == null)
            {
                return(null);
            }
            if (algo == BFS)
            {
                s = new BestFS();
            }
            else
            {
                s = new DFS();
            }

            sol_det = s.search(new SearchableMaze(maze));
            //sol_det = new SolutionDetails<Direction>(s.search(new SearchableMaze(maze)), s.getNumberOfNodesEvaluated());
            Sol.Add(name, sol_det);
            return(sol_det);
        }
        public MainWindow()
        {
            InitializeComponent();

            _center = (_size - 1) / 2;

            // "Tabulka" pro vykreslování bludiště
            for (int j = 0; j < _size; j++)
            {
                GridMap.ColumnDefinitions.Add(new ColumnDefinition());
                GridMap.RowDefinitions.Add(new RowDefinition());
            }
            this._currentX = _center;
            this._currentY = _center;

            this._knowLocations = new MainModel[_size, _size];
            this._connector     = new MainConnector();
            this._currentMaze   = Mazes.Small;
            this._allRequests   = new List <MainModel>();

            this._buttons = new[] {
                BtnUp,
                BtnDown,
                BtnRight,
                BtnLeft,
                //BtnChange,
                BtnReset,
                //BtnGrab,
                //BtnLeave
            };

            // Zobrazit načítání
            ChangeLoading(true);
        }
Example #4
0
        /// <summary>
        /// Returns a maze by its name
        /// </summary>
        /// <param name="name">Maze name</param>
        /// <returns>Maze or null</returns>
        public Maze GetMaze(string name)
        {
            if (string.IsNullOrEmpty(name) || !Mazes.ContainsKey(name))
            {
                return(null);
            }

            return(Mazes[name]);
        }
Example #5
0
 public bool SetPixel(Mazes.Point p, Color color)
 {
     try
     {
         this.mazeBmp.SetPixel(p.X, p.Y, color);
         return true;
     }
     catch { return false; }
 }
Example #6
0
        /// <summary>
        /// Removes a maze by its name
        /// </summary>
        /// <param name="name">Name of the maze</param>
        public void RemoveMaze(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            Mazes.Remove(name);
        }
Example #7
0
 public Color GetPixel(Mazes.Point p)
 {
     try
     { return this.mazeBmp.GetPixel(p.X, p.Y); }
     catch
     {
         return Color.Pink;
     }
 }
Example #8
0
        /// <summary>
        /// Clears the dungeon
        /// </summary>
        public void Clear()
        {
            foreach (Maze maze in Mazes.Values)
            {
                maze.Dispose();
            }
            Mazes.Clear();

            StartLocation = new DungeonLocation(StartLocation);
        }
Example #9
0
        public override async void GenerateMaze()
        {
            Mazes.Cell Choose(bool visited)
            {
                var chosen = new Mazes.Cell(-1, -1);

                do
                {
                    chosen = Mazes.Cells[Mazes.RNG.Next(Mazes.MazeHeight), Mazes.RNG.Next(Mazes.MazeWidth)];
                } while (chosen.Visited == visited || chosen == current);

                return(chosen);
            }

            var totalVisited = 0;

            current         = Choose(true);
            current.Visited = true;
            var initial = new Mazes.Cell(-1, -1);

            while (totalVisited < Mazes.MazeWidth * Mazes.MazeHeight - 1)
            {
                await Mazes.PaintUpdate();

                var chosen = Choose(true);
                var first  = Mazes.Cells[chosen.Row, chosen.Col];

                while (!chosen.Visited)
                {
                    await Mazes.PaintUpdate();

                    (var row, var col) = (-1, -1);

                    do
                    {
                        (row, col) = Direction(chosen.Row, chosen.Col, Cardinal[directions[chosen.Row, chosen.Col] = Mazes.RNG.Next(Cardinal.Length)]);
                    } while ((row, col) == (-1, -1));

                    Mazes.Current = initial = chosen = Mazes.Cells[row, col];
                }

                chosen = Mazes.Cells[first.Row, first.Col];

                while (chosen != initial)
                {
                    await Mazes.PaintUpdate();

                    (var row, var col) = Direction(chosen.Row, chosen.Col, Cardinal[directions[chosen.Row, chosen.Col]]);
                    Mazes.Current      = chosen = Forge(chosen.Row, chosen.Col, row, col, directions[chosen.Row, chosen.Col]);
                    totalVisited++;
                }
            }

            await Mazes.PaintUpdate(true);
        }
Example #10
0
        } //Execute()



        public bool PeekBlock(Mazes.Point p)
        {
            try
            {
                return Main.tile[p.X, p.Y].active();
            }
            catch
            {
                TShock.Players[plr].SendMessage(String.Format("Solve is having a bad problem!! Server crash may be imminent!"), Color.Red);
                return false;
            }
        }
Example #11
0
 void pop_floor(Mazes maze, Vector3 pos)
 {
     for (int z = 0; z < maze.floor.GetLength(0) && generateFloors; z++)
     {
         for (int x = 0; x < maze.floor.GetLength(1); x++)
         {
             if (maze.floor[z, x])
             {
                 pop_maze_part(floor, new Vector3(x * dim + div_dim + pos.x, pos.y, z * dim + div_dim + pos.z), Quaternion.identity);
             }
         }
     }
 }
Example #12
0
 public void generate(bool rand_exits, bool rand_floor_exits)
 {
     for (int i = 0; i < m_height; i++)
     {
         maze[i] = new Mazes(m_depth, m_width, m_nb_holes, m_nb_holes_in_walls);
         maze[i].generate(rand_exits, rand_floor_exits);
     }
     for (int w = 0; w < m_depth; w++)
     {
         for (int d = 0; d < m_width; d++)
         {
             roof[w, d] = true;
         }
     }
 }
Example #13
0
    void Start()
    {
        converterInst = GetComponent <GraphToMaze>();
        if (makeMaze)
        {
            return;//will be drawn on second frame anyway
        }
        //Graph g = Mazes.PrimPath(width, height);
        Graph g = Mazes.DfsPath(width, height);

        //Graph g = Mazes.BfsPath(width, height);
        //Graph g = Mazes.BaseGraph(10, 10);
        converterInst.MakeWalls(g, width, height, (0, 0));
        DisplayGraph(g);
    }
Example #14
0
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            Maze m;

            if (Mazes.ContainsKey(name))
            {
                return(null);
            }
            else
            {
                IMazeGenerator mg = new DFSMazeGenerator();
                m = mg.Generate(rows, cols);
                return(m);
            }
        }
Example #15
0
        public static void GenerateRules(MonoRandom rng)
        {
            if (_rng != null && _rng.Seed == rng.Seed)
            {
                return;
            }
            _rng = rng;

            Mazes.Clear();
            for (int i = 0; i < 10; i++)
            {
                var maze = new Maze();
                Mazes.Add(maze);
                maze.BuildMaze(rng);
            }
        }
        public static void GenerateRules(MonoRandom rng)
        {
            if (_rng != null && _rng.Seed == rng.Seed)
            {
                return;
            }
            _rng = rng;

            Mazes.Clear();
            for (var i = 0; i < 18; i++)
            {
                var maze = new Maze();
                Mazes.Add(maze);
                maze.BuildMaze(rng);
            }

            var words = new List <string>(PossibleWords);

            words.AddRange(ExtendedWords);

            // Choose 8 base words
            var numBaseWords = 18;
            var chosenWords  = words.OrderBy(x => rng.NextDouble()).Take(numBaseWords).ToList();

            Debug.LogFormat("[Morse Code Rule Seed Generator] + Base words: {0}", string.Join(", ", chosenWords.ToArray()));

            // Find other words that are similar to these (low cycling Levenshtein distance)
            for (var i = 0; i < numBaseWords && chosenWords.Count < 36; i++)
            {
                var prefix = chosenWords[i].Substring(1);
                var toAdd  = words
                             .Where(w => !chosenWords.Contains(w) && !w.EndsWith(prefix))
                             .Select(w => (new { word = w, pref = rng.NextDouble(), dist = Similarity(w, chosenWords[i]) }))
                             .ToList();
                toAdd.Sort((a, b) =>
                {
                    var r = a.dist - b.dist;
                    return(r == 0 ? Math.Sign(a.pref - b.pref) : r);
                });
                var howmany = Math.Min(Math.Min(rng.Next(1, 4), 36 - chosenWords.Count), toAdd.Count);
                Debug.LogFormat(@"[Password rule seed] From {0}, adding words: {1}", chosenWords[i], string.Join(", ", toAdd.Take(howmany).Select(w => string.Format("{0}/{1}/{2}", w.word, w.dist, w.pref)).ToArray()));
                chosenWords.AddRange(toAdd.Take(howmany).Select(inf => inf.word));
            }

            Words.Clear();
            Words.AddRange(chosenWords.Take(36).OrderBy(x => rng.NextDouble()));
        }
Example #17
0
        public bool PeekPixel(Mazes.Point p)
        {
            Color color;
            try
            {
                color = this.mazeBmp.GetPixel(p.X, p.Y);
            }
            catch
            {
                return false;
            }
            //bool r = (color.Name == "ff000000");
            bool r = (color.ToArgb() == wallColor.ToArgb());

            //toolbarLabel1.Text = color.ToString() + "     PeekPixel = " + r;
            return r;
        }
        public async Task <UniversalResult> SendData(Actions action, Mazes size, int tryNo = 1)
        {
            if (tryNo > 5)
            {
                // Ani na 5. pokus požadavek neprošel
                return(new UniversalResult(new ApplicationException("Nezdařilo se získat data, příliš mnoho pokusů.")));
            }

            var url = SmallMazeUrl;

            if (size == Mazes.Large)
            {
                url = LargeMazeUrl;
            }

            var actionString = action.ToString().ToLower();

            // Nastavení dat k odeslání
            var data = new {
                // hodnoty
                token   = TokenKey,
                command = actionString
            };

            // Časový limit
            var request = url.WithTimeout(Timeout);
            //.AllowHttpStatus(HttpStatusCode.NotFound)

            MainModel model;

            try {
                // Získání dat
                model = await request.PostUrlEncodedAsync(data).ReceiveJson <MainModel>();
            } catch (FlurlHttpTimeoutException) {
                // Vypršel časový limit požadavku
                return(new UniversalResult(new TimeoutException("Špatné připojení k internetu")));
            } catch (FlurlHttpException) {
                // Počkat 20 ms
                await Task.Delay(20);

                // Zkusit to znovu
                return(await SendData(action, size, tryNo + 1));
            }

            return(new UniversalResult(model));
        }
Example #19
0
        /// <summary>
        /// create a maze, save and return it
        /// </summary>
        /// <param name="name">the name of the maze</param>
        /// <param name="rows">num of rows</param>
        /// <param name="cols">num of column</param>
        /// <returns></returns>
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            Maze m;

            if (Mazes.ContainsKey(name))
            {
                //print error - this maze exist
                return(null);
            }
            else
            {
                IMazeGenerator mg = new DFSMazeGenerator();
                m      = mg.Generate(rows, cols);
                m.Name = name;
                this.Mazes.Add(name, m);
                return(m);
            }
        }
Example #20
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            foreach (Maze maze in Mazes.Values)
            {
                maze.Dispose();
            }
            Mazes.Clear();

            if (ItemTileSet != null)
            {
                ItemTileSet.Dispose();
            }
            ItemTileSet = null;

            StartLocation = null;
            Note          = "";

            IsDisposed = true;
        }
Example #21
0
    private OnActivate Activate()
    {
        return(() =>
        {
            var colors = Colors.GetFinal;
            var word = Words.GetRandom;
            new IEnum <Color[], string>(Flash, this).StartCoroutine(colors, word.Key);
            var maze = Mazes.Get(word.Value, colors[2], colors[4]);

            _position = _initialPosition = maze.Find(colors[0]);
            _order = Words.GetOrder(colors[6], word.Value.Item2);
            _initialMaze = maze.InsertBones();

            _maze = new String[_initialMaze.Length];
            _initialMaze.Copy(_maze);

            _order.ToLog(this);
            _maze.ToLog(this, _position);
        });
    }
Example #22
0
 void pop_corner(Mazes maze, Vector3 pos)
 {
     for (int z = 1; z < maze.floor.GetLength(0) && generateCorners; z++)
     {
         for (int x = 1; x < maze.floor.GetLength(1); x++)
         {
             if (optimiseCorners == true && x < maze.floor.GetLength(1) && z < maze.floor.GetLength(0))
             {
                 if (x == 0 || (maze.h_wall[z, x] && maze.h_wall[z, x - 1]))
                 {
                     continue;
                 }
                 if (z == 0 || (maze.v_wall[z, x] && maze.v_wall[z - 1, x]))
                 {
                     continue;
                 }
             }
             pop_maze_part(corner, new Vector3(x * dim + pos.x, pos.y + wallHeight / 2, z * dim + pos.z), Quaternion.identity);
         }
     }
 }
Example #23
0
    private void Update()
    {
        if (makeMaze)
        {
            makeMaze = false;

            if (mazeSettings.grid)
            {
                Graph grid = Mazes.BaseGraph(width, height);
                DisplayGraph(grid);
                converterInst.MakeWalls(grid, width, height, (0, 0));
            }
            if (mazeSettings.dfs)
            {
                Graph dfs = Mazes.DfsPath(width, height);
                //Graph dfs = Mazes.DfsIter(width, height);
                DisplayGraph(dfs);
                converterInst.MakeWalls(dfs, width, height, (0, 0));
            }
            if (mazeSettings.prims)
            {
                Graph prims = Mazes.PrimPath(width, height);
                DisplayGraph(prims);
                converterInst.MakeWalls(prims, width, height, (0, 0));
            }
            if (mazeSettings.bfs)
            {
                Graph path = Mazes.BfsPath(width, height);
                DisplayGraph(path);
                converterInst.MakeWalls(path, width, height, (0, 0));
            }

            if (!(mazeSettings.dfs || mazeSettings.prims || mazeSettings.grid || mazeSettings.bfs))
            {
                Graph nuall = Mazes.DefaultPath(width, height);
                DisplayGraph(nuall);
                converterInst.MakeWalls(nuall, width, height, (0, 0));
            }
        }
    }
Example #24
0
        public override async void GenerateMaze()
        {
            while (true)
            {
                await Mazes.PaintUpdate();

                (var row, var col) = (current.Row, current.Col);
                var adjacent = Adjacent(row, col);

                if (adjacent == -1)
                {
                    for (var r = 0; r < Mazes.MazeHeight; r++)
                    {
                        for (var c = 0; c < Mazes.MazeWidth; c++)
                        {
                            (row, col) = (r, c);

                            if (Mazes.Cells[row, col].Visited)
                            {
                                adjacent = Adjacent(row, col);

                                if (adjacent != -1)
                                {
                                    goto Path;
                                }
                            }
                        }
                    }

                    break;
                }

Path:
                (var newRow, var newCol) = Direction(row, col, Cardinal[adjacent]);
                Mazes.Current            = current = Forge(row, col, newRow, newCol, adjacent);
            }

            await Mazes.PaintUpdate(true);
        }
Example #25
0
    protected override void OnActivate()
    {
        isColorblind = Get <KMColorblindMode>().ColorblindModeActive;

        Arrows.Assign(onInteract: ArrowsInteract);
        Center.Assign(onInteract: CenterInteract);

        var colors = Colors.GetFinal;
        var word   = Words.GetRandom;
        var maze   = Mazes.Get(word.Value, colors[2], colors[4]);

        StartCoroutine(Flash(colors, word.Key));

        _position    = _initialPosition = maze.Find(colors[0]);
        _order       = Words.GetOrder(colors[6], word.Value.Item2);
        _initialMaze = maze.InsertBones();

        _maze = new String[_initialMaze.Length];
        _initialMaze.Copy(_maze);

        _order.ToLog(this);
        _maze.ToLog(this, _position);
    }
Example #26
0
 void pop_maze_2d(Mazes maze, Vector3 pos)
 {
     for (int z = 0; z < maze.h_wall.GetLength(0); z++)
     {
         for (int x = 0; x < maze.h_wall.GetLength(1); x++)
         {
             if (maze.h_wall[z, x])
             {
                 pop_maze_part(horizontalWall, new Vector3(x * dim + div_dim + pos.x, pos.y + wallHeight / 2.0F, z * dim + pos.z), Quaternion.identity);
             }
         }
     }
     for (int z = 0; z < maze.v_wall.GetLength(0); z++)
     {
         for (int x = 0; x < maze.v_wall.GetLength(1); x++)
         {
             if (maze.v_wall[z, x])
             {
                 pop_maze_part(verticalWall, new Vector3(x * dim + pos.x, pos.y + wallHeight / 2.0F, z * dim + div_dim + pos.z), Quaternion.identity);
             }
         }
     }
 }
Example #27
0
        public void PrintPathTest()
        {
            int   col;
            int   row;
            int   maxMoves;
            Mazes maze = new Mazes();

            col = maze.arrRowColDirection[0];
            row = maze.arrRowColDirection[1];

            row = Mazes.lab.GetLength(0);
            col = Mazes.lab.GetLength(1);
            if (col * row < 0)
            {
                Console.WriteLine("The Labyrinth is incorrect");
                Assert.Fail();
            }
            char first;

            first    = maze.arrDir[1];
            maxMoves = (col * row) - 1;



            // char [,] lab = maze.getLabValues();

            // int [] path = maze.FindPath(5,9,'L') ;
            //  Assert.AreEqual(14, Mazes.FindPath(0,0,'L'));

            //foreach (var item in path)
            //{
            //    Console.WriteLine(item);
            //}

            //  Assert.Fail();
        }
Example #28
0
 public void DrawWire(Mazes.Point p)
 {
     Main.tile[p.X, p.Y].wire(true);
 }
 private async Task ChangeMaze(Mazes newMaze)
 {
     _currentMaze = newMaze;
     await this.Reset();
 }
        public override void CreateRules()
        {
            if (!Initialized)
            {
                throw new Exception("You must initialize the Random number generator first");
            }

            Mazes.Clear();
            switch (Seed)
            {
            case 1:
                for (var i = 0; i < 9; i++)
                {
                    var maze = new Maze();
                    Mazes.Add(maze);
                    maze.BuildMaze(NextMinMax);
                }
                InitializeRNG(2);
                Seed = 1;
                var list = new List <Maze>();
                for (var i = 0; i < 9; i++)
                {
                    var maze = new Maze();
                    list.Add(maze);
                    maze.BuildMaze(NextMinMax);
                }
                Mazes.Add(list[2]);
                Mazes.Add(list[3]);
                Mazes.Add(list[8]);
                Mazes.Add(list[6]);
                Mazes.Add(list[1]);
                Mazes.Add(list[0]);
                Mazes.Add(list[4]);
                Mazes.Add(list[5]);
                Mazes.Add(list[7]);
                break;

            case 2:
                for (var i = 0; i < 9; i++)
                {
                    new Maze().BuildMaze(NextMinMax);     //Burn the first 9 mazes out of seed 2. Seed 1 ruleset already used them.
                }
                for (var i = 0; i < 18; i++)
                {
                    var maze = new Maze();
                    Mazes.Add(maze);
                    maze.BuildMaze(NextMinMax);
                }
                break;

            default:
                for (var i = 0; i < 18; i++)
                {
                    var maze = new Maze();
                    Mazes.Add(maze);
                    maze.BuildMaze(NextMinMax);
                }
                break;
            }
            RulesGenerated = true;
        }
Example #31
0
 private bool TestPointForTunnel(Mazes.Point p)
 { // check that the point is within the selected area, and is active (has a tile on it)
     Mazes.Rect r = new Mazes.Rect(x, y, x2 - (this.totalWidth * 2), y2 - (this.totalWidth * 2));
     return (r.PointInRect(p) && Main.tile[p.X, p.Y].active());
 }
 public Task <UniversalResult> Reset(Mazes size)
 {
     return(this.SendData(Actions.Reset, size));
 }
Example #33
0
 public bool NukeTiles(Mazes.Rect r)
 {
     for (int i = r.p.X; i < r.p.X + r.offset.X; i++)
     {
         for (int j = r.p.Y; j < r.p.Y + r.offset.Y; j++)
         {
             Main.tile[i, j].active(false);
             Main.tile[i, j].type = 0;
             //Main.tile[i, j].lava = false;
             //Main.tile[i, j].liquid = 0;
             //Main.tile[i, j].wall = 0;
             //Main.tile[i, j].wire = false;
         }
     }
     return true;
 }
Example #34
0
        } //Execute()



        public bool PeekBlock(Mazes.Point p)
        {
            return Main.tile[p.X, p.Y].active();
        }