Jump to content

Botre

Members
  • Posts

    5883
  • Joined

  • Last visited

  • Days Won

    18
  • Feedback

    100%

Posts posted by Botre

  1.  

    The issue is that the tabs don't actually switch randomly. Code is compatible but not functioning right.

    private static int rngTab = random(0, 125);  
    	private enum Tabs {
    		ATTACK(0, Tab.ATTACK);
    		private int chance;
    		private Tab tab;
    
    		public int getChance() {
    			return chance;
    		}
    
    		public Tab getTab() {
    			return tab;
    		}
    
    		private static Set<Tabs> tab_set = Collections.unmodifiableSet(EnumSet.allOf(Tabs.class));
    
    		public static Optional<Tabs> forTabs(int rng) {
    			return tab_set.stream().filter(Objects::nonNull).filter(tabs -> tabs.getChance() == rng).findAny();
    		}
    
    		public static void randomTabs(Script script, int chance) {
    			if (rngTab == forTabs(chance).get().getChance()) {
    				script.getTabs().open(forTabs(chance).get().getTab());
    			}
    		}
    
    		private Tabs(int chance, Tab tab) {
    			this.chance = chance;
    			this.tab = tab;
    		}
    	}
    
    if (getState() == BotState.FISHING) {
    			Tabs.randomTabs(this, 0);
    			return;
    		}
    

     

     

    I know it's overkill, but little better than using switch.

     

    Here is something a tad bit more clean and re-usable/generic :)

    import java.util.Random;
    
    public class EnumUtil {
        
        public static <T extends Enum<?>> T getRandomEnumValue(Class<T> clazz, Random random) {
            int constants = clazz.getEnumConstants().length;
            if(constants == 0) {
                throw new IllegalArgumentException("Enum class has no constants");
            }
            return clazz.getEnumConstants()[random.nextInt(constants)];
        }
    
        public static void main(String[] args) {
            Random  random = new Random();
            Tab tab = EnumUtil.getRandomEnumValue(Tab.class, random);
        }
        
    }
    
    • Like 1
  2. The Hashtable class is obsolete.
    You're using a Hashtable without overriding the key class' hashCode() & equals() methods.
    You hardcoded your base case (if 4 == r).
    3 ints and 2 object references per node. Memory.
    Redundant calls to table.contains(key) & table.get(key).

    The way you construct your TreeNode class is the opposite of elegant and intuitive.

     

    Your algo might not be O(n^2) but if your pseudo code looked anything like this Java implementation, I can't blame the TA for not giving you a perfect grade.

     

    • Like 1
  3. Unfortunately I haven't mastered much of the domain-specific vocabulary that would allow me to express my subjective opinion in a way that would help your artistic progress.

     

    But I won't let that silence me nor turn me into a liar. 

     

    shit

     

    *goes away* 

     

    Just because someone is unable to express an opinion doesn't mean he's not entitled to it :) 

×
×
  • Create New...