Android Open Source - ubisoldiers Search Engine






From Project

Back to project page ubisoldiers.

License

The source code is released under:

MIT License

If you think the Android project ubisoldiers listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.gobbisanches.ubisoldiers.mechanics;
/*from ww  w  .  java2s  .  c o  m*/
import android.util.Log;

import java.util.Comparator;
import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Created by Sanches on 05/07/2014.
 */
public class SearchEngine {
    SortedSet<Item> allItems;
    Integer sumOfQualityOfAllItems;

    public SearchEngine() {
        allItems = General.getPlayerGeneral().getAllMissingItemsSortedByQuality();
        sumOfQualityOfAllItems = 0;
        for(Item item : allItems) {
            sumOfQualityOfAllItems += item.getQuality();
        }
    }

    public Item performSearch(Random random, double multiplier) {
        return getItemForRoll(performRoll(random, multiplier, sumOfQualityOfAllItems));
    }

    private int performRoll(Random random, double multiplier, int maxValue) {
        int initialRoll = Math.abs(random.nextInt(maxValue));
        int roll = Math.min((int) Math.floor(initialRoll * multiplier), maxValue);

        Log.d("UBISOLDIERS", "[SEARCHENGINE] maxValue = " + maxValue);
        Log.d("UBISOLDIERS", "[SEARCHENGINE] initialRoll = " + initialRoll);
        Log.d("UBISOLDIERS", "[SEARCHENGINE] roll = " + roll);

        return roll;
    }

    private Item getItemForRoll(int roll) {
        for (Item item : allItems) {
            roll -= item.getQuality();
            if(roll <= 0) {
                return item;
            }
        }

        throw new RuntimeException("Error: Could not find any Item for roll " + roll);
    }

    public boolean hasPlayerNoMissingItems() {
        return (allItems.isEmpty());
    }
}




Java Source Code List

com.github.gobbisanches.ubisoldiers.app.ArmyFragment.java
com.github.gobbisanches.ubisoldiers.app.BattleActivity.java
com.github.gobbisanches.ubisoldiers.app.BattleFragment.java
com.github.gobbisanches.ubisoldiers.app.ItemListFragment.java
com.github.gobbisanches.ubisoldiers.app.MainActivity.java
com.github.gobbisanches.ubisoldiers.app.ResourceManager.java
com.github.gobbisanches.ubisoldiers.app.SingleFragmentActivity.java
com.github.gobbisanches.ubisoldiers.app.UbisoldierUosApplication.java
com.github.gobbisanches.ubisoldiers.app.UbisoldiersDriver.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationActivity.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationFragment.java
com.github.gobbisanches.ubisoldiers.app.UnitFragment.java
com.github.gobbisanches.ubisoldiers.app.UosManager.java
com.github.gobbisanches.ubisoldiers.mechanics.Armor.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogEntry.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogParser.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLog.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleSquad.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleUnit.java
com.github.gobbisanches.ubisoldiers.mechanics.Battle.java
com.github.gobbisanches.ubisoldiers.mechanics.DefaultGameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.GameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.General.java
com.github.gobbisanches.ubisoldiers.mechanics.ItemCollection.java
com.github.gobbisanches.ubisoldiers.mechanics.Item.java
com.github.gobbisanches.ubisoldiers.mechanics.MechanicsEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.PolicyManager.java
com.github.gobbisanches.ubisoldiers.mechanics.SearchEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.Soldier.java
com.github.gobbisanches.ubisoldiers.mechanics.Squad.java
com.github.gobbisanches.ubisoldiers.mechanics.Unit.java
com.github.gobbisanches.ubisoldiers.mechanics.Weapon.java