Exemplo n.º 1
0
        /**
         * <code>rateFactor</code> will rate the given <code>factor</code> and will give the correct rating for each of the <code>PossibleTargets</code>.
         * @param possibleTargets	an array of all the PossibleTargets on the Playfield
         * @param factor			the name of the factor that will be rated
         * @return possibleTargets	the updated array of all PossibleTargets with updated ratings
         */
        private List <PossibleTarget> rateFactor(List <PossibleTarget> possibleTargets, Factor factor)
        {
            // Set the first possibleTarget as the current best target
            PossibleTarget best = possibleTargets[0];

            // Create a new Boolean[] that will contain the results of comparePossibleTargets
            Boolean[] compares = new Boolean[2];
            // Set the rating to the corresponding Factor rating
            double rating = factor.getRating();
            //System.out.println("rating: " + rating);
            // Create new list that will contain all the equals
            List <PossibleTarget> equals = new List <PossibleTarget>();

            // Add the current best to the list of equals
            equals.Add(best);
            double bestRating = best.getRating();

            bestRating = (best.getRating() + rating);
            // Loop through all the PossibleTargets and compare them with the current best
            for (int k = 1; k < possibleTargets.Count; k++)
            {
                // Set the current possibleTarget as 'current'
                PossibleTarget current = possibleTargets[k];
                // Compare the current with the best PossibleTarget, based on a factor
                //System.out.println("current " + current.toString());
                //System.out.println("best" + best.toString());
                compares = comparePossibleTargets(factor, current, best);
                //System.out.println("Compares: [0]=" + compares[0] + ", compares[1]=" + compares[1]);
                if (compares[0] == true)                // if current >/< than the best, remove the best from the list and set this as best and add to list
                {
                    for (int j = 0; j < equals.Count; j++)
                    {
                        double equalsRating = equals[j].getRating();
                        equalsRating = equals[j].getRating() - rating;
                    }
                    equals.Clear();
                    best        = current;
                    best.rating = best.rating + rating;
                    equals.Add(best);
                }
                else if (compares[1])                     // else (current==best), name this one as best and add this one also to the list
                {
                    best        = current;
                    best.rating = best.rating + rating;
                    equals.Add(best);
                }
            }

            /*for(PossibleTarget pt : possibleTargets) {
             *      System.out.println("Rating: " + pt.rating);
             * }*/
            return(possibleTargets);
        }