Esempio n. 1
0
    // -----
    // Puzzle generation
    // -----

    void GeneratePuzzle()
    {
        int digit;

        for (int x = 0; x < 3; ++x)
        {
            digit = RNG.Range(0, 8);
            vexes[x].SetFace(2, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[x].SetFace(0, digit, colorMeshes[digit]);
            vexes[x + 3].SetFace(2, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[x + 3].SetFace(0, digit, colorMeshes[digit]);
            vexes[x + 6].SetFace(2, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[x + 6].SetFace(0, digit, colorMeshes[digit]);
        }
        for (int y = 0; y < 9; y += 3)
        {
            digit = RNG.Range(0, 8);
            vexes[y].SetFace(1, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[y].SetFace(3, digit, colorMeshes[digit]);
            vexes[y + 1].SetFace(1, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[y + 1].SetFace(3, digit, colorMeshes[digit]);
            vexes[y + 2].SetFace(1, digit, colorMeshes[digit]);
            digit = RNG.Range(0, 8);
            vexes[y + 2].SetFace(3, digit, colorMeshes[digit]);
        }

        // Scramble the pieces now that we've generated the solution.
        List <int> vexPositions = new List <int> {
            0, 1, 2, 3, 4, 5, 6, 7, 8
        };

        vexPositions.Shuffle();
        for (int i = 0; i < 9; ++i)
        {
            vexes[i].idealPosition = i;
            vexes[i].SetPosition(vexPositions[i]);
        }

        // Logging
        Debug.LogFormat("[TetraVex #{0}] Intended solution:", thisLogID);
        for (int i = 0; i < 9; i += 3)
        {
            string[] log = VexBlock.BlockLineToStrings(vexes[i], vexes[i + 1], vexes[i + 2]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[0]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[1]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[2]);
            if (i < 6)
            {
                Debug.LogFormat("[TetraVex #{0}] ───┼───┼───", thisLogID);
            }
        }
    }
Esempio n. 2
0
    bool CheckButtonPress()
    {
        bombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, checkButton.transform);
        checkButton.AddInteractionPunch(0.4f);
        checkButton.GetComponent <Animator>().Play("ZButtonPress", 0, 0);

        if (moduleSolved)
        {
            return(false);
        }

        List <VexBlock> shownOrder = VexesInDisplayOrder();

        if (shownOrder[0].GetPosition() == -1)
        {
            Debug.LogFormat("[TetraVex #{0}] STRIKE: Submitted when a piece wasn't in place.", thisLogID);
            bombModule.HandleStrike();
            return(false);
        }

        // Logging
        Debug.LogFormat("[TetraVex #{0}] Submitted solution:", thisLogID);
        for (int i = 0; i < 9; i += 3)
        {
            string[] log = VexBlock.BlockLineToStrings(shownOrder[i], shownOrder[i + 1], shownOrder[i + 2]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[0]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[1]);
            Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[2]);
            if (i < 6)
            {
                Debug.LogFormat("[TetraVex #{0}] ───┼───┼───", thisLogID);
            }
        }

        // We only check DOWN and RIGHT for each block, because left and up for each block are already checked by previous blocks.
        // We don't even bother extending the loop to hit the bottom-right block, because if we did hit it it is a guaranteed solve.
        for (int i = 0; i < 8; ++i)
        {
            if (!shownOrder[i].IsPositionOkay(i < 6 ? shownOrder[i + 3] : null, i % 3 < 2 ? shownOrder[i + 1] : null))
            {
                Debug.LogFormat("[TetraVex #{0}] STRIKE: The block in the {1} position has an incorrect connection.", thisLogID, __positionText[i]);
                bombModule.HandleStrike();
                return(false);
            }
        }

        Debug.LogFormat("[TetraVex #{0}] SOLVE: All connections okay; this is a valid solution.", thisLogID);
        bombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.CorrectChime, bombModule.transform);
        bombModule.HandlePass();
        moduleSolved = true;
        return(false);
    }