Esempio n. 1
0
    void OnGUI()
    {
        // GUIの見た目を変える。
        GUIStyle      guiStyle   = new GUIStyle();
        GUIStyleState styleState = new GUIStyleState();

        // GUI背景色のバックアップ
        Color backColor = GUI.backgroundColor;

        // GUI背景の色を設定
        GUI.backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);

        // 背景用テクスチャを設定
        styleState.background = Texture2D.whiteTexture;

        // テキストの色を設定
        styleState.textColor = Color.green;

        // スタイルの設定。
        guiStyle.normal = styleState;

        if (GameRuler.isInGame())
        {
            GUI.Label(new Rect(130, 0, 65, 20), "Score " + Scorer.GetScore(), guiStyle);
        }
        else if (GameRuler.isGameOver())
        {
            GUI.Label(new Rect(0, 0, Screen.width, Screen.height), "GameOver", guiStyle);
        }
        else if (GameRuler.isGoal())
        {
            GUI.Label(new Rect(0, 0, Screen.width, Screen.height), "Goal", guiStyle);
            GUI.Label(new Rect(130, 0, 65, 20), "Score " + Scorer.GetScore(), guiStyle);
        }
    }
Esempio n. 2
0
    public void TestTwoPlayerAllOwnedOne()
    {
        var player  = new Player(new ArmyManager(), new Color(0, 0, 0));
        var player2 = new Player(new ArmyManager(), new Color(0, 0, 0));
        var players = new List <Player>();

        players.Add(player);
        players.Add(player2);
        var scorer = new Scorer();
        var world  = new World(MAPSFILE);
        int sum    = 0;

        for (int i = 0; i < World.WIDTH; i++)
        {
            for (int j = 0; j < World.HEIGHT; j++)
            {
                Province p = world.GetProvinceAt(new Pos(i, j));
                p.Owner = player;
                if (p.City != null)
                {
                    sum += p.City.Points;
                }
            }
        }

        scorer.UpdateScores(world);

        Assert.AreEqual(sum, scorer.GetScore(player));
        Assert.AreEqual(0, scorer.GetScore(player2));
    }
Esempio n. 3
0
            public override sealed void Collect(int doc)
            {
                //System.out.println("Q1: Doc=" + doc + " score=" + score);
                float score = scorer.GetScore();

                Assert.IsTrue(score == 1.0f, "got score=" + score);
                base.Collect(doc);
            }
Esempio n. 4
0
            public override sealed void Collect(int doc)
            {
                //System.out.println("Q2: Doc=" + doc + " score=" + score);
                float score = scorer.GetScore();

                Assert.AreEqual(1.0f + doc, score, 0.00001f);
                base.Collect(doc);
            }
Esempio n. 5
0
            public override float GetScore()
            {
                float rawScore  = m_innerScorer.GetScore();
                long  timeVal   = (long)m_termList.GetRawValue(m_orderArray.Get(m_innerScorer.DocID));
                float timeScore = m_parent.ComputeTimeFactor(timeVal);

                return(RecencyBoostScorerBuilder.CombineScores(timeScore, rawScore));
            }
Esempio n. 6
0
 /// <summary>
 /// <seealso cref="Scorer.GetScore"/>
 /// </summary>
 public override float GetScore()
 {
     for (int i = 0; i < valSrcScorers.Length; i++)
     {
         vScores[i] = valSrcScorers[i].GetScore();
     }
     return(qWeight * provider.CustomScore(subQueryScorer.DocID, subQueryScorer.GetScore(), vScores));
 }
Esempio n. 7
0
            public override float GetScore()
            {
                float score = qWeight * scorer.GetScore() * vals.SingleVal(scorer.DocID);

                // Current Lucene priority queues can't handle NaN and -Infinity, so
                // map to -Float.MAX_VALUE. This conditional handles both -infinity
                // and NaN since comparisons with NaN are always false.
                return(score > float.NegativeInfinity ? score : -float.MaxValue);
            }
Esempio n. 8
0
 public override double DoubleVal(int document)
 {
     try
     {
         return(scorer.GetScore());
     }
     catch (IOException exception)
     {
         throw new Exception(exception.ToString(), exception);
     }
 }
 public override double DoubleVal(int document)
 {
     try
     {
         return(scorer.GetScore());
     }
     catch (Exception exception) when(exception.IsIOException())
     {
         throw RuntimeException.Create(exception);
     }
 }
Esempio n. 10
0
 public override double DoubleVal(int document)
 {
     try
     {
         Debug.Assert(document == scorer.DocID);
         return(scorer.GetScore());
     }
     catch (IOException exception)
     {
         throw new Exception(exception.ToString(), exception);
     }
 }
Esempio n. 11
0
    public void TestSinglePlayerNoneOwned()
    {
        var player  = new Player(new ArmyManager(), new Color(0, 0, 0));
        var players = new List <Player>();

        players.Add(player);
        var scorer = new Scorer();

        scorer.UpdateScores(new World(MAPSFILE));

        Assert.AreEqual(0, scorer.GetScore(player));
    }
Esempio n. 12
0
        public override double DoubleVal(int document)
        {
            try
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(document == scorer.DocID);
                }

#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
                return(scorer.GetScore());
#else
                // LUCENENET specific: The intermediate cast to decimal is required here to prevent us from losing precision on x86 .NET Framework with optimizations enabled
                return((double)(decimal)scorer.GetScore());
#endif
            }
            catch (Exception exception) when(exception.IsIOException())
            {
                throw RuntimeException.Create(exception);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// NOTE: This was floatVal() in Lucene
        /// </summary>
        public override float SingleVal(int doc)
        {
            try
            {
                if (doc < lastDocRequested)
                {
                    if (noMatches)
                    {
                        return(defVal);
                    }
                    scorer = weight.GetScorer(readerContext, acceptDocs);
                    if (scorer == null)
                    {
                        noMatches = true;
                        return(defVal);
                    }
                    scorerDoc = -1;
                }
                lastDocRequested = doc;

                if (scorerDoc < doc)
                {
                    scorerDoc = scorer.Advance(doc);
                }

                if (scorerDoc > doc)
                {
                    // query doesn't match this document... either because we hit the
                    // end, or because the next doc is after this doc.
                    return(defVal);
                }

                // a match!
                return(scorer.GetScore());
            }
            catch (IOException e)
            {
                throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
            }
        }
Esempio n. 14
0
        public void DistanceTest()
        {
            Scorer scorer = new Scorer();
            City   city   = new City
            {
                FullName  = "Test 123456798",
                ShortName = "Test",
                Latitude  = 90,
                Longitude = 0
            };

            double score = scorer.GetScore(city, "Test", 90, 0);

            Assert.AreEqual(1.00, score); // perfect name, perfect distance
            score = scorer.GetScore(city, "", 90, 0);
            Assert.AreEqual(0.50, score); // no name, perfect distance
            score = scorer.GetScore(city, "", -90, 180);
            Assert.AreEqual(0.00, score); // no name, distance as far as possible
            score = scorer.GetScore(city, "", -90, -180);
            Assert.AreEqual(0.00, score); // no name, distance as far as possible (other way)
            score = scorer.GetScore(city, "", 0, 90);
            Assert.AreEqual(0.25, score); // no name, distance half way
            score = scorer.GetScore(city, "", 0, -90);
            Assert.AreEqual(0.25, score); // no name, distance half way (other way)
        }
Esempio n. 15
0
        public override ValueFiller GetValueFiller()
        {
            //
            // TODO: if we want to support more than one value-filler or a value-filler in conjunction with
            // the FunctionValues, then members like "scorer" should be per ValueFiller instance.
            // Or we can say that the user should just instantiate multiple FunctionValues.
            //
            return(new ValueFiller.AnonymousValueFiller <MutableValueSingle>(new MutableValueSingle(), fillValue: (doc, mutableValue) =>
            {
                try
                {
                    if (noMatches)
                    {
                        mutableValue.Value = defVal;
                        mutableValue.Exists = false;
                        return;
                    }
                    scorer = weight.GetScorer(readerContext, acceptDocs);
                    scorerDoc = -1;
                    if (scorer == null)
                    {
                        noMatches = true;
                        mutableValue.Value = defVal;
                        mutableValue.Exists = false;
                        return;
                    }
                    lastDocRequested = doc;

                    if (scorerDoc < doc)
                    {
                        scorerDoc = scorer.Advance(doc);
                    }

                    if (scorerDoc > doc)
                    {
                        // query doesn't match this document... either because we hit the
                        // end, or because the next doc is after this doc.
                        mutableValue.Value = defVal;
                        mutableValue.Exists = false;
                        return;
                    }

                    // a match!
                    mutableValue.Value = scorer.GetScore();
                    mutableValue.Exists = true;
                }
                catch (IOException e)
                {
                    throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
                }
            }));
        }
Esempio n. 16
0
        protected override void AfterNext()
        {
            Scorer sub = m_subScorers[0];

            m_doc = sub.DocID;
            if (m_doc != NO_MORE_DOCS)
            {
                m_score      = sub.GetScore();
                m_nrMatchers = 1;
                CountMatches(1);
                CountMatches(2);
            }
        }
Esempio n. 17
0
            public override float GetScore()
            {
                float score = m_innerScorer.GetScore();

                foreach (BoboDocScorer facetScorer in m_facetScorers)
                {
                    float fscore = facetScorer.Score(m_docid);
                    if (fscore > 0.0)
                    {
                        score *= fscore;
                    }
                }
                return(score);
            }
Esempio n. 18
0
            public virtual void Collect(int doc)
            {
                docTermOrds.SetDocument(doc);
                long ord;

                while ((ord = docTermOrds.NextOrd()) != SortedSetDocValues.NO_MORE_ORDS)
                {
                    docTermOrds.LookupOrd(ord, joinValue);
                    if (!joinValueToJoinScores.TryGetValue(joinValue, out JoinScore joinScore) || joinScore == null)
                    {
                        joinValueToJoinScores[BytesRef.DeepCopyOf(joinValue)] = joinScore = new JoinScore();
                    }
                    joinScore.AddScore(scorer.GetScore());
                }
            }
 public override double DoubleVal(int document)
 {
     try
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(document == scorer.DocID);
         }
         return(scorer.GetScore());
     }
     catch (Exception exception) when(exception.IsIOException())
     {
         throw RuntimeException.Create(exception);
     }
 }
Esempio n. 20
0
        public void BasicTest()
        {
            Scorer scorer = new Scorer();
            City   city   = new City
            {
                FullName  = "London, ON, Canada",
                ShortName = "London",
                Latitude  = 42.98339,
                Longitude = -81.23304
            };

            double score = scorer.GetScore(city, "London", null, null);

            Assert.AreEqual(1.00, score); // perfect name, perfect distance
            score = scorer.GetScore(city, "Lon", null, null);
            Assert.AreEqual(0.75, score); // half name, perfect distance
            score = scorer.GetScore(city, "", null, null);
            Assert.AreEqual(0.50, score); // no name, perfect distance

            score = scorer.GetScore(city, "London", 42.98339, -81.23304);
            Assert.AreEqual(1.00, score); // perfect name, perfect distance
            score = scorer.GetScore(city, "", 42.98339, -81.23304);
            Assert.AreEqual(0.50, score); // no name, perfect distance
        }
Esempio n. 21
0
 public void Collect(int doc)
 {
     docs.AddDoc(doc);
     if (keepScores)
     {
         if (totalHits >= scores.Length)
         {
             float[] newScores = new float[ArrayUtil.Oversize(totalHits + 1, 4)];
             Array.Copy(scores, 0, newScores, 0, totalHits);
             scores = newScores;
         }
         scores[totalHits] = scorer.GetScore();
     }
     totalHits++;
 }
Esempio n. 22
0
    public void TestParameterizedOnePlayer(int num)
    {
        var player  = new Player(new ArmyManager(), new Color(0, 0, 0));
        var players = new List <Player>();

        players.Add(player);
        var scorer = new Scorer();
        var world  = new World();
        var prov   = world.GetProvinceAt(new Pos(0, 0));

        prov.City  = new City("Urbana", num);
        prov.Owner = player;
        scorer.UpdateScores(world);

        Assert.AreEqual(num, scorer.GetScore(player));
    }
Esempio n. 23
0
            public virtual void Collect(int doc)
            {
                terms.Get(doc, spare);
                BytesRef joinValue = spare;

                if (joinValue.Length == 0 && !docsWithField.Get(doc))
                {
                    return;
                }

                if (!joinValueToJoinScores.TryGetValue(joinValue, out JoinScore joinScore) || joinScore == null)
                {
                    joinValueToJoinScores[BytesRef.DeepCopyOf(joinValue)] = joinScore = new JoinScore();
                }
                joinScore.AddScore(scorer.GetScore());
            }
Esempio n. 24
0
            public virtual void Collect(int doc)
            {
                docTermOrds.SetDocument(doc);
                long ord;

                while ((ord = docTermOrds.NextOrd()) != SortedSetDocValues.NO_MORE_ORDS)
                {
                    docTermOrds.LookupOrd(ord, joinValue);
                    var joinScore = JoinValueToJoinScores.ContainsKey(joinValue) ? JoinValueToJoinScores[joinValue] : null;
                    if (joinScore == null)
                    {
                        JoinValueToJoinScores[BytesRef.DeepCopyOf(joinValue)] = joinScore = new JoinScore();
                    }
                    joinScore.AddScore(scorer.GetScore());
                }
            }
Esempio n. 25
0
        public override double DoubleVal(int document)
        {
            try
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(document == scorer.DocID);
                }

                // LUCENENET specific: The explicit cast to float is required here to prevent us from losing precision on x86 .NET Framework with optimizations enabled
                return((float)scorer.GetScore());
            }
            catch (Exception exception) when(exception.IsIOException())
            {
                throw RuntimeException.Create(exception);
            }
        }
Esempio n. 26
0
            public virtual void Collect(int doc)
            {
                terms.Get(doc, spare);
                BytesRef joinValue = spare;

                if (joinValue.Length == 0 && !docsWithField.Get(doc))
                {
                    return;
                }

                var joinScore = JoinValueToJoinScores.ContainsKey(joinValue) ? JoinValueToJoinScores[joinValue] : null;

                if (joinScore == null)
                {
                    JoinValueToJoinScores[BytesRef.DeepCopyOf(joinValue)] = joinScore = new JoinScore();
                }
                joinScore.AddScore(scorer.GetScore());
            }
Esempio n. 27
0
        /// <summary>
        /// Score similarity of given text with this Violation.  Lower is better.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public virtual int ScoreMatchingText(string text)
        {
            IList <int> phraseScores = new List <int>();

            if (!string.IsNullOrEmpty(this.Keywords))
            {
                // score against each keyword
                foreach (string vKeyphrase in this.Keywords.Split(','))
                {
                    if (!string.IsNullOrEmpty(vKeyphrase))
                    {
                        phraseScores.Add(Scorer.GetScore(vKeyphrase, text));
                    }
                }
            }
            else
            {
                phraseScores.Add(Scorer.GetScore(this.Name, text));
            }

            return(phraseScores.Any() ? phraseScores.Min() : 1000);
        }
Esempio n. 28
0
            public virtual void Collect(int docNr)
            {
                float score = scorer.GetScore();

                docNr += docBase;
                /* System.out.println(docNr + " '" + dBase.getDocs()[docNr] + "': " + score); */
                Assert.True(score > 0.0, parent.QueryText + ": positive score");
                Assert.True(totalMatched < parent.ExpectedDocNrs.Length, parent.QueryText + ": too many hits");
                int i;

                for (i = 0; i < parent.expectedDocNrs.Length; i++)
                {
                    if ((!encountered[i]) && (parent.ExpectedDocNrs[i] == docNr))
                    {
                        encountered[i] = true;
                        break;
                    }
                }
                if (i == parent.ExpectedDocNrs.Length)
                {
                    Assert.True(false, parent.QueryText + ": doc nr for hit not expected: " + docNr);
                }
                totalMatched++;
            }
        public virtual void Collect(int parentDoc)
        {
            //System.out.println("\nC parentDoc=" + parentDoc);
            totalHitCount++;

            float score = float.NaN;

            if (trackMaxScore)
            {
                score    = scorer.GetScore();
                maxScore = Math.Max(maxScore, score);
            }

            // TODO: we could sweep all joinScorers here and
            // aggregate total child hit count, so we can fill this
            // in getTopGroups (we wire it to 0 now)

            if (queueFull)
            {
                //System.out.println("  queueFull");
                // Fastmatch: return if this hit is not competitive
                for (int i = 0; ; i++)
                {
                    int c = reverseMul[i] * comparers[i].CompareBottom(parentDoc);
                    if (c < 0)
                    {
                        // Definitely not competitive.
                        //System.out.println("    skip");
                        return;
                    }
                    if (c > 0)
                    {
                        // Definitely competitive.
                        break;
                    }
                    if (i == compEnd)
                    {
                        // Here c=0. If we're at the last comparer, this doc is not
                        // competitive, since docs are visited in doc Id order, which means
                        // this doc cannot compete with any other document in the queue.
                        //System.out.println("    skip");
                        return;
                    }
                }

                //System.out.println("    competes!  doc=" + (docBase + parentDoc));

                // This hit is competitive - replace bottom element in queue & adjustTop
                for (int i = 0; i < comparers.Length; i++)
                {
                    comparers[i].Copy(bottom.Slot, parentDoc);
                }
                if (!trackMaxScore && trackScores)
                {
                    score = scorer.GetScore();
                }
                bottom.Doc           = docBase + parentDoc;
                bottom.readerContext = currentReaderContext;
                bottom.Score         = score;
                CopyGroups(bottom);
                bottom = queue.UpdateTop();

                for (int i = 0; i < comparers.Length; i++)
                {
                    comparers[i].SetBottom(bottom.Slot);
                }
            }
            else
            {
                // Startup transient: queue is not yet full:
                int comparerSlot = totalHitCount - 1;

                // Copy hit into queue
                for (int i = 0; i < comparers.Length; i++)
                {
                    comparers[i].Copy(comparerSlot, parentDoc);
                }
                //System.out.println("  startup: new OG doc=" + (docBase+parentDoc));
                if (!trackMaxScore && trackScores)
                {
                    score = scorer.GetScore();
                }
                OneGroup og = new OneGroup(comparerSlot, docBase + parentDoc, score, joinScorers.Length, trackScores);
                og.readerContext = currentReaderContext;
                CopyGroups(og);
                bottom    = queue.Add(og);
                queueFull = totalHitCount == numParentHits;
                if (queueFull)
                {
                    // End of startup transient: queue just filled up:
                    for (int i = 0; i < comparers.Length; i++)
                    {
                        comparers[i].SetBottom(bottom.Slot);
                    }
                }
            }
        }
Esempio n. 30
0
 public virtual void Collect(int doc)
 {
     scores[0] = scorer.GetScore();
 }