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(Claim c: pr.getForbidden()){ c.finishParse(); } 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){ claim.finishParse(); HSRInstanceSet is = (HSRInstanceSet)claim.getInstanceSet().getInstanceSet(); int n = is.getSingleton().getN(); int q = (int)Math.ceil(claim.getQuality() * n); SCGConfig scg_cfg = config.getScgCfg(); if (claim.getProtocol() instanceof Positive){ 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 ); try { InstanceSet instance = new InstanceSet(FullyQualifiedClassName.parse("hsr.HSRInstanceSet"), instanceSet , new verbatim(instanceSet.print())); if(nextBoolean) claim = new Claim(instance, FullyQualifiedClassName.parse("hsr.protocol.Positive"), new Positive(), ((double)randQ)/randN); else claim = new Claim(instance, FullyQualifiedClassName.parse("hsr.protocol.Negative"), new Negative(), ((double)randQ)/randN); } catch (scg.ParseException e) { } return claim; } }}