| 24 | |
| 25 | The basic structure of an agent looks like this |
| 26 | {{{ |
| 27 | public class RandomParty extends DefaultParty { |
| 28 | @Override |
| 29 | public void notifyChange(Inform info) { |
| 30 | // System.out.println("Received info:" + info); |
| 31 | if (info instanceof Settings) { |
| 32 | fetchProfile(((Settings) info).getProfile()); |
| 33 | this.me = ((Settings) info).getID(); |
| 34 | } else if (info instanceof ActionDone) { |
| 35 | lastActor = ((ActionDone) info).getAction().getActor(); |
| 36 | Action otheract = ((ActionDone) info).getAction(); |
| 37 | if (otheract instanceof Offer) { |
| 38 | lastReceivedBid = ((Offer) otheract).getBid(); |
| 39 | } |
| 40 | } else if (info instanceof YourTurn) { |
| 41 | myTurn(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | private void myTurn() { |
| 46 | Action action; |
| 47 | if (lastReceivedBid != null && profileint.getProfile() |
| 48 | .getUtility(lastReceivedBid).doubleValue() > 0.6) { |
| 49 | action = new Accept(lastActor, lastReceivedBid); |
| 50 | } else { |
| 51 | AllBidsList bidspace = new AllBidsList(getProfile().getDomain()); |
| 52 | long i = random.nextInt(bidspace.size().intValue()); |
| 53 | action = new Offer(me, bidspace.get(BigInteger.valueOf(i))); |
| 54 | } |
| 55 | try { |
| 56 | getConnection().send(action); |
| 57 | } catch (IOException e) { |
| 58 | e.printStackTrace(); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Capabilities getCapabilities() { |
| 65 | return new Capabilities(new HashSet<>( |
| 66 | Arrays.asList(new ProtocolRef(new URI("SAOP"))))); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String getDescription() { |
| 71 | return "places random bids until it can accept an offer with utility >0.6"; |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | }}} |