package agents; import java.util.ArrayList; import java.util.Random; import master.Product; public class AgentWin extends Agent { public AgentWin(String id) { super(id); // TODO Auto-generated constructor stub } boolean debug = false; double [] seedList; int count = 0; int seed = 0; Random master = new Random(-1); @Override public boolean willBuy(Product prod, double probOfGood) { //Reverse the generator, find the seed, then always choose the correct answer if(count++ == 0 || count>1000){ print("[re]initing seed"); count = 1; master = new Random(findSeed(prod.getValue(),prod.getPrice(),count)); } double price = master.nextDouble(); double value = master.nextDouble(); double draw = master.nextDouble(); if(draw<=probOfGood){ return true; } return false; } public int findSeed(double value,double price,int count){ return findSeed(price/value,count); } public int findSeed(double target,int count){ /*This is cool. Seeds are at most 32 bits wide (int), which we have further restricted to 0-9999 * (last 4 digits of A#). * doubles are 64 bits wide, with 46 of the bits available for the fractional component. * * Due to the reduced search space, and low likelyhood of having neighboring doubles map to * seeds [46bits->32bits], you can reverse the random number generator to find the seed. * * A confounding factor is that the doubles coming in (price and value) must be divided to find the * Random number that was generated by the generator. * This introduces floating point error, which can throw off the reverser. * To fix this, I search for the nearest double that maps back, and use that as the seed. * * Because that worked, I did not work on covering the corner cases of equidistant doubles. */ double [] seedList = buildSeedList(2); int index = -1; double minDiff = Double.POSITIVE_INFINITY; for(int i = 0; i< 10000; ++i){ if(Math.abs(seedList[i]-target)0){ list[i] = r.nextDouble(); } } return list; } @Override public void learn(ArrayList> trainingInstances) { // TODO Auto-generated method stub } @Override public double computeProbOfGood(ArrayList prodFeatures) { // TODO Auto-generated method stub return 0; } private void print(String in){ if(debug) System.out.println(in); } }