2-APL UPC project.
0
fork

Configure Feed

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

added dealer agent and first version of dealing

cyberslas d3124de2 84604d97

+80 -26
+1
code/2apl_platform/briscola_chiamata/briscola_chiamata.mas
··· 1 1 n : notary.2apl 1 @cardtable 2 2 gk : gatekeeper.2apl 1 @cardtable 3 + d : dealer.2apl 1 @cardtable 3 4 marcos : marcos.2apl 2 @cardtable 4 5 fabrizio : fabrizio.2apl 2 @cardtable 5 6 borja : borja.2apl 2 @cardtable
+32
code/2apl_platform/briscola_chiamata/dealer.2apl
··· 1 + BeliefUpdates: 2 + { not assigned(POS, X) } SetAssigned(POS, X) { assigned(POS, X) } 3 + 4 + Beliefs: 5 + notary(n). 6 + gatekeeper(gk). 7 + player(X) :- assigned(POS, X). 8 + 9 + Plans: 10 + @cardtable(enterAsDealer()) 11 + 12 + PC-rules: 13 + message(X, inform, _, _, registered(POS, Y)) <- true | 14 + { 15 + SetAssigned(POS, Y) 16 + } 17 + 18 + message(X, inform, _, _, dealer(Y)) <- true | 19 + { 20 + /* here start shuffling and dealing cards */ 21 + /* send cards */ 22 + B( assigned(0, P0) ); 23 + send (P0, inform, givecards([1,2,3,4,6,7,8])); 24 + B( assigned(1, P1) ); 25 + send (P1, inform, givecards([1,2,3,4,6,7,8])); 26 + B( assigned(2, P2) ); 27 + send (P2, inform, givecards([1,2,3,4,6,7,8])); 28 + B( assigned(3, P3) ); 29 + send (P3, inform, givecards([1,2,3,4,6,7,8])); 30 + B( assigned(4, P4) ); 31 + send (P4, inform, givecards([1,2,3,4,6,7,8])) 32 + }
+5 -3
code/2apl_platform/briscola_chiamata/gatekeeper.2apl
··· 4 4 5 5 Beliefs: 6 6 notary(n). 7 - assigned(POS, X) :- player(X). 7 + dealer(d). 8 + player(X) :- assigned(POS, X). 8 9 9 10 Plans: 10 11 @cardtable(enterAsGatekeeper()) ··· 15 16 @cardtable(sit(X), POS); 16 17 SetAssigned(POS, X); 17 18 send(X, inform, registered(POS, X)); 18 - send(n, inform, registered(POS, X)) 19 + send(n, inform, registered(POS, X)); 20 + send(d, inform, registered(POS, X)) 19 21 } 20 22 21 23 PR-rules: 22 24 @cardtable(sit(X)); REST <- true | 23 25 { 24 26 send(X, inform, refused(X)) 25 - } 27 + }
+6 -5
code/2apl_platform/briscola_chiamata/notary.2apl
··· 7 7 8 8 Beliefs: 9 9 gatekeeper(gk). /* we know who the gatekeeper is, for simplicity */ 10 + dealer(d). 10 11 currentturn(1). /* the first turn is for the agent in postion 1 */ 12 + 11 13 12 14 Plans: 13 15 @cardtable(enterAsNotary()) /* join the game as notary */ ··· 18 20 SetAssigned(POS, Y); /* update belief about assigned sit */ 19 21 if B( POS = 4 ) then /* if we believe we already assigned all the sits, then choose the dealer */ 20 22 { 21 - @cardtable(chooseDealer(), D); 22 - SetDealer(D); 23 - send(D, inform, dealer(D)) 23 + /*@cardtable(chooseDealer(), D);*/ 24 + /*SetDealer(D);*/ 25 + send(d, inform, dealer(d)) 24 26 } 25 27 } 26 28 ··· 38 40 UpdateTrun(X + 1); 39 41 @cardtale(selectTrun(X + 1)) 40 42 } 41 - } 42 - 43 + }
+20 -16
code/2apl_platform/briscola_chiamata/player.2apl
··· 2 2 { true } SetAssigned(POS, X) { assigned(POS, X) } 3 3 { true } RemoveAssigned(POS, X) { not assigned(POS, X) } 4 4 { true } AddBidHistorical(Cantity, Who) { bidhistorical(Cantity, Who) } 5 + { true } SetAsDealer(X) { dealer(X) } 6 + { true } SetHand(X) { hand(X) } 5 7 Beliefs: 6 8 notary(n). 7 9 gatekeeper(gk). 10 + dealer(d). 11 + player(X) :- assigned(POS, X). 8 12 9 13 Plans: 10 14 [ B(gatekeeper(X)) ; send(X, request, register(me)) ] ··· 12 16 PC-rules: 13 17 message(X, inform, _, _, registered(POS, Y)) <- true | 14 18 { 15 - SetAssigned(POS, X) 19 + SetAssigned(POS, Y) 16 20 } 17 21 message(X, inform, _, _, refused(Y)) <- true | 18 22 { 19 23 print("I'm out!") 20 24 } 21 - message(X, inform, _, _, dealer(Y)) <- true | 22 - { 23 - print("I'm the dealer!") 24 - /* here start shuffling and dealing cards */ 25 - } 26 - 27 - message (X, inform, _, _, firstbid()) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 25 + 26 + message(X, inform, _, _, firstbid(_)) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 28 27 { 29 28 /* for fist, the agent bids */ 30 29 /* TODO the agent must know who is the next bidding, or ask to dealer*/ 31 - send (Next, inform, bid()); 30 + send (Next, inform, bid(_)) 32 31 33 32 } 34 33 35 - message (X, inform, _, _, firstbid()) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 34 + message(X, inform, _, _, firstbid(_)) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 36 35 { 37 36 /* for fist, the agent bids */ 38 37 /* TODO the agent must know who is the next bidding, or ask to dealer*/ 39 38 send (Next, inform, bid(1)) 40 39 } 41 40 42 - message (X, inform, _, _, bid(Cuantity)) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 41 + message(X, inform, _, _, bid(Cuantity, Pos)) <- scenario(bidding) | /* message from dealer, telling that this agent is the firts to bid */ 43 42 { 44 - /* for fist, the agent bids only once. NOTE i suppose "me" is a self reference */ 45 - if B( bidhistorical(_, me) ) 43 + if B( bidhistorical(_, me) ) then 46 44 { 47 - send (Next, inform, pass()) 45 + send (Next, inform, pass(_)) 48 46 } 49 47 else 50 48 { ··· 53 51 54 52 } 55 53 56 - turnselected (X) <- assigned(X, _) and scenario(playing) | /* when percepts turnselected, and its his turn*/ 54 + message(d, inform, _, _, givecards(X)) <- true | 55 + { 56 + print ("I've cards!"); 57 + SetHand(X) 58 + } 59 + 60 + turnselected(X) <- assigned(X, _) and scenario(playing) | /* when percepts turnselected, and its his turn*/ 57 61 { 58 62 /*TODO*/ 59 - 63 + skip 60 64 } 61 65
+16 -2
code/2apl_platform/environments/cardtable/Env.java
··· 29 29 { 30 30 private HashMap<String,Agent> agentmap = new HashMap<String,Agent>(); 31 31 32 - private int numberOfPlayers, numberOfNotaries, numberOfGatekeepers; 32 + private int numberOfPlayers, numberOfNotaries, numberOfGatekeepers, numberOfDealers; 33 33 34 34 // The default constructor 35 35 public Env() ··· 56 56 57 57 return wrapBoolean(true); 58 58 } 59 - 59 + 60 + public Term enterAsDealer(String sAgent) throws ExternalActionFailedException { 61 + Agent agent = getAgent(sAgent); 62 + writeToLog("Dealer sit: " +agent.getName()); 63 + 64 + if(numberOfDealers>0) 65 + throw new ExternalActionFailedException("There is already a dealer at the table."); 66 + else 67 + numberOfDealers++; 68 + 69 + agent._type=3; 70 + 71 + return wrapBoolean(true); 72 + } 73 + 60 74 public Term enterAsGatekeeper(String sAgent) throws ExternalActionFailedException { 61 75 Agent agent = getAgent(sAgent); 62 76 writeToLog("Gatekeeper in the system: " +agent.getName());