Example #1
0
    /// <summary>
    /// This will validate the current code we are working with
    /// </summary>
    private void ValidateCode(MyLineRenderer currentLineRend)
    {
        Debug.Log("Validating Code");

        // if its solved dont do anything
        if (solved == true)
        {
            return;
        }

        // if the code is correct
        if (currentCode == correctCode && currentNumberOfConnections == correctNumberOfConnections)
        {
            // start coroutine to reload the scene
            StartCoroutine(WaitThenReloadScene());
            // set solved to true
            solved = true;

            // if the current line is drawing the reset it
            if (currentLine.drawLine)
            {
                currentLine.ResetLine();
            }

            // change the color of all lines to green
            foreach (MyLineRenderer lineRend in allLineRenderers)
            {
                lineRend.ChangeLinesColor(lineSuccessMat);
                lineRend.lineFinished = true;
            }
        }
        // if the combo was wrong
        else
        {
            // reset the code, number of connections so far, and set combo failed to true
            currentCode = "";
            currentNumberOfConnections = 0;
            comboFailed = true;

            // if we have a current line and its drawing reset the line
            if (currentLine != null && currentLine.drawLine)
            {
                currentLine.ResetLine();
            }

            // update the color of the line to red
            foreach (MyLineRenderer lineRend in allLineRenderers)
            {
                lineRend.ChangeLinesColor(lineFailMat);
            }
        }

        // get rid of our current line
        currentLine = null;
    }
 public void mctsSearch(int numIterations)
 {
     MyLineRenderer.Init();
     for (int i = 0; i < numIterations; i++)
     {
         currentState.Save();
         birdPosList = new List <Vector3>();
         birdPosList.Add(currentState.birdPos);
         MCTS_TreeNode selected = treePolicy();
         float         reward   = selected.rollOut();
         backUp(selected, reward);
         MyLineRenderer.lineStrips.Add(birdPosList);
     }
 }
Example #3
0
    /// <summary>
    /// Function on what should happen when a new line is found
    /// </summary>
    /// <param name="lineRenderer">New line renderer that has been found</param>
    private void NewLineFound(MyLineRenderer lineRenderer)
    {
        // if a combo has been failed
        if (comboFailed)
        {
            // invert the failed
            comboFailed = false;

            // reset lines of each line renderer
            foreach (MyLineRenderer lineRend in allLineRenderers)
            {
                lineRend.ResetLine();
            }
        }

        // check if the new line is already done or if its our current line
        if (!lineRenderer.lineFinished && lineRenderer != currentLine)
        {
            // now that its a valid line update info
            currentCode += lineRenderer.identifier;
            currentNumberOfConnections++;

            // check if its our last lineRenderer
            if (currentNumberOfConnections == MaxNumberOfConnections)
            {
                // if it is check if we have the right code then leave function
                currentLine.EndFollow(lineRenderer.offset * -1);
                ValidateCode(lineRenderer);
                return;
            }

            // have the new line start following input
            lineRenderer.StartFollowingInput();

            // check if we are working with a current line
            if (currentLine != null)
            {
                // if we are set its endpoint
                currentLine.EndFollow(lineRenderer.offset * -1);
            }

            // set our new line renderer as our current
            currentLine = lineRenderer;
        }
    }
Example #4
0
    public override Action GetAction()
    {
        MyLineRenderer.Init();
        //Initialize population
        for (int i = 0; i < 2; i++)
        {
            populations[i].Clear();
        }
        popIndex = 0;
        for (int i = 0; i < sizeGeneration; i++)
        {
            populations[popIndex].Add(RandomChromosome());
        }
        if (lastBestChromosome != "")
        {
            //TODO: Your code here (Q1): Overwrite populations[popIndex][0] with the shifted version of last best chromosome.
        }

        for (int g = 1; g <= numGenerations; g++)
        {
            EvaluateCurrentPopulation();
            FillMatingPool();
            CrossOver();
            Mutation();
            Elitism();
            popIndex = 1 - popIndex;
        }
        //Go over the population one last time to find the best answer found by GA
        EvaluateCurrentPopulation();
        //print(populations[popIndex][eliteIndex]);
        //Now extract first action from populations[popIndex][eliteIndex]
        lastBestChromosome = populations[popIndex][eliteIndex];
        int actionIdx = lastBestChromosome[0] == '0' ? 0 : 1;

        return((Action)(actionIdx));
    }
    public Material GetMaterialOfLine(Line.TYPE type_)
    {
        int index = (int)type_;

        if (linesMaterial.Length-1 < index){
            Debug.LogError("Line's Material is null.");
        }

        return linesMaterial[index];
    }