Exemplo n.º 1
0
 private void ProcessPieceDiff(StatState diff)
 {
     if (diff.IsValidPieceStats)
     {
         if (diff.T == 1)
         {
             pieceHistory.Add("T");
         }
         else if (diff.J == 1)
         {
             pieceHistory.Add("J");
         }
         else if (diff.Z == 1)
         {
             pieceHistory.Add("Z");
         }
         else if (diff.O == 1)
         {
             pieceHistory.Add("O");
         }
         else if (diff.S == 1)
         {
             pieceHistory.Add("S");
         }
         else if (diff.L == 1)
         {
             pieceHistory.Add("L");
         }
         else if (diff.I == 1)
         {
             pieceHistory.Add("I");
         }
     }
 }
Exemplo n.º 2
0
 private void ProcessSoftDrop(StatState diff, StatState newState)
 {
     if (diff.Lines == 0)
     {
         softDropTotal += diff.Score;
     }
     else
     {
         softDropTotal += diff.Score - ScoreTable.getScore(diff.Lines, newState.Level);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Level is calculated purely on linecount. We get the first level transition to work off.
 /// </summary>
 /// <param name="diff"></param>
 /// <param name="current"></param>
 private void ProcessLevel(StatState diff, StatState current)
 {
     if (!leveledUp && diff.Level != 0)
     {
         firstLevelUpBoundary = (current.Lines / 10) * 10;
         this.currentLevel    = this.startLevel + 1;
         leveledUp            = true;
     }
     else if (leveledUp)
     {
         this.currentLevel = ((current.Lines - firstLevelUpBoundary) / 10) + 1 + startLevel;
     }
 }
Exemplo n.º 4
0
        private void processEvent(JSONNode obj)
        {
            lastMessageTimeStamp = Time.realtimeSinceStartup;
            StatState currentState = new StatState(obj);

            if (currentState.IsValidMainStats)
            {
                if (prevState == null || isNewGame(prevState, currentState)) //first game
                {
                    OnNewGame();
                }
                gameState.processEvent(currentState);
            }
            prevState = currentState;
        }
Exemplo n.º 5
0
        private void ProcessLineScore(StatState diff, StatState newState)
        {
            if (diff.Lines == 0)
            {
                return;
            }

            distClears[diff.Lines - 1] += 1;
            distScores[diff.Lines - 1] += ScoreTable.getScore(diff.Lines, newState.Level);
            if ((newState.Lines / 10) > tenLineScores.Count)
            {
                tenLineScores.Add(newState.Score);
            }
            lineHistory.Add(diff.Lines);
            lineScores.Add(new LineScore(newState.Lines, newState.Score, this.Duration));
        }
Exemplo n.º 6
0
        //Only call if both area isValid!
        //Call on the old one...
        public StatState diff(StatState other)
        {
            StatState result = new StatState();

            result.Score             = other.Score - this.Score;
            result.Lines             = other.Lines - this.Lines;
            result.Level             = other.Level - this.Level;
            result.T                 = other.T - this.T;
            result.J                 = other.J - this.J;
            result.Z                 = other.Z - this.Z;
            result.O                 = other.O - this.O;
            result.S                 = other.S - this.S;
            result.L                 = other.L - this.L;
            result.I                 = other.I - this.I;
            result.IsValidMainStats  = other.IsValidMainStats || this.IsValidMainStats;
            result.IsValidPieceStats = other.IsValidPieceStats || this.IsValidPieceStats;

            return(result);
        }
Exemplo n.º 7
0
        private bool LegitDiff(StatState diff, StatState current)
        {
            if (diff.Lines < 0 || diff.Lines > 4)
            {
                Debug.Log("lines" + diff.Lines.ToString());
                return(false);
            }
            if (diff.Level < 0 || diff.Level > 1)
            {
                Debug.Log("level" + diff.Level);
            }
            //we scored more than a tetris + softdrop...
            if (diff.Score > ScoreTable.getScore(4, current.Level) + 50)
            {
                Debug.Log(diff.Score.ToString() + (ScoreTable.getScore(4, current.Level) + 50).ToString());
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public void processEvent(StatState current)
        {
            if (lastState == null)
            {
                lastState    = current;
                startLevel   = current.Level;
                currentLevel = current.Level;
                StartTime    = DateTime.Now;
                FinishTime   = DateTime.Now;
                GenerateTenLineGoal();
                ProcessPieceDiff(current); //get first piece.
                return;
            }

            //First, we have to fix the level.
            StatState diff = lastState.diff(current);

            ProcessLevel(diff, current);
            current.Level = this.currentLevel;
            diff          = lastState.diff(current);

            //quick sanity check
            if (!LegitDiff(diff, current))
            {
                Debug.Log(":(");
                Debug.Log(lastState);
                Debug.Log(current);
                Debug.Log(diff);
                return;
            }

            FinishTime = DateTime.Now;
            ProcessSoftDrop(diff, current);
            ProcessLineScore(diff, current);
            ProcessPieceDiff(diff);


            lastState = current;
        }
Exemplo n.º 9
0
 private bool isNewGame(StatState prevState, StatState current)
 {
     return(!prevState.IsValidMainStats && current.Lines == 0);
 }