Пример #1
0
        public static MazeBase CopyEnvironment(MazeBase environment)
        {
            var converted = new MazeBase
            {
                AdditionalRewards       = environment.AdditionalRewards,
                Columns                 = environment.Columns,
                GetRewardAction         = environment.GetRewardAction,
                GoalPosition            = environment.GoalPosition,
                DefaultActionPunishment = environment.DefaultActionPunishment,
                ObjectiveAction         = environment.ObjectiveAction,
                ObjectiveReward         = environment.ObjectiveReward,
                TerminalStates          = environment.TerminalStates,
                Obstructions            = environment.Obstructions,
                PrioritizeFromState     = environment.PrioritizeFromState,
                QualitySaveDirectory    = environment.QualitySaveDirectory,
                QualitySaveFrequency    = environment.QualitySaveFrequency,
                QualityTable            = environment.CopyQuality(),
                RewardsTable            = environment.RewardsTable,
                Rows           = environment.Rows,
                StatesPerPhase = environment.StatesPerPhase,
                StatesTable    = environment.StatesTable
            };

            return(converted);
        }
Пример #2
0
        private void InitMaze()
        {
            m_CurrentLevel = Mathf.Clamp(m_CurrentLevel, 0, (m_MazePrefabs.Length - 1));

            if (m_Maze != null)
            {
                if (m_Maze.gameObject != null)
                {
                    Destroy(m_Maze.gameObject);
                }
            }

            // Instance maze depending on the current level
            GameObject mazeObj = Instantiate(m_MazePrefabs[m_CurrentLevel], transform);

            m_Maze = mazeObj.GetComponent <MazeBase>();

            if (m_Maze != null)
            {
                // Initialize maze
                m_MazeCurrentRotation = m_Maze.transform.rotation;
                m_MazeNextRotation    = m_Maze.transform.rotation;
                m_MazeCurrentLerpTime = 0.0f;
                m_Maze.DoStart();
                m_Maze.DisableExit();

                m_ItemsCollected = 0;
                //m_MazeGameUI.SetItems(m_ItemsCollected, m_Maze.NumberItems);
            }
        }
        private MazeBase GetTestMaze()
        {
            var maze = new MazeBase(
                _agent.Environment.Columns,
                _agent.Environment.Rows,
                _agent.StartPosition,
                _agent.Environment.GoalPosition,
                _agent.Environment.ObjectiveReward);

            maze.RewardsTable      = _agent.Environment.RewardsTable;
            maze.StatesTable       = _agent.Environment.StatesTable;
            maze.AdditionalRewards = _agent.Environment.AdditionalRewards;



            return(maze);
        }
Пример #4
0
    public void CylinderBuild(Vector3 pos, Vector3 scale)
    {
        MazeObject = InitBuild(pos, scale);

        GameObject MazeBase;

        if (MyFloorPrefab)
        {
            MazeBase = Instantiate(MyFloorPrefab);
        }
        else
        {
            MazeBase = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
        }
        MazeBase.transform.parent        = MazeObject.transform;
        MazeBase.transform.localPosition = new Vector3(0, 0, 0);
        MazeBase.transform.localScale    = new Vector3(((scale.x - 1) / scale.x), ((scale.y - 1) / scale.y) * 0.5f, ((scale.z - 1) / scale.z));
        if (MyFloor)
        {
            MazeBase.GetComponent <Renderer>().material = MyFloor;
        }

        GameObject[] MazeBases = new GameObject[2];
        for (int i = 0; i < 2; i++)
        {
            MazeBases[i] = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            MazeBases[i].transform.parent = MazeObject.transform;
            if (MyFloor)
            {
                MazeBases[i].GetComponent <Renderer>().material = MyFloor;
            }
            MazeBases[i].name = "Floortile";
            MazeBases[i].transform.localScale = new Vector3(1f, (1 / scale.y), 1f);
        }
        float Locposition = 0.5f;

        MazeBases[0].transform.localPosition = new Vector3(0, Locposition, 0);

        MazeBases[1].transform.localPosition = new Vector3(0, -Locposition, 0);

        SearchArray(8);
    }
Пример #5
0
    public void SphereBuild(Vector3 pos, Vector3 scale)
    {
        MazeObject = InitBuild(pos, scale);

        SearchArray(5);
        GameObject MazeBase;

        if (MyFloorPrefab)
        {
            MazeBase = Instantiate(MyFloorPrefab);
        }
        else
        {
            MazeBase = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        }
        MazeBase.transform.parent        = MazeObject.transform;
        MazeBase.transform.localPosition = new Vector3(0, 0, 0);
        MazeBase.transform.localScale    = new Vector3(((scale.x - 1) / scale.x), ((scale.y - 1) / scale.y), ((scale.z - 1) / scale.z));
        if (MyFloor)
        {
            MazeBase.GetComponent <Renderer>().material = MyFloor;
        }
    }
Пример #6
0
    public void BottomFloorBuild(Vector3 pos, Vector3 scale)
    {
        MazeObject = InitBuild(pos, scale);

        SearchArray(2);
        GameObject MazeBase;

        if (MyFloorPrefab)
        {
            MazeBase = Instantiate(MyFloorPrefab);
        }
        else
        {
            MazeBase = GameObject.CreatePrimitive(PrimitiveType.Cube);
        }
        MazeBase.transform.parent     = MazeObject.transform;
        MazeBase.transform.localScale = new Vector3(((scale.x) / scale.x), ((scale.y) / scale.y), ((scale.z) / scale.z));
        if (MyFloor)
        {
            MazeBase.GetComponent <Renderer>().material = MyFloor;
        }


        if (y == 1)
        {
            MazeBase.transform.localPosition = new Vector3(0, -1, 0);
        }
        else if (x == 1)
        {
            MazeBase.transform.localPosition = new Vector3(-1, 0, 0);
        }
        else if (z == 1)
        {
            MazeBase.transform.localPosition = new Vector3(0, 0, -1);
        }
    }
Пример #7
0
        public void GenerateMazePrefab(string nameMaze)
        {
            MazeJSONData mazeJSONData;
            bool         tryLoadMaze = MazeJSONTool.LoadMazeJSON(nameMaze, out mazeJSONData);

            if (tryLoadMaze)
            {
                GameObject obj = new GameObject(nameMaze);
                obj.layer = LayerMask.NameToLayer("Game");
                MazeBase maze = obj.AddComponent <MazeBase>();

                // Maze settings
                MazeSettings mazeSettings = new MazeSettings(mazeJSONData.Columns, mazeJSONData.Rows);
                mazeSettings.NameMaze = nameMaze;
                //mazeSettings.StartPoint = mazeJSONData.StartLocation;
                //mazeSettings.EndPoint = mazeJSONData.EndLocation;

                maze.InitializeMaze(mazeSettings);

                // Create rooms
                Debug.Log("number rooms: " + mazeJSONData.NumberRooms);
                maze.CreateRooms(mazeJSONData.NumberRooms);

                // Create cells
                Debug.Log("number tiles: " + mazeJSONData.ListTiles.Count);
                for (int i = 0; i < mazeJSONData.ListTiles.Count; i++)
                {
                    IVector2 coordsCell = new IVector2(mazeJSONData.ListTiles[i].Coords.Column, mazeJSONData.ListTiles[i].Coords.Row);

                    // Instance cell
                    GameObject goCell = Instantiate(m_CellPrefab);
                    goCell.layer            = LayerMask.NameToLayer("Game");
                    goCell.name             = "Cell_" + coordsCell.Column + "_" + coordsCell.Row;
                    goCell.transform.parent = obj.transform;
                    // Set position tiles
                    goCell.transform.localPosition = new Vector3(coordsCell.Column * m_TileSize, 0.0f, coordsCell.Row * m_TileSize);
                    // Setup index room
                    MazeCell mCell = goCell.GetComponent <MazeCell>();
                    mCell.Coords = coordsCell;

                    // Set type cell
                    mCell.SetTypeCell(mazeJSONData.ListTiles[i].TileType);
                    if (mazeJSONData.ListTiles[i].TileType == MazeCell.ETypeCell.STARTLOCATION)
                    {
                        mazeSettings.StartPoint = coordsCell;
                    }
                    if (mazeJSONData.ListTiles[i].TileType == MazeCell.ETypeCell.ENDLOCATION)
                    {
                        mazeSettings.EndPoint = coordsCell;
                    }



                    /*bool bVisibleTile = true;
                     * if (mazeJSONData.ListTiles[i].IsVisible == 0)
                     * {
                     *  bVisibleTile = false;
                     * }
                     * if (mCell.IsVisible)
                     * {
                     *
                     *  // Set material for start point
                     *  if ((coordsCell.Column == mazeSettings.StartPoint.Column) && (coordsCell.Row == mazeSettings.StartPoint.Row))
                     *  {
                     *      mCell.SetTypeCell(MazeCell.ETypeCell.STARTLOCATION);
                     *  }
                     *
                     *  // Set material for start point
                     *  else if ((coordsCell.Column == mazeSettings.EndPoint.Column) && (coordsCell.Row == mazeSettings.EndPoint.Row))
                     *  {
                     *      mCell.SetTypeCell(MazeCell.ETypeCell.ENDLOCATION);
                     *
                     *  }
                     *  else
                     *  {
                     *      // Check if the coords are in the list of holes
                     *      bool isHole = false;
                     *      for (int iHole = 0; iHole < mazeJSONData.ListHoles.Count; iHole++)
                     *      {
                     *          if ((coordsCell.Column == mazeJSONData.ListHoles[iHole].Coords.Column) && (coordsCell.Row == mazeJSONData.ListHoles[iHole].Coords.Row))
                     *          {
                     *              mCell.SetTypeCell(MazeCell.ETypeCell.HOLE);
                     *              isHole = true;
                     *
                     *              Debug.LogFormat("HOLE DATA: Coords {0}x{1} TypeHole: {2} ConnectedCoords: {3}x{4} ", mazeJSONData.ListHoles[iHole].Coords.Column, mazeJSONData.ListHoles[iHole].Coords.Row, mazeJSONData.ListHoles[iHole].TypeHole, mazeJSONData.ListHoles[iHole].ConnectedCoords.Column, mazeJSONData.ListHoles[iHole].ConnectedCoords.Row);
                     *
                     *              mazeSettings.AddHole(mazeJSONData.ListHoles[iHole]);
                     *              mCell.SetHole(mazeJSONData.ListHoles[iHole]);
                     *              break;
                     *          }
                     *      }
                     *
                     *      if (!isHole)
                     *      {
                     *          mCell.SetTypeCell(MazeCell.ETypeCell.NONE);
                     *      }
                     *  }
                     *
                     *  // Add obstacles
                     *  for (int iObstacle = 0; iObstacle < mazeJSONData.ListObstacles.Count; iObstacle++)
                     *  {
                     *      if ((mCell.Coords.Column == mazeJSONData.ListObstacles[iObstacle].Coords.Column) && (mCell.Coords.Row == mazeJSONData.ListObstacles[iObstacle].Coords.Row))
                     *      {
                     *          // Instance obstacle
                     *          mCell.SetObstacle(mazeJSONData.ListObstacles[iObstacle]);
                     *          break;
                     *      }
                     *  }
                     *
                     * }*/
                    // Add cell to the maze
                    maze.AddCell(mCell);
                }
                // Segup each edge for each cells
                for (int i = 0; i < mazeJSONData.ListTiles.Count; i++)
                {
                    MazeCell currentCell = maze.GetCell(mazeJSONData.ListTiles[i].Coords);

                    if (currentCell.TypeCell != MazeCell.ETypeCell.INVISIBLE)
                    {
                        // Setup each cell
                        for (int iEdge = 0; iEdge < mazeJSONData.ListTiles[i].Edges.Length; iEdge++)
                        {
                            // Gets connected cell with this edge
                            // Gets direction for this edge
                            MazeDirection dir = (MazeDirection)iEdge;

                            IVector2 coordsConnectedCell = mazeJSONData.ListTiles[i].Coords + dir.ToIntVector2();

                            // Get connected cell (it could be null)
                            MazeCell connectedCell = maze.GetCell(coordsConnectedCell);

                            // Get type edge
                            MazeCellEdge.TypeEdgeEnum tEdge = mazeJSONData.ListTiles[i].Edges[iEdge];

                            currentCell.SetEdge(dir, tEdge, connectedCell);
                        }
                    }
                }

#if UNITY_EDITOR
                // Create prefab
                string fileLocation = "Assets/TheMaze/Prefabs/Mazes/" + nameMaze + ".prefab";
                Object emptyObj     = PrefabUtility.CreateEmptyPrefab(fileLocation);

                PrefabUtility.ReplacePrefab(obj, emptyObj, ReplacePrefabOptions.ConnectToPrefab);
#endif
            }
        }