-
Posts
5883 -
Joined
-
Last visited
-
Days Won
18 -
Feedback
100%
Everything posted by Botre
-
Explain HOW it doesn't work. Try getNpcs().closest()
-
LAST UPDATE: MARCH 10, 2015 You could use Collections by converting the array to a List but that would be more expensive and wouldn't work for primitives. The ArrayUtilities.swapEntriesByIndex(...) method can be found here: http://osbot.org/forum/topic/65570-some-array-utilities-for-your-convenience/ package org.bjornkrols.algorithms.sequence_permutation; import java.util.Random; import org.bjornkrols.utilities.array.ArrayUtilities; /** * Generates a random permutation of a finite set in an unbiased manner. * * These methods can be used both procedurally (by not using the return value) * and as a factory (by calling it on a copy of an existing array for example). * * @param set The set to be shuffled. * @return The shuffled set. * @author Bjorn Krols (Botre) * @version 0.2 * @since March 5, 2015 */ public final class KnuthShuffle { private static final Random RANDOM = new Random(); private KnuthShuffle() { // This class should never be instantiated. // Do not delete or make accessible. } /** * @see KnuthShuffle */ public static boolean[] shuffle(boolean[] set) { int length = set.length; // For each index i of the array, starting at 1 (because i = 0 would systematically return j = 0). for (int i = 1; i < length; i++) { // Find j, a random index between 0 (inclusive) and i (inclusive). int j = RANDOM.nextInt(i + 1); // Swap the entries at indexes i and j. ArrayUtilities.swapEntriesByIndex(set, i, j); } return set; } /** * @see KnuthShuffle */ public static byte[] shuffle(byte[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static short[] shuffle(short[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static char[] shuffle(char[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static int[] shuffle(int[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static long[] shuffle(long[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static float[] shuffle(float[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static double[] shuffle(double[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } /** * @see KnuthShuffle */ public static Object[] shuffle(Object[] set) { int length = set.length; for (int i = 1; i < length; i++) ArrayUtilities.swapEntriesByIndex(set, i, RANDOM.nextInt(i + 1)); return set; } }
-
Would you mind sharing a small implementation of this? For example; what kind of class would/could implement the Activity interface?
-
LAST UPDATE: MARCH 6, 2015 Yes Logs is plural, there's no such thing as "a log" in osrs. package org.bjornkrols.woodcutting; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; /** * @author Bjorn Krols (Botre) * @version 0.0 * @since March 6, 2015 */ public enum Tree { TREE(1, 25f, Logs.LOGS), DYING_TREE(1, 25f, Logs.LOGS), DEAD_TREE(1, 25f, Logs.LOGS), EVERGREEN(1, 25f, Logs.LOGS), JUNGLE_TREE(1, 25f, Logs.LOGS), ACHEY_TREE(1, 25f, Logs.ACHEY_TREE_LOGS), OAK(15, 37.5f, Logs.OAK_LOGS), WILLOW(30, 67.5f, Logs.WILLOW_LOGS), TEAK(35, 85f, Logs.TEAK_LOGS), MAPLE(45, 100f, Logs.MAPLE_LOGS), HOLLOW_TREE(45, 82.5f, Logs.BARK), MAHOGANY(50, 125f, Logs.MAHOGANY_LOGS), ARCTIC_PINE(54, 140f, Logs.ARCTIC_PINE_LOGS), YEW(60, 175f, Logs.YEW_LOGS), MAGIC(75, 250f, Logs.MAGIC_LOGS); private final int chopLevel; private final float chopExperience; private final Logs logs; private Tree(final int chopLevel, final float chopExperience, final Logs logs) { this.chopLevel = chopLevel; this.chopExperience = chopExperience; this.logs = logs; } public int getChopLevel() { return chopLevel; } public boolean canChop(Script script) { return chopLevel <= script.getSkills().getDynamic(Skill.WOODCUTTING); } public float getChopExperience() { return chopExperience; } public Logs getLogs() { return logs; } @Override public String toString() { String string = super.toString().replaceAll("\\s+","").toLowerCase(); return Character.toUpperCase(string.charAt(0)) + string.substring(1); } } package org.bjornkrols.woodcutting; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; /** * @author Bjorn Krols (Botre) * @version 0.1 * @since March 6, 2015 */ public enum Logs { LOGS(1, 40f), ACHEY_TREE_LOGS(1, 40f), OAK_LOGS(15, 60f), WILLOW_LOGS(30, 90f), TEAK_LOGS(35, 105f), ARCTIC_PINE_LOGS(42, 125f), MAPLE_LOGS(45, 135f), BARK(999, 0f), // Can't be burned. MAHOGANY_LOGS(50, 157.5f), YEW_LOGS(60, 202.5f), MAGIC_LOGS(75, 303.8f); private final int burnLevel; private final float burnExperience; private Logs(final int burnLevel, final float burnExperience) { this.burnLevel = burnLevel; this.burnExperience = burnExperience; } public int getBurnLevel() { return burnLevel; } public boolean canBurn(Script script) { return burnLevel <= script.getSkills().getDynamic(Skill.FIREMAKING); } public float getBurnExperience() { return burnExperience; } @Override public String toString() { String string = super.toString().replaceAll("\\s+","").toLowerCase(); return Character.toUpperCase(string.charAt(0)) + string.substring(1); } }
-
- 1
-
-
They were probably a huge pain to test so :p
-
Updated
-
Passing a method as a parameter is tedious imho. I could make fetchCurrentTime() non abstract and have it take a long argument for current time and an int for converting to other time units but the current implementation is more efficient (I could also get rid of fetchCurrentTime() and make the getElaspsed...() methods take those parameters but again, no need for that). Perhaps I misunderstood, if I did feel free to post some pseudocode :p
-
Because it doesn't have a way to the fetch the current time or a valid mtups value to convert between time units and therefore shouldn't be instantiated, only extended.
-
LAST UPDATE: MARCH 6, 2015 package org.bjornkrols.timing; /** * A base for basic timer subclasses. * * @author Bjorn Krols (Botre) * @version 0.1 * @since March 6, 2015 */ public abstract class BasicAbstractTimer { protected long st; protected int mtups; protected BasicAbstractTimer() { start(); } public void start() { st = fetchCurrentTime(); } public void restart() { start(); } protected abstract long fetchCurrentTime(); public double getElapsedDays(){ return getElapsedSeconds() / 86400; } public double getElapsedHours(){ return getElapsedSeconds() / 86400; } public double getElapsedSeconds() { return (fetchCurrentTime() - st) / mtups; } public double getElapsedMilliSeconds() { return getElapsedSeconds() / 1000; } public double getElapsedNanoSeconds() { return getElapsedSeconds() / 1000000000; } public int[] distribute() { int seconds = (int) getElapsedSeconds(); int d[] = new int[4]; d[0] = (seconds / 86400); // Days. d[1] = ((seconds % 86400) / 3600); // Hours. d[2] = (((seconds % 86400) % 3600) / 60); // Minutes. d[3] = (((seconds % 86400) % 3600) % 60); // Seconds. return d; } @Override public String toString() { StringBuilder sb = new StringBuilder(); int[] d = distribute(); for (int i = 0; i < d.length; i++) { sb.append(String.format("%02d", d[(int) i])); if (i != d.length - 1) sb.append(":"); } return sb.toString(); } } package org.bjornkrols.timing; /** * A millisecond precision timer. * * @author Bjorn Krols (Botre) * @version 0.0 * @since March 6, 2015 */ public final class BasicMilliTimer extends BasicAbstractTimer { public BasicMilliTimer() { super(); mtups = 1000; } @Override protected long fetchCurrentTime() { return System.currentTimeMillis(); } @Override public double getElapsedMilliSeconds() { return st - fetchCurrentTime(); } } package org.bjornkrols.timing; /** * A nanosecond precision timer. * * @author Bjorn Krols (Botre) * @version 0.0 * @since March 6, 2015 */ public final class BasicNanoTimer extends BasicAbstractTimer { public BasicNanoTimer() { super(); mtups = 1000000000; } @Override protected long fetchCurrentTime() { return System.nanoTime(); } @Override public double getElapsedNanoSeconds() { return st - fetchCurrentTime(); } }
-
1028 Lesson 44: don't mess up forum games, they are sacred.
-
Lesson 34: "The postcount comment". Omg Mysteryy you almost have 1337 postcount, how amazing I'm so glad for you! Leson 35: "The Mysteryy"
-
Lesson 19: "For no reason whatsoever, try quoting someone quoting you (and be appreciative for the postcount opportunity)". Lesson 7: "The doge". Lesson 8: "The mald". Lesson 23: "Make up a bunch of lessons about spamming".
-
Lesson 17: "Quoting a correct answer unnecessarily, instead of liking it."
-
Dw it's a common mistake, glad you solved it
-
Make sure you are using the OSBot API import. That is: org.osbot.rs07.api.map.Position and not: javax.swing.text.Position
-
Why would you even make a thread about this, ever heard about PMs?