Esempio n. 1
0
    void Start()
    {
        /*
         * Brick b1 = new Brick(3, 1);
         * Brick b2 = new Brick(2, 2);
         * //Brick b3 = new Brick(3, 1);
         *
         * Structure s = new Structure(4, 4, 4);
         *
         * s.AddBrick(b1, 1, 1, 0, Direction.NORTH);
         * s.AddBrick(b2, 0, 0, 0, Direction.NORTH);
         * //s.AddBrick(b3, -1, 3, 0, Direction.NORTH);
         *
         * foreach(Brick piece in s.Pieces) {
         *  int[][] bounds = piece.GetBounds();
         *  Debug.LogFormat("Bounds: ({0}, {1}) to ({2}, {3})", bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]);
         * }
         */

        //Random.InitState(12345);
        StructureGenerator sg = new StructureGenerator();

        sg.Generate();
        List <int[]> pages = sg.GetManualPages();

        int[] page = pages[0];

        printArray(page, 8);
        printArray(page.Rotate(1, 8, 8), 8);
        printArray(page.Rotate(2, 8, 8), 8);
        printArray(page.Rotate(3, 8, 8), 8);

        /*
         * for (int i = 0; i < 10; i++) {
         *  for (int j = 0; j < 10; j++) {
         *      Debug.LogFormat("i={0} j={1}", i, j);
         *      if (i == 3 && j == 5) {
         *          goto label1;
         *      }
         *      if (i == 7 && j == 2) {
         *          goto label2;
         *      }
         *      if (i == 9 && j == 3) {
         *          goto label3;
         *      }
         *      label1:;
         *  }
         *  label2:;
         * }
         * label3:
         * Debug.Log("DONE");
         */
    }
Esempio n. 2
0
        public GridMap Build(int width, int height)
        {
            var structure = StructureGenerator.Generate(width, height);

            return(GridMapGenerator.Generate(structure));
        }
Esempio n. 3
0
    void GenerateCluster(Vector3 center)
    {
        // Is this... insane?
        StructureGenerator gen = this.GetComponent(typeof(StructureGenerator)) as StructureGenerator;

        for (int i = 0; i < NumStructures; i++)
        {
            LevelStructure structure = gen.Generate(1.0f, null);
            gen.CurrentGenerated = null; // look at me. I'm the owner now.

            if (structure.structurePerturbations.HasFlag(StructurePerturbations.RotateSpherical))
            {
                if (UnityEngine.Random.value < 0.5f)
                {
                    // Apply a fun perturbation. Maybe this should be in the structure generation?
                    // https://docs.unity3d.com/ScriptReference/Random-rotation.html just, like, purely random?
                    // Ah this is nice:https://www.youtube.com/watch?v=paJPbqpQIQc&feature=emb_logo
                    Vector3 perturbation = UnityEngine.Random.insideUnitSphere; // between -1 and 1, apparently.
                    perturbation *= 10;
                    structure.transform.Rotate(perturbation);
                }
            }
            else if (structure.structurePerturbations.HasFlag(StructurePerturbations.RotateOverY))
            {
                float coin = UnityEngine.Random.value;
                // Let's flip 90 degrees
                if (coin < 0.4f)
                {
                    structure.transform.Rotate(0, 90, 0);
                }
                else if (coin < 0.5)
                {
                    structure.transform.Rotate(0, UnityEngine.Random.Range(-179f, 180f), 0);
                }
            }

            //var structure = structurePrefabs.PickRandom<LevelStructure>().GenerateClone();

            structure.transform.parent = transform;
            int bailCount = 0;
            do
            {
                var newVector = 30 * UnityEngine.Random.insideUnitSphere;
                newVector.x *= 2;
                newVector   += center;
                structure.transform.position = newVector;
                Debug.Log("ITERATING");

                Physics.SyncTransforms();

                if (bailCount++ > 100)
                {
                    break;
                }

                //} while (CollidesWithExistingObject(structure));
                float radius = CenteredBalloonRadius(structure, structure.transform.childCount);
                Debug.Log("Found radius: " + radius);
            } while (CollidesWithExistingObject(structure) && CenteredBalloonRadius(structure, structure.transform.childCount) < 15);

            Debug.Log("ADDED!" + structure.transform.position);
            generatedStructures.Add(structure);
        }
    }
Esempio n. 4
0
    // Setup Methods

    private void Start()
    {
        modSettings = JsonConvert.DeserializeObject <Settings>(ModSettings.Settings);

        PAGE_ROTATIONS_ENABLED           = modSettings.pageRotationsEnabled;
        SOLUTION_TRANSFORMATIONS_ENABLED = modSettings.solutionTransformationsEnabled;

        // Initialize Independent Variables
        Submission           = new int[GridButtons.Length];
        PageDisplayTimer     = Time.time;
        CurrentPage          = 0;
        CurrentColor         = 1;
        ManualPageDisplayTop = true;
        ModuleID             = ModuleIDCounter++;

        // Setup Buttons
        for (int i = 0; i < GridButtons.Length; i++)
        {
            int j = i;
            GridButtons[i].OnInteract += delegate { HandleGridPress(j); return(false); };
        }
        for (int i = 0; i < ColorButtons.Length; i++)
        {
            int j = i;
            ColorButtons[i].OnInteract += delegate { HandleColorPress(j); return(false); };
        }
        LeftButton.OnInteract   += delegate { HandlePageTurnPress(0); return(false); };
        RightButton.OnInteract  += delegate { HandlePageTurnPress(1); return(false); };
        SubmitButton.OnInteract += delegate { HandleSubmit(); return(false); };

        // Puzzle and Solution Generator
        // StructureGenerator gen = new StructureGenerator(10, new int[] { 8, 8, 8 }); // [OLD VERSION]
        StructureGenerator gen = new StructureGenerator(6, new int[] { 8, 8, 8 });

        SolutionStructure     = gen.Generate();
        SolutionPieceDisplays = gen.GetPieceDisplays(true);
        for (int i = 0; i < SolutionStructure.Pieces.Count; i++)
        {
            Brick piece = SolutionStructure.Pieces[i];
            Debug.LogFormat("[LEGO #{0}] Piece #{1}: Position: ({2}, {3}, {4}), Dimensions: {5}x{6}, Rotation: {7}, Color: {8}", ModuleID, i, piece.Position[0], piece.Position[1], piece.Position[2], piece.Dimensions[0], piece.Dimensions[1], piece.Facing, Colors[piece.BrickColor + 1].name);
        }

        Debug.LogFormat("[LEGO #{0}] Instruction Rotations are {1}.", ModuleID, PAGE_ROTATIONS_ENABLED ? "enabled" : "disabled");
        Debug.LogFormat("[LEGO #{0}] Solution Rotations are {1}.", ModuleID, SOLUTION_TRANSFORMATIONS_ENABLED ? "enabled" : "disabled");

        // Setup Instruction Pages
        if (PAGE_ROTATIONS_ENABLED)
        {
            PageRotations = new Direction[] {
                BombInfo.IsIndicatorOn(Indicator.NSA) ? Direction.NORTH : Direction.SOUTH,
                BombInfo.GetSerialNumberLetters().Any(x => "AEIOU".Contains(x)) ? Direction.EAST : Direction.WEST,
                BombInfo.GetPortCount(Port.RJ45) > 0 ? Direction.WEST : Direction.EAST,
                BombInfo.GetPortPlates().Any(x => x.Length == 0) ? Direction.SOUTH : Direction.NORTH,
                BombInfo.GetPortCount(Port.Parallel) == 0 ? Direction.SOUTH : Direction.NORTH,
                BombInfo.GetBatteryCount(Battery.D) > 3 ? Direction.WEST : Direction.EAST,
                BombInfo.IsIndicatorOff(Indicator.BOB) ? Direction.NORTH : Direction.SOUTH,
                BombInfo.IsIndicatorOn(Indicator.CAR) ? Direction.EAST : Direction.WEST,
                BombInfo.GetBatteryHolderCount() < 2 ? Direction.NORTH : Direction.SOUTH,
                BombInfo.GetSerialNumberNumbers().Count() == 3 ? Direction.WEST : Direction.EAST
            };
            Debug.LogFormat("[LEGO #{0}] Instruction Rotations (indexed by: page # mod 10): {1}", ModuleID, string.Join(", ", PageRotations.Select(x => x.ToString()).ToArray()));

            SolutionManualPages           = gen.GetManualPages(true).AsEnumerable().Select((x, i) => x.Rotate((int)PageRotations[i % 10], 8, 8)).ToList();
            SolutionManualPagesBottomOnly = gen.GetManualPages(false).AsEnumerable().Select((x, i) => x.Rotate((int)PageRotations[i % 10], 8, 8)).ToList();
        }
        else
        {
            SolutionManualPages           = gen.GetManualPages(true);
            SolutionManualPagesBottomOnly = gen.GetManualPages(false);
        }
        for (int i = 0; i < SolutionManualPages.Count; i++)
        {
            Debug.LogFormat("[LEGO #{0}] Manual Page {1} w/ top:\n{2}", ModuleID, i + 1, string.Join("\n", string.Join("", SolutionManualPages[i].Select(x => ColorSymbols[x]).ToArray()).SplitInGroups(8).Reverse().ToArray()));
            Debug.LogFormat("[LEGO #{0}] Manual Page {1} w/o top:\n{2}", ModuleID, i + 1, string.Join("\n", string.Join("", SolutionManualPagesBottomOnly[i].Select(x => ColorSymbols[x]).ToArray()).SplitInGroups(8).Reverse().ToArray()));
        }

        // Setup Solution
        Brick yellowPiece = SolutionStructure.Pieces.Find(x => x.BrickColor == 5);

        /* [OLD VERSION]
         * SolutionFace = SolutionStructure.Pieces.Count(x => x.Dimensions[0] * x.Dimensions[1] == 6) >= 5 ? 1 :
         *             yellowPiece.Dimensions[0] * yellowPiece.Dimensions[1] == 3 ? 0 :
         *             SolutionManualPages.Count >= 10 ? 1 : 0;
         */
        SolutionFace = SolutionStructure.Pieces.Count(x => x.Dimensions[0] * x.Dimensions[1] == 6) >= 3 ? 1 :
                       yellowPiece.Dimensions[0] * yellowPiece.Dimensions[1] == 3 ? 0 :
                       SolutionManualPages.Count >= 7 ? 1 : 0;
        Debug.LogFormat("[LEGO #{0}] Solution Face: {1}", ModuleID, SolutionFace == 0 ? "BOTTOM" : "TOP");
        if (SOLUTION_TRANSFORMATIONS_ENABLED)
        {
            /* [OLD VERSION]
             * SolutionRotation = SolutionStructure.Pieces.Find(x => x.BrickColor == 1).Dimensions.SequenceEqual(SolutionStructure.Pieces.Find(x => x.BrickColor == 4).Dimensions) ? Direction.WEST :
             *                 SolutionStructure.Pieces.Max(x => x.Position[2]) > 2 ? Direction.NORTH :
             *                 SolutionStructure.Pieces.Find(x => x.BrickColor == 6).Position[2] > SolutionStructure.Pieces.Find(x => x.BrickColor == 0).Position[2] ? Direction.EAST : Direction.SOUTH;
             */
            SolutionRotation = SolutionStructure.Pieces.Find(x => x.BrickColor == 1).Dimensions.SequenceEqual(SolutionStructure.Pieces.Find(x => x.BrickColor == 4).Dimensions) ? Direction.WEST :
                               SolutionStructure.Pieces.Max(x => x.Position[2]) > 2 ? Direction.NORTH :
                               SolutionStructure.Pieces.Find(x => x.BrickColor == 2).Position[2] > SolutionStructure.Pieces.Find(x => x.BrickColor == 0).Position[2] ? Direction.EAST : Direction.SOUTH;
            Debug.LogFormat("[LEGO #{0}] Solution Rotation: {1}", ModuleID, SolutionRotation);
        }
        else
        {
            SolutionRotation = Direction.NORTH;
        }
        if (SolutionFace == 0)
        {
            if (SolutionRotation == Direction.EAST)
            {
                SolutionRotation = Direction.WEST;
            }
            else if (SolutionRotation == Direction.WEST)
            {
                SolutionRotation = Direction.EAST;
            }
        }
        SolutionDisplay = gen.GetSolutionDisplay(SolutionFace).Rotate((int)SolutionRotation, 8, 8);
        Debug.LogFormat("[LEGO #{0}] Solution:\n{1}", ModuleID, string.Join("\n", string.Join("", SolutionDisplay.Select(x => ColorSymbols[x]).ToArray()).SplitInGroups(8).Reverse().ToArray()));

        // Module Setup
        BombModule.OnActivate += delegate { ActivateModule(); };

        // Post-Setup Initialization
        MaxPages = SolutionManualPages.Count + 2;
    }