Exemplo n.º 1
0
    public void Update()
    {
        // LOGIC
        int Frames = _Controller == Control.NEURAL_NETWORL ? GameplayManager.GetInstance().UpdatesPerFrame : 1;

        // if (Input.GetKeyDown(KeyCode.LeftControl))
        //     UpdateOverclock = !UpdateOverclock;

        for (int i = 0; i < Frames; i++)
        {
            UpdateMovement();
            Tick();
        }

        // Update Histogram
        if (OPH != null)
        {
            float[] Outputs = TetrisPerceptronManager.GetEpochManager().GetCurrentEpoch().CurrentOutputs;

            if (Outputs != null && Outputs.Length == (int)Tetris.Move.TOTAL)
            {
                for (int i = 0; i < Outputs.Length; i++)
                {
                    OPH.UpdateOutput(i, Outputs[i]);
                }
            }
        }

        // GRAPHICS
        TetrisBoardColors.UpdateColors();
    }
Exemplo n.º 2
0
    // Update Text
    private void UpdateText()
    {
        // Objects
        Tetris T = Tetris.GetInstance();
        TetrisPerceptronManager TPM = TetrisPerceptronManager.GetInstance();

        // Text setters
        _TickText.text       = T.GetTickCounter().ToString();
        _CurrentPiece.text   = Tetris._Piece._Type.ToString();
        _NextPiece.text      = Tetris._Piece._NextType.ToString();
        _GenerationText.text = TetrisPerceptronManager.GetEpochManager().GetGeneration().ToString();
        _EpochText.text      = (TetrisPerceptronManager.GetEpochManager().GetEpochIndex().ToString() + "/" + TetrisPerceptronManager.GetEpochManager().GetMaxEpochs().ToString());
        _LinesText.text      = Tetris._Lines.ToString();
        _TotalLinesText.text = Tetris._TotalLines.ToString();
        _FitnessText.text    = Tetris._Fitness.ToString();
        // Move Text is updated internally
        if (LimitPieces <= 0)
        {
            _PiecesUsedText.text = Tetris._PiecesUsed.ToString();
        }
        else
        {
            _PiecesUsedText.text = Tetris._PiecesUsed.ToString() + '/' + LimitPieces.ToString();
        }

        _BestSoFar.text       = _Histogram.GetMaxValue().ToString();
        _SimulationSpeed.text = UpdatesPerFrame.ToString();

        if (!PauseMenu.GetInstance().getActive())
        {
            int    time    = (int)(Time.time - PauseMenu.GetInstance()._PauseTime);
            string seconds = (time % 60).ToString("00");
            string minutes = (time / 60 % 60).ToString("00");
            string hours   = (time / 3600).ToString("0000");

            _TimeText.text = hours + ':' + minutes + ':' + seconds;
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape))
        {
            // Can only unpause if not saving
            if (SavingThread.GetInstance().checkThreadRunning() == false)
            {
                ToggleActive();
            }
        }

        if (_Active)
        {
            // Saving Effect
            bool CheckSaving = SavingThread.GetInstance().checkThreadRunning();
            PauseMenu.GetInstance()._LoadingText.enabled = CheckSaving;
            if (CheckSaving)
            {
                PauseMenu.GetInstance()._LoadingText.text = "Loading... (" +
                                                            SavingThread.m_Saving_Layer.ToString() + "-" +
                                                            SavingThread.m_Saving_Perceptron.ToString() + "-" +
                                                            SavingThread.m_Saving_Weight.ToString() + ")";
            }
            //

            _Parent.SetActive(true);

            Vector3 Position = _FancyBar.GetComponent <RectTransform>().position;
            Position.y = Mathf.Lerp(Position.y, getItem(_MenuIndex)._Text.GetComponent <RectTransform>().position.y, 0.3f);
            _FancyBar.GetComponent <RectTransform>().position = Position;

            if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
            {
                _MenuIndex++;
                if (_MenuIndex > _Items.Length - 1)
                {
                    _MenuIndex = 0;
                }
            }
            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
            {
                _MenuIndex--;
                if (_MenuIndex < 0)
                {
                    _MenuIndex = _Items.Length - 1;
                }
            }

            for (int i = 0; i < _Items.Length; i++)
            {
                if (i != _MenuIndex)
                {
                    _Items[i]._Text.color = Color.Lerp(_Items[i]._Text.color, _UnselectedColor, 0.25f);
                }
            }
            _Items[_MenuIndex]._Text.color = Color.Lerp(_Items[_MenuIndex]._Text.color, _SelectedColor, 0.4f);

            // API for File Browser
            // https://github.com/gkngkc/UnityStandaloneFileBrowser
            //
            if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
            {
                switch (_Items[_MenuIndex]._type)
                {
                case PauseItem.Type.RESUME:
                {
                    // Can only unpause if not saving
                    if (SavingThread.GetInstance().checkThreadRunning() == false)
                    {
                        ToggleActive();
                    }
                }
                break;

                case PauseItem.Type.SAVE_EPOCH:
                {
                    // Get Current Epoch
                    Epoch epoch = TetrisPerceptronManager.GetEpochManager().GetCurrentEpoch();
                    if (epoch == null)
                    {
                        Debug.LogError("No Current Epoch");
                        return;
                    }

                    string Directory = SimpleFileDialog.SelectFile();
                    if (Directory == "")
                    {
                        Debug.LogError("Directory Not Selected");
                        return;
                    }

                    SavingThread.GetInstance().SaveEpoch(epoch, Directory);
                }
                break;

                case PauseItem.Type.SAVE_BEST_EPOCH:
                {
                    // Get Best Epoch
                    Epoch epoch = TetrisPerceptronManager.GetEpochManager().GetBestEpochAcrossGeneration();
                    if (epoch == null)
                    {
                        Debug.LogError("No Current Epoch");
                        return;
                    }

                    string Directory = SimpleFileDialog.SelectFile();
                    if (Directory == "")
                    {
                        Debug.LogError("Directory Not Selected");
                        return;
                    }

                    SavingThread.GetInstance().SaveEpoch(epoch, Directory);
                }
                break;

                case PauseItem.Type.LOAD_EPOCH:
                {
                    // Read Data File as String
                    string Data = SimpleFileDialog.OpenFile();
                    if (Data.Length == 0)
                    {
                        return;
                    }

                    // Read File
                    Epoch Result = EpochParser.LoadFile(Data);
                    if (Result == null)
                    {
                        return;
                    }

                    // Set To Current Epoch
                    TetrisPerceptronManager.GetEpochManager().OverrideCurrentEpoch(Result);

                    // Reset Game
                    Tetris.GetInstance().ResetGame();
                }
                break;
                }
            }
        }
        else
        {
            _Parent.SetActive(false);
        }
    }