2-APL UPC project.
0
fork

Configure Feed

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

i'm able to keep track of cards that are played plus cards that are currently on the table

fdesan 41b14108 581100e4

+35 -29
+34 -8
code/2apl_platform/briscola_chiamata/fabrizio.2apl
··· 5 5 as well as the history of cards played */ 6 6 { true } RemoveCardOnTable(S,R,X) { not cardontable(S,R,X) } /* Discard beliefs about the cards on the table 7 7 as soon as they are not neeed anymore */ 8 + { not hasplayed(_) } SetHasPlayed(X) { hasplayed(X) } /* Keep track of who is playing */ 9 + { hasplayed(X) } RemoveHasPlayed(X) { not hasplayed(X) } 8 10 9 11 Beliefs: 10 12 nopoints(X) :- (X=two;X=four;X=five;X=six;X=seven). 11 13 fewpoints(X) :- (X=jack;X=queen;X=king). 12 - getlowestcard(H, [S, R]) :- hascard(H, [S,R]), nopoints(R), !. 13 - getlowestcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), !. 14 - getlowestcard(H, [S, R]) :- hascard(H, [S,R]). 14 + manypoints(X) :- (X=ace;X=three). 15 + 16 + getlowcard(H, [S, R]) :- hascard(H, [S,R]), nopoints(R), !. 17 + getlowcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), !. 18 + getlowcard(H, [S, R]) :- hascard(H, [S,R]). 19 + 20 + gethighcard(H, [S, R]) :- hascard(H, [S,R]), manypoints(R), !. 21 + gethighcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), !. 22 + gethighcard(H, [S, R]) :- hascard(H, [S,R]). 23 + 24 + hasplayed(0). 25 + 15 26 16 27 PC-rules: 17 - /* track all the cards played by other players */ 28 + /* track all the cards played by other players _before_ me */ 18 29 event(cardPlayed(S, R, N), cardtable) <- true | 19 30 { 20 - AddCardPlayed(S, R, N) 21 - } 31 + if B( assigned(P0, _) and hasplayed(P1) and P0 > P1 ) then 32 + { 33 + AddCardPlayed(S, R, N) 34 + }; 22 35 36 + if B( hasplayed(P1) and P1 = 4) then 37 + { 38 + RemoveHasPlayed(P1); 39 + SetHasPlayed(0) 40 + } 41 + else 42 + { 43 + B ( hasplayed(P1)); 44 + RemoveHasPlayed(P1); 45 + SetHasPlayed(P1 + 1) 46 + } 47 + 48 + } 23 49 24 50 /* it's my turn playing */ 25 51 message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] | 26 52 { 27 53 28 54 /* find out the best card to play */ 29 - B( getlowestcard(H, [S, R]) ); 55 + B( getlowcard(H, [S, R]) ); 30 56 31 57 /* play the card */ 32 58 @cardtable(playCard(S, R)); ··· 34 60 /* discard beliefs about cards on the table */ 35 61 while B( cardontable(S1, R1, X1) ) do 36 62 { 37 - RemoveCardOnTable(S1,R1,X1) 63 + [ RemoveCardOnTable(S1,R1,X1) ] 38 64 }; 39 65 40 66 /* update beliefs about the cards I have */
+1 -21
code/2apl_platform/briscola_chiamata/player.2apl
··· 16 16 notary(n). 17 17 gatekeeper(gk). 18 18 dealer(d). 19 - player(X) :- assigned(POS, X). 20 19 21 20 getfirstcard([], 0, []). 22 21 getfirstcard([X], 0, []). ··· 193 192 if B( hascard(H, [S, R]) ) then 194 193 { 195 194 print("I go alone!"); 196 - SetPartner(Me) // The player goes alone 195 + SetPartner(me) // The player goes alone 197 196 } 198 197 } 199 198 ··· 224 223 B( deletehandcard(S, R, H, RES ) ); 225 224 RemoveHand(H); 226 225 SetHand(RES) 227 - 228 - /* 229 - // Check if hand is ended 230 - if B(RES = []) then 231 - { 232 - endhand() 233 - } 234 - */ 235 - 236 226 } 237 227 238 228 message(n, inform, _, _, yourpoints(Y)) <- true | ··· 243 233 SetPoints(P + Y) 244 234 } 245 235 246 - /***** 247 - endhand() <- hand([]) | 248 - { 249 - print("I finish my hand!"); 250 - RemoveHand([]); 251 - B( points(P) ); 252 - send(n, inform, doiwin(P)) 253 - } 254 - *****/ 255 - 256 236 message(n, inform, _, _, gameisover(X)) <- hand([]) | 257 237 { 258 238 RemoveHand([]);