Exemplo n.º 1
0
        /**
         * <code>compareRatings</code> compares all the ratings of <code>PossibleTarget</code>s and retuns the best ones
         * @param possibleTargets	an array of all the PossibleTargets
         * @return bestOptions, the list of the best PossibleTargets
         */
        private List <PossibleTarget> compareRatings(List <PossibleTarget> possibleTargets)
        {
            // create list bestOptions, which will be all the PossibleTargets with the same and highest values
            List <PossibleTarget> bestOptions = new List <PossibleTarget>();
            // set the first possibleTarget as current best target
            PossibleTarget highestRating = possibleTargets[0];

            // Add this target to the list of bestOptions
            bestOptions.Add(highestRating);
            // Loop through all the possibleTargets and compare their ratings
            for (int k = 1; k < possibleTargets.Count; k++)
            {
                if (highestRating.rating < possibleTargets[k].rating)                   // if one with a higher rating is found, empty the list and add this as best
                {
                    bestOptions.Clear();
                    highestRating = possibleTargets[k];
                    bestOptions.Add(possibleTargets[k]);
                }
                else if (highestRating.rating == possibleTargets[k].rating)                     // else (same ratings), add the current rating to bestOptions
                {
                    bestOptions.Add(possibleTargets[k]);
                }
            }
            return(bestOptions);
        }
Exemplo n.º 2
0
        /**
         * <code>compareFactor</code> compares <code>Factor</code> values between two <code>PossibleSpot</code>s
         * @param factor			the <code>Factor</code> that has to be compared
         * @param compareOptions	the list of PossibleTargets that have to be compared
         * @return equals			, the list of PossibleTargets (in this case the length is either 1 or 0)
         */
        private List <PossibleTarget> compareFactor(Factor factor, List <PossibleTarget> compareOptions)
        {
            // Set the first possibleTarget as the current best target
            PossibleTarget best = compareOptions[0];
            // 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(compareOptions[0]);
            // Create a new Boolean[] that will contain the results of comparePossibleTargets
            Boolean[] compares = new Boolean[2];
            // Loop through all the PossibleTargets and compare the values of the factors
            for (int k = 1; k < compareOptions.Count; k++)
            {
                // set the current PossibleTarget as 'current'
                PossibleTarget current = compareOptions[k];
                // Compare the current with the best PossibleTarget, based on a factor
                compares = comparePossibleTargets(factor, current, best);
                if (compares[0])                  // if current >/< than the best, remove the best from the list and set this as best and add to list
                {
                    equals.Clear();
                    best = current;
                    equals.Add(best);
                }
                else if (compares[1])                    // else (current==best), clear the list and break (as it turns out there are more than one with the same valuees)
                {
                    equals.Clear();
                    break;
                }
            }
            return(equals);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /**
         * <code>comparePossibleTargets</code> is used in <code>rateFactor</code> to compare two <code>PossibleTargets</code>'s factor values.
         * @param factor	the factor of which the value has to be compared
         * @param possible	the first PossibleSpot (the one that will be placed before the evaluation symbol)
         * @param best		the second PossibleSpot (the one that will be placed behind the evaluation symbol)
         * @return result	an Boolean[2] array. Index 0 will contain true/false for the >/< evaluator and Index 1 will contain the true/false for the == evaluator.
         */
        private Boolean[] comparePossibleTargets(Factor factor, PossibleTarget possible, PossibleTarget best)
        {
            // Create a new Boolean[] that will contain the results of comparePossibleTargets
            Boolean[] result = new Boolean[2];
            //System.out.println("Spots: " + possible.toGoalSpot().toString() + ", " + best.toGoalSpot().toString());

            // Look at which factor has to be compared and compare them between two PossibleTargets
            if (factor == Factor.TPD)
            {
                result [0] = (possible.getTPD() > best.getTPD());
                result [1] = possible.getTPD() == best.getTPD();
                //System.out.println("result 0: " + result[0]);
                //System.out.println("result 1: " + result[1]);
            }
            else if (factor == Factor.ST)
            {
                result [0] = possible.getSurThreat() < best.getSurThreat();
                result [1] = possible.getSurThreat() == best.getSurThreat();
            }
            else if (factor == Factor.SD)
            {
                result [0] = possible.getSD() < best.getSD();
                result [1] = possible.getSD() == best.getSD();
            }
            else if (factor == Factor.FDC)
            {
                result [0] = possible.getCalcCost() < best.getCalcCost();
                result [1] = possible.getCalcCost() == best.getCalcCost();
            }
            else if (factor == Factor.HD)
            {
                result[0] = possible.getHighestDanger() < best.getHighestDanger();
                result[1] = possible.getHighestDanger() == best.getHighestDanger();
            }
            return(result);
        }
Exemplo n.º 5
0
        /**
         * <code>pickTarget</code> picks the best <code>GoalSpot</code> based on:<br>
         * <ul>
         *      <li> TPD (Total Player Distance): How far are all players away from the <code>GoalSpot</code>?</li>
         *      <li> SD (Spot Distance): How far away is the MovingSpot away from the <code>GoalSpot</code>?</li>
         *      <li> FDC (Fastest Danger Cost): How dangerous is the fastest path to the <code>GoalSpot</code>?</li>
         *      <li> ST (Surround Threat): How dangerous is the area around the <code>GoalSpot</code>?</li>
         *      <li> HD (Highest Danger): What is the highest danger level while moving over the FDC-path to the <code>GoalSpot</code>?</li>
         * </ul>
         * @param allGoals	the array of all the GoalSpots on the Playfield
         * @return target	the GoalSpot that is the best choice to move to
         */
        public GoalSpot pickTarget(List <GoalSpot> allGoals)
        {
            // Create the empty array that will contain all the PossibleTargets.
            List <PossibleTarget> possibleTargets = new List <PossibleTarget>();

            // Create all the PossibleTargets (out of GoalSpots) and set the correct values for HD, TPD, SD, FDC and ST.
            for (int i = 0; i < allGoals.Count; i++)
            {
                //System.out.println("\nGOAL " + i);
                GoalSpot current = allGoals[i];
                possibleTargets[i] = new PossibleTarget(current);
                PossibleTarget possible       = possibleTargets[i];
                int            calculatedCost = 0;
                double         penalty        = 1;

                // Calculate the Fastest Danger Cost to this spot
                calculatedCost = current.calculateDangerCost(x, y, possible);

                //TODO: Move to the calculateSurround() in GoalSpot
                // Check if the GoalSpot is located against the wall and add a penalty
                if (current.getX() == 0 || current.getX() == playfield.width - 1 ||
                    current.getY() == playfield.height || current.getY() == 0)
                {
                    penalty = 1.6;
                }

                // Set all the values for the variables in PossibleTarget
                possible.setTPD(current.getTPD());
                possible.setSD(current.getSD());
                possible.setPenalty(penalty);
                possible.setCalcCost(calculatedCost);
                int weightedSurThreat = (int)(current.calculateSurround() * penalty);
                possible.setSurThreat(weightedSurThreat);
                //System.out.println("HD: " + possible.getHighestDanger());
                //System.out.println("TPD: " + current.getTPD());
                //System.out.println("SD: " + current.getSD());
                //System.out.println("ST: " + weightedSurThreat);
                //System.out.println("FDC: " + calculatedCost);
            }

            // Loop through all factors and rate them for each of the PossibleTargets
            foreach (Factor factor in factors)
            {
                possibleTargets = rateFactor(possibleTargets, factor);
            }


            // Create a new list BestOptions to compare the ratings
            List <PossibleTarget> bestOptions = new List <PossibleTarget>();

            // Compare ratings between all the PossibleTargets
            bestOptions = compareRatings(possibleTargets);

            // Check if bestOptions.size() is 1, as that means there is only one best Spot -> return this spot
            if (bestOptions.Count == 1)
            {
                //System.out.println("Found directly!");
                return(bestOptions[0].toGoalSpot());
            }             // Else: Continue with all the best options left

            // Make new list to be rated on independent factors (bestOptions = backup)
            //List<PossibleTarget> compareOptions = bestOptions;
            // Loop through all the factors and compare them for all the remaining best options
            //System.out.println("Compare again: ");
            foreach (Factor current in factors)
            {
                //System.out.println(bestOptions.get(0).toString());
                //System.out.println(bestOptions.get(1).toString());
                List <PossibleTarget> compareOptions = compareFactor(current, bestOptions);
                // If the list has a size of 1 then, a result has been found and return this GoalSpot
                if (compareOptions.Count == 1)
                {
                    return(compareOptions[0].toGoalSpot());
                    // Else reset compareOptions with bestOptions and then try again for the next factor

                    /*} else {
                     * compareOptions = bestOptions; */
                }
            }
            //System.out.println("Random: ");
            //If all else fails, pick a random target from the original PossibleTargets
            return(pickRandomGoal(bestOptions));
        }