HSRAvatar{{ private Config config; /* Constructor to be called during registration where you supply config*/ public HSRAvatar(Config cfg){ config = cfg; } /**proposing random unique claims which are not in the forbidden list**/ public ProposeResponse propose(ProposeRequest pr){ List claims = List.create(); SCGConfig scg_cfg = config.getScgCfg(); int maxProposals = scg_cfg.getMaxProposals() -1; for(int i =0; i< maxProposals;i++){ Claim claim = generateRandomClaim(); while(pr.getForbidden().contains(claim) || claims.contains(claim)){ claim = generateRandomClaim(); } claims = claims.append(claim); } return new ProposeResponse(claims); } /**Random oppose method - randomly agrees, refutes or strengthens by a factor of 1 **/ public OpposeResponse oppose(OpposeRequest or){ return new OpposeResponse(or.getClaims().map(new List.Map() { public OpposeAction map(Claim claim){ Random rand = new Random(); int randOppose = rand.nextInt(3); if(randOppose == 0) return new NoOpposition(); else if(randOppose == 1){ HSRInstanceSet is = (HSRInstanceSet)claim.getInstanceSet(); int n = is.getSingleton().getN(); int q = (int)Math.ceil(claim.getQuality() * n); SCGConfig scg_cfg = config.getScgCfg(); if (claim.getProtocol() instanceof ForAllExists){ if(q>1) return new Strengthening(claim.getQuality() - scg_cfg.getMinStrengthening()); else return new Refuting(); }else{ if(q hsr_cfg.getMaxN()){ randN = 2+ rand.nextInt(hsr_cfg.getMaxN() - 2); } int randK = 1 + rand.nextInt(randN - 1); int randQ = 1+ rand.nextInt(randN - 1); HSRInstance singleton = new HSRInstance(randN, randK); // get the maximum allowed n from config HSRInstanceSet instanceSet = new HSRInstanceSet(singleton ); return new Claim(instanceSet, nextBoolean?ForAllExists.getInstance():ExistsForAll.getInstance(),((double)randQ)/randN); } }}