コード例 #1
0
    // Score from line clear
    private void IncreaseScoreFromLineClear(LineClear LC)
    {
        ScoreSystem G = ScoreSystemManager.GetCurrent();

        switch (LC)
        {
        case LineClear.CLEAR_1:
            IncreaseFitness(G.Line_Single);
            break;

        case LineClear.CLEAR_2:
            IncreaseFitness(G.Line_Double);
            break;

        case LineClear.CLEAR_3:
            IncreaseFitness(G.Line_Triple);
            break;

        case LineClear.CLEAR_4:
            IncreaseFitness(G.Line_Quad);
            break;

        case LineClear.CLEAR_4_Combo:
            IncreaseFitness(G.Line_Combo);
            break;
        }
    }
コード例 #2
0
 // Scriptの取得
 private void GetScript()
 {
     Script_render    = render.GetComponent <Render>();
     Script_hold      = hold.GetComponent <Hold>();
     Script_next      = next.GetComponent <Next>();
     Script_lineClear = lineClear.GetComponent <LineClear>();
 }
コード例 #3
0
        private bool PerformLineOperations()
        {
            ICollection <int> fullLines = new LinkedList <int>();

            for (int y = 0; y < GameRules.Height; y++)
            {
                int x;
                for (x = 0; x < GameRules.Width; x++)
                {
                    if (!_settledBlocks.ContainsKey(new Vector2Int(x, y)))
                    {
                        break;
                    }
                }

                if (x == GameRules.Width)
                {
                    fullLines.Add(y);
                }
            }

            if (fullLines.Count == 0)
            {
                return(false);
            }

            // Clear stage...
            foreach (var y in fullLines)
            {
                for (int x = 0; x < GameRules.Width; x++)
                {
                    _settledBlocks.Remove(new Vector2Int(x, y));
                    LineClear?.Invoke(y);
                }
            }

            // Shift stage...
            for (int y = 0; y < GameRules.Height; y++)
            {
                var currentY             = y;
                var freeSlotsAmountBelow = fullLines.Count(i => i < currentY);
                for (int x = 0; x < GameRules.Width; x++)
                {
                    var index = new Vector2Int(x, y);
                    if (_settledBlocks.TryGetValue(index, out var block))
                    {
                        _settledBlocks.Remove(index);
                        var newIndex = index + Vector2Int.down * freeSlotsAmountBelow;
                        block.Location           = newIndex;
                        _settledBlocks[newIndex] = block;
                    }
                }
            }

            return(true);
        }
コード例 #4
0
    // Add piece to board
    private void AddPieceToBoard()
    {
        // Move piece back up 1
        _Piece._y++;

        // Score from crowded section
        int section = TetrisBoard.CheckPieceInCrowd(ScoreSystemManager.GetCurrent().Section_Counts_As_Width_Divided_By);

        if (section == -1)
        {
            IncreaseFitness(ScoreSystemManager.GetCurrent().NonCrowded_Section);
        }
        else if (section == 1)
        {
            IncreaseFitness(ScoreSystemManager.GetCurrent().Crowded_Section);
        }

        // Current Bumpiness
        float Bump_Old = TetrisHeuristics.CalculateBumpiness();
        // Current Holes
        float Holes_Old = TetrisHeuristics.CountHoles();

        /* */
        /* */

        // Add piece to board
        TetrisBoard.AddSolidsToBoardFromPiece();

        // Remove Horizontal Lines
        LineClear LC = TetrisBoard.UpdateCompletedLines();

        // Give score for those lines
        if (!GameplayManager.GetInstance().LinesDoNotClear)
        {
            IncreaseScoreFromLineClear(LC);
        }

        /* */
        /* */

        // Current Bumpiness
        float Bump = TetrisHeuristics.CalculateBumpiness();

        IncreaseFitness(ScoreSystemManager.GetCurrent().BumpAverage *Bump);

        // Change in Bumpiness
        float Bump_Change = Bump - Bump_Old;

        IncreaseFitness(ScoreSystemManager.GetCurrent().BumpFixMultiplier *Bump_Change);

        // Change in Holes
        float Holes_Change = Mathf.Max(0.0f, TetrisHeuristics.CountHoles() - Holes_Old);

        IncreaseFitness(ScoreSystemManager.GetCurrent().HoleAdded *Holes_Change);
        // Current Aggregate Height Score
        float AggregateHeightScore = TetrisHeuristics.AggregateHeight() * ScoreSystemManager.GetCurrent().AggregateHeightChangedMultiplier;

        IncreaseFitness(AggregateHeightScore);

        // Check Values for Testing
        //Debug.Log("Aggregate Height: " + TetrisHeuristics.AggregateHeight());
        //Debug.Log("Complete Rows: " + TetrisHeuristics.CalculateCompleteRows());
        //Debug.Log("Holes: " + TetrisHeuristics.CountHoles());
        //Debug.Log("Bumpiness: " + TetrisHeuristics.CalculateBumpiness());
        //Debug.Log("~~~");

        // Score from height
        float y_level      = (float)(_Piece._WorldMin.y) / 24.0f;
        float height_score = Mathf.Lerp(
            ScoreSystemManager.GetCurrent().Height_Lerp_Bot,
            ScoreSystemManager.GetCurrent().Height_Lerp_Top,
            y_level);

        IncreaseFitness(height_score);

        // Score from bottom row
        float BottomCount = TetrisHeuristics.CountTetrisPiecesRow(0);

        IncreaseFitness(ScoreSystemManager.GetCurrent().Bottom_Row *BottomCount);

        // Score from top 2 rows
        float TopCount = TetrisHeuristics.CountTetrisPiecesRow(TetrisBoard._Height - 1);

        TopCount += TetrisHeuristics.CountTetrisPiecesRow(TetrisBoard._Height - 2);
        IncreaseFitness(ScoreSystemManager.GetCurrent().Top_2_Rows *TopCount);

        // Reset Piece
        _Piece._Type = Tetrominoes.NONE;

        // Add Total Pieces Added
        _PiecesUsed++;
    }
コード例 #5
0
ファイル: TetrisGame.cs プロジェクト: Chapmania/Juniper
 private void PlayLineClear(int numLines)
 {
     LineClear?.Invoke(this, new IntegerEventArgs(numLines));
 }
コード例 #6
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
 private void TSpin(LineClear move)
 {
 }
コード例 #7
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
        private void Tetris()
        {
            if (LastScore == LineClear.Tetris)
            {
                TotalPoints += (int)PointValues.Tetris * 3 * Level / 2 + Combo();
                linesThisLevel += 12;
            }
            else
            {
                TotalPoints += (int)PointValues.Tetris * Level + Combo();
                linesThisLevel += 8;
            }
            TotalLinesCleared += 4;

            LastPlay = LineClear.Tetris;
            LastScore = LineClear.Tetris;
            Sounds.Tetris();
        }
コード例 #8
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
        private void Triple()
        {
            TotalPoints += (int)PointValues.Triple * Level + Combo();
            TotalLinesCleared += 3;
            linesThisLevel += 5;

            LastPlay = LineClear.Triple;
            LastScore = LineClear.Triple;
            Sounds.Score(combo);
        }
コード例 #9
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
        private void Single()
        {
            TotalPoints += (int)PointValues.Single * Level + Combo();
            TotalLinesCleared++;
            linesThisLevel++;

            LastPlay = LineClear.Single;
            LastScore = LineClear.Single;
            Sounds.Score(combo);
        }
コード例 #10
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
 private bool IsScoringPlay(LineClear play)
 {
     switch (play)
     {
         case LineClear.None:
         case LineClear.TSpin: return false;
     }
     return true;
 }
コード例 #11
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
 public void reset()
 {
     Level = 1;
     linesThisLevel = 0;
     TotalPoints = 0;
     TotalLinesCleared = 0;
     LastPlay = LineClear.None;
     LastScore = LineClear.None;
 }
コード例 #12
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
 public void LastMove(LineClear move)
 {
     switch (move)
     {
         case LineClear.None: LastPlay = move; break;
         case LineClear.Single: Single(); break;
         case LineClear.Double: Double(); break;
         case LineClear.Triple: Triple(); break;
         case LineClear.Tetris: Tetris(); break;
         case LineClear.TSpin: TSpin(move); break;
         case LineClear.TSpinSingle: TSpin(move); break;
         case LineClear.TSpinDouble: TSpin(move); break;
         case LineClear.TSpinTriple: TSpin(move); break;
     }
 }
コード例 #13
0
ファイル: Scoring.cs プロジェクト: patrickdean/tetris-clone
 public void Drop(LineClear move)
 {
     if (move == LineClear.SoftDrop)
         TotalPoints++;
     else if (move == LineClear.HardDrop)
         TotalPoints += 2;
 }