Ejemplo n.º 1
0
    void CheckEnemy()
    {
        NativeArray <bool> result = new NativeArray <bool>(1, Allocator.TempJob);

        result[0] = false;
        CatchJob catchJob = new CatchJob {
            x      = (int)player.x,
            z      = (int)player.z,
            result = result
        };
        JobHandle jobHandle = catchJob.Schedule(this);

        jobHandle.Complete();
        if (result[0])
        {
            DestroyThemAll destroyJob = new DestroyThemAll {
                CommandBuffer = endSimCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
            };
            JobHandle destroyJobHandle = destroyJob.Schedule(this);
            destroyJobHandle.Complete();
            RecursiveBacktracking.StaticReset();
            MenuController.LoadMazeStatic();
        }
        result.Dispose();
    }
Ejemplo n.º 2
0
        public void TestFindSubsetsInDupList()
        {
            var nums = new List <int> {
                2, 1, 2, 2
            };
            var results = RecursiveBacktracking.FindSubsetsInDupList(nums);

            Assert.AreEqual(8, results.Count);
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int>()));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 2, 2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 2, 2, 2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                2, 2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                2, 2, 2
            }));
        }
Ejemplo n.º 3
0
    private void GenerateMaze()
    {
        switch (mazeName)
        {
        case "Backtracking":
        {
            RecursiveBacktracking mazeGenerator = new RecursiveBacktracking(Width, Height);
            CellRB[,] maze = mazeGenerator.GenerateMaze();
            SpawnMaze(maze);
        }
        break;

        case "Sidewinder":
        {
            Sidewinder mazeGenerator = new Sidewinder(Width, Height);
            CellSidewinder[,] maze = mazeGenerator.GenerateMaze();
            SpawnMaze(maze);
        };
            break;

        case "BinaryTree":
        {
            BinaryTree mazeGenerator = new BinaryTree(Width, Height);
            CellBT[,] maze = mazeGenerator.GenerateMaze();
            SpawnMaze(maze);
        }
        break;

        default:
            Debug.Log("Unknown algorithm");
            break;
        }
    }
Ejemplo n.º 4
0
    void BackToMenu()
    {
        DestroyThemAll destroyJob = new DestroyThemAll {
            CommandBuffer = endSimCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        };
        JobHandle destroyJobHandle = destroyJob.Schedule(this);

        destroyJobHandle.Complete();
        RecursiveBacktracking.StaticReset();
        MenuController.LoadMenuStatic();
    }
Ejemplo n.º 5
0
        public void TestGenerateParenthesis()
        {
            var results = RecursiveBacktracking.GenerateParenthesis(3);

            Assert.AreEqual(5, results.Count);
            Assert.IsTrue(results.Contains("((()))"));
            Assert.IsTrue(results.Contains("(()())"));
            Assert.IsTrue(results.Contains("(())()"));
            Assert.IsTrue(results.Contains("()(())"));
            Assert.IsTrue(results.Contains("()()()"));
        }
Ejemplo n.º 6
0
        public void TestFindSubsetsWithTargetSum()
        {
            var nums = new List <int> {
                10, 1, 2, 7, 6, 1, 5
            };
            var results = RecursiveBacktracking.FindSubsetsWithTargetSum(nums, 8);

            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 7
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 2, 5
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                6, 2
            }));
            Assert.IsTrue(RecursiveBacktracking.ContainsSubset(results, new List <int> {
                1, 1, 6
            }));
        }
Ejemplo n.º 7
0
    /*
     *
     * def carve_passages_from(cx, cy, grid)
     * directions = [N, S, E, W].sort_by{rand}
     *
     * directions.each do |direction|
     * nx, ny = cx + DX[direction], cy + DY[direction]
     *
     *      if ny.between ? (0, grid.length-1) && nx.between?(0, grid[ny].length-1) && grid[ny][nx] == 0
     *        grid[cy][cx] |= direction
     *        grid[ny][nx] |= OPPOSITE[direction]
     *        carve_passages_from(nx, ny, grid)
     *      end
     *    end
     *  end
     *
     * */


    private static WorldData create_world_data(Vector2Int spawn, Pool rooms, FlyweightList[] prototypes, float cell_size)
    {
        // Initialise the whole world
        WorldData world_data = new WorldData(Vector3.zero, new Vector2Int(11, 11), 16.0f * cell_size);

        /*
         * int index = 0;
         * for (int x = 0; x < world_data.Count.x; x++)
         * {
         *  for (int y = 0; y < world_data.Count.y; y++)
         *  {
         *      world_data.set(x, y, rooms.get(index));
         *      index++;
         *      if (index >= rooms.Length)
         *          index = 0;
         *  }
         * }
         */

        Vector2Int        current = new Vector2Int(3, 3);
        Vector2Int        prev;
        List <Vector2Int> open_direction = new List <Vector2Int>();

        prev = current;

        var layout = RecursiveBacktracking.build_path(spawn, world_data.Count, 30);

        for (int x = 0; x < layout.GetLength(0); x++)
        {
            for (int y = 0; y < layout.GetLength(1); y++)
            {
                if (layout[x, y])
                {
                    world_data.set(x, y, rooms.get(Random.Range(0, rooms.Length)));
                }
            }
        }

        /*
         * for (int i = 0; i < 12; i++)
         * {
         *  open_direction.Clear();
         *  if (current.x > 0)                      open_direction.Add(new Vector2Int(-1,  0));
         *  if (current.y > 0)                      open_direction.Add(new Vector2Int( 0, -1));
         *  if (current.x < world_data.Count.x - 1) open_direction.Add(new Vector2Int( 1,  0));
         *  if (current.y < world_data.Count.y - 1) open_direction.Add(new Vector2Int( 0,  1));
         *
         *  for (int j = 0; j < open_direction.Count; j++)
         *  {
         *      if((current += open_direction[j]) == prev)
         *      {
         *          open_direction.RemoveAt(j);
         *          break;
         *      }
         *  }
         *
         *  current += open_direction[Random.Range(0, open_direction.Count)];
         *
         *
         *  world_data.set(current.x, current.y, rooms.get(0));
         *  prev = current;
         * }
         */
        return(world_data);
    }