Esempio n. 1
0
    private void UpdatePlayerScoresArray()
    {
        Array.Sort(playerScores); // Even though the aray *should* be sorted, we sort here incase it was initialized out-of-order via the property inspector

        ScoreElement newScore     = new ScoreElement(PlayerPrefs.GetString("PlayerName", GameManager.Instance.defaultPlayerName), Time.timeSinceLevelLoad - startTimeOffset, currentLevelScore);
        float        newScoreRank = newScore.CalculateScoreRank();

        for (int i = 0; i < playerScores.Length; i++)
        {
            bool  hasInserted      = false;
            float currentScoreRank = playerScores[i].CalculateScoreRank();

            if (newScoreRank > currentScoreRank)
            {
                hasInserted = true;
                currentPlayerScoresEntryIndex = i;

                for (int j = i; j < playerScores.Length; j++)
                {
                    ScoreElement temp = playerScores[j];
                    playerScores[j] = newScore;
                    newScore        = temp;
                }
            }

            if (hasInserted) // If we've inserted the new element, we're done
            {
                break;
            }
        } // End score insertion loop

        SaveScores();
    }
Esempio n. 2
0
        public ScoreElement GenerateScoreElement(string obtainedText, string searchedText)
        {
            if (string.IsNullOrWhiteSpace(obtainedText))
            {
                throw new System.ArgumentException("message", nameof(obtainedText));
            }

            if (string.IsNullOrWhiteSpace(searchedText))
            {
                throw new System.ArgumentException("message", nameof(searchedText));
            }

            obtainedText = obtainedText.ToLower();
            searchedText = searchedText.ToLower();

            var strLen   = obtainedText.Length;
            var distance = StringHelper.LevenshteinDistance(obtainedText, searchedText);

            var element = new ScoreElement
            {
                Ingresado           = searchedText,
                Obtenido            = obtainedText,
                PesoValor           = this.MatchValue,
                PesoValorUI         = this.MatchValue.ToString("P2"),
                ObtenidoLen         = strLen.ToString(),
                LevenshteinDistante = distance
            };

            //Si la distancia es igual al Len del string obtenido es porque no coincide absolutamente nada.
            //En este caso retorna 0. No ha coincidencia alguna.
            if (distance >= strLen)
            {
                element.CoeficienteParcialUI = (0M).ToString("#0.00");
                element.CoeficienteFinal     = 0;
                element.CoeficienteFinalUI   = (0M).ToString("P2");
                return(element);
            }

            //Si los textos son iguales, retonra el valor del Coeficiente completo.
            if (distance == 0)
            {
                element.CoeficienteParcialUI = (1M).ToString("#0.00");
                element.CoeficienteFinal     = this.MatchValue;
                element.CoeficienteFinalUI   = this.MatchValue.ToString("P2");
                return(element);
            }

            //Si la distancia es menor entonces es necesario el calculo porcentual del coeficiente.
            if (distance < strLen)
            {
                var matchCoef = ((decimal)(strLen - distance) / (decimal)strLen);
                var finalCoef = (matchCoef * this.MatchValue);

                element.CoeficienteParcialUI = matchCoef.ToString("#0.00");
                element.CoeficienteFinal     = finalCoef;
                element.CoeficienteFinalUI   = finalCoef.ToString("P2");
            }

            return(element);
        }
Esempio n. 3
0
    void FillScores()
    {
        m_scores.Sort(delegate(SaveManager.Score x, SaveManager.Score y) {
            if (x.value < y.value)
            {
                return(1);
            }
            else if (x.value > y.value)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        });

        for (int i = 0; i < m_scores.Count; ++i)
        {
            ScoreElement se = Instantiate(ScoreUIElement);
            se.transform.SetParent(ScoreLayout.transform);

            if (i < MaxScoreCount)
            {
                se.Init(i + 1, m_scores[i].name, m_scores[i].value);
            }
            else
            {
                se.Init("...");
                break;
            }
        }
    }
Esempio n. 4
0
    public void CreateScoreElement(string name, int amount, int finalScoreValue, string description)
    {
        GameObject   newElement   = Instantiate(scoreElementPrefab, scoreScreenContentParent.transform);
        ScoreElement scoreElement = newElement.GetComponent <ScoreElement>();

        scoreElements.Add(scoreElement);
        scoreElement.InitializeSetup(name, amount, finalScoreValue, description);
    }
Esempio n. 5
0
    // Compares this object with the received object:
    //      If this.score > otherScore, return 1
    //      If this.score == otherScore, return 0
    //      If this.score < otherScore, return -1
    public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(1);
        }

        ScoreElement otherScore = (ScoreElement)obj;

        return((int)Mathf.Sign(otherScore.CalculateScoreRank() - this.CalculateScoreRank())); // Rank is calculated as: points - (time in seconds)
    }
Esempio n. 6
0
 public void ToggleToolTip(ScoreElement element)
 {
     if (!toggle)
     {
         toggle  = true;
         DataSet = MasterManager.mm.playerData[getElement(MasterManager.mm.playerData, element.id)];
     }
     else
     {
         toggle = false;
     }
     toolTip.SetActive(toggle);
 }
Esempio n. 7
0
    // Use this for initialization
    void Start()
    {
        List <int> highscores = gameStats.GetHighscores();
        int        count      = 0;

        foreach (int highscore in highscores)
        {
            GameObject   newScoreElement = Instantiate(scoreElementObject, transform);
            ScoreElement scoreElement    = newScoreElement.GetComponent <ScoreElement>();

            scoreElement.setScore(highscore);

            scoreElement.transform.parent        = transform;
            scoreElement.transform.localPosition = new Vector3(0, -count * spacing, 0);


            count++;
        }
    }
Esempio n. 8
0
    public void scoreboardzeichnen()
    {
        if (obj.Count > 0)
        {
            for (int i = 0; i < obj.Count; i++)
            {
                Destroy(obj[i]);
            }
            obj.Clear();
        }


        foreach (PlayerData data in MasterManager.mm.playerData)
        {
            GameObject   objectS = Instantiate(scoreElement, transform);
            ScoreElement se      = objectS.GetComponent <ScoreElement>();
            se.nameElement.text  = data.name;
            se.scoreElement.text = data.score;
            se.id = data.id;

            obj.Add(objectS);
        }
    }
Esempio n. 9
0
    // When a score is added, ensure the necessary information is added to the text of `ScoreDetails'
    public void AddElement(string element, int inScoreConst)
    {
        scoreDetails.text = "";

        // If trick already added, increment its count - otherwise add new trick
        if (scoreElements.Exists(e => e.GetElement() == element))
        {
            (scoreElements.Find(x => x.GetElement() == element)).Increment();
        }
        else
        {
            ScoreElement newElement = new ScoreElement(element, inScoreConst);
            scoreElements.Add(newElement);
        }

        // Add information regarding each trick to text
        for (int i = 0; i < scoreElements.Count; i++)
        {
            if (i == 0)
            {
                scoreDetails.text = scoreDetails.text + " (" + scoreElements[i].GetElement() + "*" + scoreElements[i].GetCount() + " (" + scoreElements[i].GetScore() + ")";
            }
            else
            {
                scoreDetails.text = scoreDetails.text + " + " + scoreElements[i].GetElement() + "*" + scoreElements[i].GetCount() + " (" + scoreElements[i].GetScore() + ")";
            }

            if (i == scoreElements.Count - 1)
            {
                scoreDetails.text += ") * " + multiplier;
            }
        }
        // Increase multiplier - ensures trick combos rewarded
        multiplier += .02f;
        // This rounding needs to occur as error can occur with float addition
        multiplier = (float)Math.Round(multiplier, 2);
    }
Esempio n. 10
0
 private void SwapArrays(ref ScoreElement[] previousRow, ref ScoreElement[] currentRow) {
     var tmp = previousRow;
     previousRow = currentRow;
     currentRow = tmp;
 }
Esempio n. 11
0
        /// <summary>
        /// This is step (2) in the dynamic programming model - to fill in the scoring matrix
        /// and calculate the traceback entries.  This version is used when the open/extension
        /// gap costs are different (affine gap model).
        /// </summary>
        private IEnumerable<OptScoreMatrixCell> CreateAffineTracebackTable()
        {
            /* We will need a low constant number that is not Int32.MinValue 
             * for the boundaries of the matrix (if we used Int32.MinValue it would 
             * over flow when added to the move score to a very high value and become the max
             * rather than the min).
             */
            int EDGE_MIN_VALUE = Int32.MinValue + Math.Max(Rows, Cols) * Math.Abs (GapOpenCost);


            // Horizontal and vertical gap counts.
            int gapStride = Cols + 1;

            /* These are equivalent to traceback matrices for the 
             * horizontal and vertical "gap" matrices.  However, rather than store
             * an arrow that points in a direction, we store the size of moves,
             * which allows us to transition into and out of the gap matrices in one
             * step, rather than following paths through them.
             */
            var matrixSize = checked((Rows + 1) * gapStride);
            try {
                h_Gap_Length = new int[matrixSize];
                v_Gap_Length = new int[matrixSize];
            }
            catch(OutOfMemoryException oom) {
                throw new OutOfMemoryException (GenerateOOMErrorMessageWhenAllocatingGapTracebacks (), oom);
            }

            /* As we progress through, we only need to know about 
             * the current row and the previous row for the recursions,
             * so we only use these two, rather than a full matrix.
             */
            ScoreElement[] previousScoreRow = new ScoreElement[Cols];
            ScoreElement[] currentScoreRow = new ScoreElement[Cols];
            int[][] matrix = SimilarityMatrix.Matrix;

            // Upper left element is initalized to 0
            currentScoreRow [0] = new ScoreElement () {
                HorizontalGapScore = EDGE_MIN_VALUE,
                VerticalGapScore = EDGE_MIN_VALUE,
                MatchScore = 0
            };
            if (IncludeScoreTable) {
                ScoreTable[0] = 0;

            }
            // Initialize first row
            sbyte[] traceback = Traceback [0];
            for (int j = 1; j < traceback.Length; j++)
            {
                // always have to go left from top
                traceback[j] = SourceDirection.Left;
                h_Gap_Length[j] = j;
                var initialScore = (j - 1) * GapExtensionCost + GapOpenCost;
                currentScoreRow [j] = new ScoreElement () {
                    HorizontalGapScore = initialScore,
                    VerticalGapScore = EDGE_MIN_VALUE,
                    MatchScore = EDGE_MIN_VALUE
                };
                if (IncludeScoreTable)
                   ScoreTable[j] = initialScore;
            }

            for (int i = 1; i < Rows; i++)
            {
                // Create the next TB row
                traceback = new sbyte[Cols];
                Traceback [i] = traceback;
                // Make the current row the last row,
                // reuse the current rows memory for the new row
                SwapArrays(ref currentScoreRow, ref previousScoreRow);
              
                /* Initialize first column
                 * We can't move further back horizontally here (we are at 
                 * the edge), so we set the score to something so low we will
                 * never go this direction on the highest scoring path, and so 
                 * can avoid explicitly checking for an edge
                 */
                currentScoreRow[0] = new ScoreElement() {
                    MatchScore = EDGE_MIN_VALUE, 
                    HorizontalGapScore = EDGE_MIN_VALUE, 
                    VerticalGapScore = (i - 1) * GapExtensionCost + GapOpenCost};
                traceback[0] = SourceDirection.Up;
                v_Gap_Length[i * gapStride] = i;

                for (int j = 1; j < Cols; j++)
                {
                    // Get the three important values
                    var cellAbove = previousScoreRow[j];
                    var cellDiagAbove = previousScoreRow [j - 1];
                    var cellLeft = currentScoreRow [j - 1];

                    // Gap in reference sequence
                    int scoreAbove;
                    int scoreAboveOpen = Math.Max(cellAbove.HorizontalGapScore, cellAbove.MatchScore) + GapOpenCost;
                    int scoreAboveExtend = cellAbove.VerticalGapScore + GapExtensionCost;
                    if (scoreAboveOpen > scoreAboveExtend)
                    {
                        scoreAbove = scoreAboveOpen;
                        v_Gap_Length[i * gapStride + j] = 1;
                    }
                    else
                    {
                        scoreAbove = scoreAboveExtend;
                        v_Gap_Length[i * gapStride + j] = v_Gap_Length[(i - 1) * gapStride + j] + 1;
                    }

                    // Gap in query sequence
                    int scoreLeft;
                    int scoreLeftOpen = Math.Max(cellLeft.MatchScore, cellLeft.VerticalGapScore) + GapOpenCost;
                    int scoreLeftExtend = cellLeft.HorizontalGapScore + GapExtensionCost;
                    if (scoreLeftOpen > scoreLeftExtend)
                    {
                        scoreLeft = scoreLeftOpen;
                        h_Gap_Length[i * gapStride + j] = 1;
                    }
                    else
                    {
                        scoreLeft = scoreLeftExtend;
                        h_Gap_Length[i * gapStride + j] = h_Gap_Length[i * gapStride + (j - 1)] + 1;
                    }

                    // Get the exact match/mismatch score
                    int mScore = (matrix != null) ? matrix[QuerySequence[i - 1]][ReferenceSequence[j - 1]] : SimilarityMatrix[QuerySequence[i - 1], ReferenceSequence[j - 1]];
                    /* Since all possible previous states have the same match score applied, 
                     * we can just add to the previous max */
                    int scoreDiag = cellDiagAbove.BestScore + mScore;

                    // Store the scores for this cell
                    currentScoreRow[j] = new ScoreElement() { HorizontalGapScore = scoreLeft,
                                                              VerticalGapScore = scoreAbove,
                                                              MatchScore = scoreDiag };
                                                              

                    // Get the max S = MAX(diag,above,left) and assign the traceback
                    if ((scoreDiag > scoreAbove) && (scoreDiag > scoreLeft))
                    {
                        traceback[j] = SourceDirection.Diagonal;
                    }
                    else if (scoreLeft > scoreAbove)
                    {
                        traceback[j] = SourceDirection.Left;
                    }
                    else //if (scoreAbove > scoreLeft)
                    {
                        traceback[j] = SourceDirection.Up;
                    }
                }

                if (IncludeScoreTable)
                {
                    Array.Copy(currentScoreRow.Select(x => x.BestScore).ToArray(), 0, ScoreTable, i * Cols, Cols);
                }
            }

            return new[]
            {
                new OptScoreMatrixCell
                {
                    Row = Rows-1, 
                    Col = Cols-1, 
                    Score = currentScoreRow[Cols-1].BestScore,
                }
            };
        }
Esempio n. 12
0
 public void ToggleToolTip(ScoreElement element)
 {
     board.ToggleToolTip(element);
 }
Esempio n. 13
0
        /// <summary>
        /// This is step (2) in the dynamic programming model - to fill in the scoring matrix
        /// and calculate the traceback entries.  This version is used when the open/extension
        /// gap costs are different (affine gap model).
        /// </summary>
        private IEnumerable <OptScoreMatrixCell> CreateAffineTracebackTable()
        {
            /* We will need a low constant number that is not Int32.MinValue
             * for the boundaries of the matrix (if we used Int32.MinValue it would
             * over flow when added to the move score to a very high value and become the max
             * rather than the min).
             */
            int EDGE_MIN_VALUE = Int32.MinValue + Math.Max(Rows, Cols) * Math.Abs(GapOpenCost);


            // Horizontal and vertical gap counts.
            int gapStride = Cols + 1;

            /* These are equivalent to traceback matrices for the
             * horizontal and vertical "gap" matrices.  However, rather than store
             * an arrow that points in a direction, we store the size of moves,
             * which allows us to transition into and out of the gap matrices in one
             * step, rather than following paths through them.
             */
            var matrixSize = checked ((Rows + 1) * gapStride);

            try {
                h_Gap_Length = new int[matrixSize];
                v_Gap_Length = new int[matrixSize];
            }
            catch (OutOfMemoryException oom) {
                throw new OutOfMemoryException(GenerateOOMErrorMessageWhenAllocatingGapTracebacks(), oom);
            }

            /* As we progress through, we only need to know about
             * the current row and the previous row for the recursions,
             * so we only use these two, rather than a full matrix.
             */
            ScoreElement[] previousScoreRow = new ScoreElement[Cols];
            ScoreElement[] currentScoreRow  = new ScoreElement[Cols];
            int[][]        matrix           = SimilarityMatrix.Matrix;

            // Upper left element is initalized to 0
            currentScoreRow [0] = new ScoreElement()
            {
                HorizontalGapScore = EDGE_MIN_VALUE,
                VerticalGapScore   = EDGE_MIN_VALUE,
                MatchScore         = 0
            };
            if (IncludeScoreTable)
            {
                ScoreTable[0] = 0;
            }
            // Initialize first row
            sbyte[] traceback = Traceback [0];
            for (int j = 1; j < traceback.Length; j++)
            {
                // always have to go left from top
                traceback[j]    = SourceDirection.Left;
                h_Gap_Length[j] = j;
                var initialScore = (j - 1) * GapExtensionCost + GapOpenCost;
                currentScoreRow [j] = new ScoreElement()
                {
                    HorizontalGapScore = initialScore,
                    VerticalGapScore   = EDGE_MIN_VALUE,
                    MatchScore         = EDGE_MIN_VALUE
                };
                if (IncludeScoreTable)
                {
                    ScoreTable[j] = initialScore;
                }
            }

            for (int i = 1; i < Rows; i++)
            {
                // Create the next TB row
                traceback     = new sbyte[Cols];
                Traceback [i] = traceback;
                // Make the current row the last row,
                // reuse the current rows memory for the new row
                SwapArrays(ref currentScoreRow, ref previousScoreRow);

                /* Initialize first column
                 * We can't move further back horizontally here (we are at
                 * the edge), so we set the score to something so low we will
                 * never go this direction on the highest scoring path, and so
                 * can avoid explicitly checking for an edge
                 */
                currentScoreRow[0] = new ScoreElement()
                {
                    MatchScore         = EDGE_MIN_VALUE,
                    HorizontalGapScore = EDGE_MIN_VALUE,
                    VerticalGapScore   = (i - 1) * GapExtensionCost + GapOpenCost
                };
                traceback[0] = SourceDirection.Up;
                v_Gap_Length[i * gapStride] = i;

                for (int j = 1; j < Cols; j++)
                {
                    // Get the three important values
                    var cellAbove     = previousScoreRow[j];
                    var cellDiagAbove = previousScoreRow [j - 1];
                    var cellLeft      = currentScoreRow [j - 1];

                    // Gap in reference sequence
                    int scoreAbove;
                    int scoreAboveOpen   = Math.Max(cellAbove.HorizontalGapScore, cellAbove.MatchScore) + GapOpenCost;
                    int scoreAboveExtend = cellAbove.VerticalGapScore + GapExtensionCost;
                    if (scoreAboveOpen > scoreAboveExtend)
                    {
                        scoreAbove = scoreAboveOpen;
                        v_Gap_Length[i * gapStride + j] = 1;
                    }
                    else
                    {
                        scoreAbove = scoreAboveExtend;
                        v_Gap_Length[i * gapStride + j] = v_Gap_Length[(i - 1) * gapStride + j] + 1;
                    }

                    // Gap in query sequence
                    int scoreLeft;
                    int scoreLeftOpen   = Math.Max(cellLeft.MatchScore, cellLeft.VerticalGapScore) + GapOpenCost;
                    int scoreLeftExtend = cellLeft.HorizontalGapScore + GapExtensionCost;
                    if (scoreLeftOpen > scoreLeftExtend)
                    {
                        scoreLeft = scoreLeftOpen;
                        h_Gap_Length[i * gapStride + j] = 1;
                    }
                    else
                    {
                        scoreLeft = scoreLeftExtend;
                        h_Gap_Length[i * gapStride + j] = h_Gap_Length[i * gapStride + (j - 1)] + 1;
                    }

                    // Get the exact match/mismatch score
                    int mScore = (matrix != null) ? matrix[QuerySequence[i - 1]][ReferenceSequence[j - 1]] : SimilarityMatrix[QuerySequence[i - 1], ReferenceSequence[j - 1]];

                    /* Since all possible previous states have the same match score applied,
                     * we can just add to the previous max */
                    int scoreDiag = cellDiagAbove.BestScore + mScore;

                    // Store the scores for this cell
                    currentScoreRow[j] = new ScoreElement()
                    {
                        HorizontalGapScore = scoreLeft,
                        VerticalGapScore   = scoreAbove,
                        MatchScore         = scoreDiag
                    };


                    // Get the max S = MAX(diag,above,left) and assign the traceback
                    if ((scoreDiag > scoreAbove) && (scoreDiag > scoreLeft))
                    {
                        traceback[j] = SourceDirection.Diagonal;
                    }
                    else if (scoreLeft > scoreAbove)
                    {
                        traceback[j] = SourceDirection.Left;
                    }
                    else //if (scoreAbove > scoreLeft)
                    {
                        traceback[j] = SourceDirection.Up;
                    }
                }

                if (IncludeScoreTable)
                {
                    Array.Copy(currentScoreRow.Select(x => x.BestScore).ToArray(), 0, ScoreTable, i * Cols, Cols);
                }
            }

            return(new[]
            {
                new OptScoreMatrixCell
                {
                    Row = Rows - 1,
                    Col = Cols - 1,
                    Score = currentScoreRow[Cols - 1].BestScore,
                }
            });
        }