2-APL UPC project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added playcard method

fdesan 37b0476d 401e7d01

+32 -6
+3 -1
code/2apl_platform/environments/cardtable/Agent.java
··· 7 7 // 0 player 8 8 // 1 gatekeeper 9 9 // 2 notary 10 + 11 + /* BUG: add set/get method and remove protected */ 10 12 protected int _type; 11 13 12 - // _position null means agent is not sit at the table 14 + /* BUG: _position null means agent is not sit at the table, add set/get method */ 13 15 protected Integer _position = null; 14 16 15 17 public Agent( String name ) {
+29 -5
code/2apl_platform/environments/cardtable/Env.java
··· 49 49 numberOfNotaries++; 50 50 51 51 agent._type=2; 52 + agent._position=-1; /* notary hasn't a real position, but it needs a value in order to be sit at the table */ 52 53 53 54 return wrapBoolean(true); 54 55 } ··· 63 64 numberOfDealers++; 64 65 65 66 agent._type=3; 67 + agent._position=-1; /* dealer hasn't a real position, but it needs a value in order to be sit at the table */ 66 68 67 69 return wrapBoolean(true); 68 70 } ··· 77 79 numberOfGatekeepers++; 78 80 79 81 agent._type=1; 82 + agent._position=-1; /* gk hasn't a real position, but it needs a value in order to be sit at the table */ 80 83 81 84 return wrapBoolean(true); 82 85 } ··· 146 149 147 150 deck.shuffle(); 148 151 149 - notifyEvent("deckShuffled", deck); 152 + Agent d = getDealer(); 153 + notifyEvent("deckShuffled", deck, d); 150 154 151 155 return wrapBoolean(true); 152 156 } 153 157 158 + public Term playCard(String sAgent, APLIdent suit, APLIdent rank) { 159 + notifyEvent("cardPlayed", suit, rank); 160 + return wrapBoolean(true); 161 + } 162 + 154 163 /* Standard functions --------------------------------------*/ 155 164 156 165 private void notifyAgents(APLFunction event, String... receivers) { 157 166 throwEvent(event, receivers); 158 167 } 159 168 160 - private void notifyEvent(String parm1, Deck deck) throws ExternalActionFailedException 169 + private void notifyEvent(String parm1, Deck deck, Agent d) 161 170 { 162 - Agent d = getDealer(); 163 - 164 171 LinkedList returnList = new LinkedList(); 165 172 List deckList = deck.getDeck(); 166 173 ··· 174 181 returnList.add(id); 175 182 Rank rank = card.getRank(); 176 183 id = new APLIdent(rank.getName()); 177 - deckStr += rank.getName() + ">, "; 184 + deckStr += rank.getName() + ">"; 178 185 returnList.add(id); 186 + if(i.hasNext()) 187 + deckStr += ", "; 179 188 } 180 189 deckStr += " ]"; 181 190 ··· 183 192 { 184 193 notifyAgents(new APLFunction(parm1,new APLList(returnList)), d.getName()); 185 194 writeToLog("EVENT: "+parm1+" "+deckStr+" "+" to "+d.getName()); 195 + } 196 + } 197 + 198 + private void notifyEvent(String parm1, APLIdent suit, APLIdent rank) { 199 + ArrayList<String> targetAgents = new ArrayList<String>(); 200 + for (Agent a : agentmap.values()) 201 + { 202 + if ((a.isSit() && a.getType()==0) || (a.isSit() && a.getType()==2)) 203 + targetAgents.add(a.getName()); 204 + } 205 + 206 + if (!targetAgents.isEmpty()) 207 + { 208 + notifyAgents(new APLFunction(parm1,suit,rank),targetAgents.toArray(new String[0])); 209 + writeToLog("EVENT: "+parm1+"("+suit.toString()+","+rank.toString()+")"+" to "+targetAgents); 186 210 } 187 211 } 188 212