// End Current Game private void EndGame() { //Debug.Log("GAMEOVER"); if (_Controller == Control.NEURAL_NETWORL) { // Count total empty spaces float empty_slots = TetrisBoard._TotalCells - TetrisBoard.CountSolidsInBoard(); IncreaseFitness(ScoreSystemManager.GetCurrent().GameOver_EmptySlots *empty_slots); // Increase Fitness by the IncreaseFitness(ScoreSystemManager.GetCurrent().Per_Piece_Placed *(float)_PiecesUsed); // Calculate Fitness from Heuristics TetrisPerceptronManager.GetInstance().FinishCurrentAI(_Fitness); GameplayManager.GetInstance()._Histogram.AddValue(_Fitness); } ResetGame(); }
// 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; } }
// Movement private void UpdateMovement() { // Set Move if (_Controller == Control.PLAYER) { if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { SetMove(Move.MOVE_LEFT); } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { SetMove(Move.MOVE_RIGHT); } else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { SetMove(Move.MOVE_DOWN); } else if (Input.GetKeyDown(KeyCode.Space)) { SetMove(Move.COLLAPSE); } else if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Comma)) { SetMove(Move.ROTATE_CCW); } else if (Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.Period)) { SetMove(Move.ROTATE_CW); } } else if (_Controller == Control.NEURAL_NETWORL) { // Update Neurons TetrisPerceptronManager.GetInstance().UpdateAI(); // Set Move to its selected move SetMove(TetrisPerceptronManager._AI_Move); } }