source: src/main/java/agents/anac/y2015/fairy/kawaii.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 6.0 KB
Line 
1package agents.anac.y2015.fairy;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.EndNegotiation;
10import genius.core.actions.Inform;
11import genius.core.actions.Offer;
12import genius.core.parties.AbstractNegotiationParty;
13import genius.core.parties.NegotiationInfo;
14import genius.core.utility.AdditiveUtilitySpace;
15
16/**
17 * This is your negotiation party.
18 */
19public class kawaii extends AbstractNegotiationParty {
20 private negotiatingInfo negotiatingInfo; // �����
21 private bidSearch bidSearch; // Bid�T��
22 private strategy strategy; // ���헪
23 private Bid offeredBid = null; // ��Ă��ꂽ���ӈČ��
24
25 // �f�o�b�O�p
26 public static boolean isPrinting = false; // ���b�Z�[�W��\������
27
28 @Override
29 public void init(NegotiationInfo info) {
30 super.init(info);
31
32 if (isPrinting) {
33 System.out.println("*** SAOPMN_SampleAgent ***");
34 }
35
36 negotiatingInfo = new negotiatingInfo(
37 (AdditiveUtilitySpace) utilitySpace);
38 try {
39 bidSearch = new bidSearch((AdditiveUtilitySpace) utilitySpace,
40 negotiatingInfo);
41 } catch (Exception e) {
42 throw new RuntimeException("init failed:" + e, e);
43 }
44 strategy = new strategy((AdditiveUtilitySpace) utilitySpace,
45 negotiatingInfo);
46 }
47
48 /**
49 * Each round this method gets called and ask you to accept or offer. The
50 * first party in the first round is a bit different, it can only propose an
51 * offer.
52 *
53 * @param validActions
54 * Either a list containing both accept and offer or only offer.
55 * @return The chosen action.
56 */
57 @SuppressWarnings("rawtypes")
58 @Override
59 // Action�̑I��
60 public Action chooseAction(List<Class<? extends Action>> validActions) {
61 double time = timeline.getTime(); // ���݂̌��Ž������擾
62
63 // System.out.println("�s���I��");
64 // Accept
65 if (validActions.contains(Accept.class)
66 && strategy.selectAccept(offeredBid, time)) {
67 return new Accept(getPartyId(), offeredBid);
68 }
69
70 // EndNegotiation
71 // if(true){ return new EndNegotiation(); }
72
73 if (strategy.selectEndNegotiation(time)) {
74 return new EndNegotiation(getPartyId());
75 }
76
77 // Offer
78 return OfferAction();
79 }
80
81 public Action OfferAction() {
82 Bid offerBid = bidSearch.getBid(generateRandomBid(),
83 strategy.getThreshold(timeline.getTime()));
84 negotiatingInfo.updateMyBidHistory(offerBid);
85 return new Offer(getPartyId(), offerBid);
86 }
87
88 /**
89 * All offers proposed by the other parties will be received as a message.
90 * You can use this information to your advantage, for example to predict
91 * their utility.
92 *
93 * @param sender
94 * The party that did the action.
95 * @param action
96 * The action that party did.
97 */
98 @Override
99 // ���g�ȊO�̌��ŽQ���҂�Action����M
100 public void receiveMessage(AgentID sender, Action action) {
101
102 // System.out.println("��M");
103 // System.out.println("Sender:"+sender+", Action:"+action);
104 super.receiveMessage(sender, action);
105 // Here you can listen to other parties' messages
106 if (isPrinting) {
107 System.out.println("Sender:" + sender + ", Action:" + action);
108 }
109
110 // System.out.println("��M");
111
112 if (action != null) {
113 if (action instanceof Inform
114 && ((Inform) action).getName() == "NumberOfAgents"
115 && ((Inform) action).getValue() instanceof Integer) {
116 Integer opponentsNum = (Integer) ((Inform) action).getValue();
117 negotiatingInfo.updateOpponentsNum(opponentsNum);
118 if (isPrinting) {
119 System.out.println("NumberofNegotiator:"
120 + negotiatingInfo.getNegotiatorNum());
121 }
122 } else if (action instanceof Accept) {
123 if (!negotiatingInfo.getOpponents().contains(sender)) {
124 negotiatingInfo.initOpponent(sender);
125 } // ���o�̌��Ž҂͏���
126 negotiatingInfo.setOpponentsBool(sender, true);// ���ӂł��邱�Ƃ̃Z�b�g
127
128 } else if (action instanceof Offer) {
129 if (!negotiatingInfo.getOpponents().contains(sender)) {
130 negotiatingInfo.initOpponent(sender);
131 } // ���o�̌��Ž҂͏���
132 offeredBid = ((Offer) action).getBid(); // ��Ă��ꂽ���ӈČ��
133 negotiatingInfo.setOpponentsBool(sender, false);// ���ӂłȂ����Ƃ̃Z�b�g
134 try {
135 negotiatingInfo.updateInfo(sender, offeredBid);
136 } // �������X�V
137 catch (Exception e) {
138 System.out.println(
139 "�����̍X�V�Ɏ��s���܂���");
140 e.printStackTrace();
141 }
142 } else if (action instanceof EndNegotiation) {
143 // System.out.println("���‚����􂵂܂����B");
144 }
145 }
146
147 // old ver 3/2 r
148 /*
149 * if (action != null ) { if(action instanceof Accept){
150 * if(!negotiatingInfo.getOpponents().contains(sender)){
151 * negotiatingInfo.initOpponent(sender); } //
152 * ���o�̌��Ž҂͏���
153 * negotiatingInfo.setOpponentsBool(sender,true);//���ӂł��é‚
154 * ±ï¿½Æ‚̃Z�b�g } else if(action instanceof Offer) {
155 * if(!negotiatingInfo.getOpponents().contains(sender)){
156 * negotiatingInfo.initOpponent(sender); } //
157 * ���o�̌��Ž҂͏���
158 * negotiatingInfo.setOpponentsBool(sender,false);//���ӂłȂ�ï¿
159 * ½ï¿½ï¿½Æ‚̃Z�b�g offeredBid = ((Offer) action).getBid(); //
160 * ��Ă��ꂽ���ӈČ�� try {
161 * negotiatingInfo.updateInfo(sender, offeredBid); } //
162 * �������X�V catch (Exception e) {
163 * System.out.println(
164 * "�����̍X�V�Ɏ��s���܂���");
165 * e.printStackTrace(); } } else { Object obj = ((Object)action); int
166 * opponentsNum =
167 * Integer.parseInt(obj.toString().replaceAll("[^0-9]",""));
168 * negotiatingInfo.updateOpponentsNum(opponentsNum); if(isPrinting){
169 * System.out.println("NumberofNegotiator:" +
170 * negotiatingInfo.getNegotiatorNum());} } }
171 */
172 }
173
174 @Override
175 public String getDescription() {
176 return "ANAC2015";
177 }
178
179}
Note: See TracBrowser for help on using the repository browser.