2-APL UPC project.
0
fork

Configure Feed

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

first basic straight strategy implemented --- also several improvements to the main code

fdesan 581100e4 65eb9831

+119 -50
+45 -1
code/2apl_platform/briscola_chiamata/fabrizio.2apl
··· 1 - Include: player.2apl 1 + Include: player.2apl 2 + 3 + BeliefUpdates: 4 + { true } AddCardPlayed(S, R, X) { cardontable(S, R, X), cardplayed(S, R, X) } /* Keep track of cards on the table 5 + as well as the history of cards played */ 6 + { true } RemoveCardOnTable(S,R,X) { not cardontable(S,R,X) } /* Discard beliefs about the cards on the table 7 + as soon as they are not neeed anymore */ 8 + 9 + Beliefs: 10 + nopoints(X) :- (X=two;X=four;X=five;X=six;X=seven). 11 + 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]). 15 + 16 + PC-rules: 17 + /* track all the cards played by other players */ 18 + event(cardPlayed(S, R, N), cardtable) <- true | 19 + { 20 + AddCardPlayed(S, R, N) 21 + } 22 + 23 + 24 + /* it's my turn playing */ 25 + message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] | 26 + { 27 + 28 + /* find out the best card to play */ 29 + B( getlowestcard(H, [S, R]) ); 30 + 31 + /* play the card */ 32 + @cardtable(playCard(S, R)); 33 + 34 + /* discard beliefs about cards on the table */ 35 + while B( cardontable(S1, R1, X1) ) do 36 + { 37 + RemoveCardOnTable(S1,R1,X1) 38 + }; 39 + 40 + /* update beliefs about the cards I have */ 41 + B( deletehandcard(S, R, H, RES ) ); 42 + RemoveHand(H); 43 + SetHand(RES) 44 + 45 + }
+41 -26
code/2apl_platform/briscola_chiamata/notary.2apl
··· 3 3 { true } RemoveAssigned(POS, X) { not assigned(POS, X) } 4 4 { true } SetDealer(X) { dealer(X) } 5 5 { not currentturn(_) } UpdateTurn(X) { currentturn(X) } 6 - { currentturn(X) } RemoveTrun(X) { not currentturn(X) } 6 + { currentturn(X) } RemoveTurn(X) { not currentturn(X) } 7 + { not rounds(_) } UpdateRounds(X) { rounds(X) } 8 + { rounds(X) } RemoveRounds(X) { not rounds(X) } 7 9 { true } PlayerPass(X) { playerpass(X) } 8 - { true } AddCardPlayed(S, R, X) { cardontable(S, R, X) } /* Player X has played card of rank R and suit S */ 9 - { true } AddBriscola(S, R) { briscola(S, R) } /* Set the riscola to be a card of rank R and suit S */ 10 + { true } SetBriscola(S, R) { briscola(S, R) } /* Set the briscola to be a card of rank R and suit S */ 11 + { true } AddCardPlayed(S, R, X) { cardontable(S, R, X) } /* Keep track of cards on the table */ 10 12 { true } RemoveCardPlayed(S, R, X) { not cardontable(S, R, X) } 11 13 12 14 { not points(P, X) } AddPoints(P, X) { points(P, X) } 13 15 { points(P, X) } RemovePoints(P, X) { not points(P, X) } 14 16 15 17 Beliefs: 16 - gatekeeper(gk). /* we know who the gatekeeper is, for simplicity */ 18 + gatekeeper(gk). /* we know who the gatekeeper is, for simplicity */ 17 19 dealer(d). 18 20 currentturn(0). /* the first turn is for the agent in postion 0 */ 21 + rounds(8). /* there are 8 rounds */ 19 22 20 23 getpoints(jack, X) :- X is 2. 21 24 getpoints(queen, X) :- X is 3. ··· 24 27 getpoints(ace, X) :- X is 11. 25 28 getpoints(Y, X) :- X is 0. 26 29 27 - briscolaPlayed(X) :- cardontable(S, _, X), briscola(S, _). /* Keep track of who played a briscola */ 30 + briscolaPlayed(X) :- cardontable(S, _, X), briscola(S, _). /* Keep track of who played a briscola: it is useful when points of a round has to be counted in order to establish if someone has played a briscola */ 28 31 29 - getwinner(Winner, Suit) :- cardontable(Suit, ace, Winner), !. 30 - getwinner(Winner, Suit) :- cardontable(Suit, three, Winner), !. 31 - getwinner(Winner, Suit) :- cardontable(Suit, king, Winner), !. 32 - getwinner(Winner, Suit) :- cardontable(Suit, queen, Winner), !. 33 - getwinner(Winner, Suit) :- cardontable(Suit, jack, Winner), !. 34 - getwinner(Winner, Suit) :- cardontable(Suit, seven, Winner), !. 35 - getwinner(Winner, Suit) :- cardontable(Suit, six, Winner), !. 36 - getwinner(Winner, Suit) :- cardontable(Suit, five, Winner), !. 37 - getwinner(Winner, Suit) :- cardontable(Suit, four, Winner), !. 38 - getwinner(Winner, Suit) :- cardontable(Suit, two, Winner), !. 32 + getroundwinner(W, S) :- cardontable(S, ace, W), !. 33 + getroundwinner(W, S) :- cardontable(S, three, W), !. 34 + getroundwinner(W, S) :- cardontable(S, king, W), !. 35 + getroundwinner(W, S) :- cardontable(S, queen, W), !. 36 + getroundwinner(W, S) :- cardontable(S, jack, W), !. 37 + getroundwinner(W, S) :- cardontable(S, seven, W), !. 38 + getroundwinner(W, S) :- cardontable(S, six, W), !. 39 + getroundwinner(W, S) :- cardontable(S, five, W), !. 40 + getroundwinner(W, S) :- cardontable(S, four, W), !. 41 + getroundwinner(W, S) :- cardontable(S, two, W), !. 39 42 43 + /* 44 + * This is wrong: a player win if its team has won. A team wins if the sum of the points of its parters is greater than the sum of the points of the other players. 45 + */ 40 46 major(X, Y) :- X >= Y. 41 47 win(X, P1, [X, P1]). 42 48 win(X, P1, [X, P1|T]) :- win(Y, P2, T), major(P1, P2). ··· 89 95 message(X, inform, _, _, declarebriscola(Briscola)) <- true | 90 96 { 91 97 B( Briscola = [S, R] ); 92 - AddBriscola(S, R); 98 + SetBriscola(S, R); 93 99 B( assigned(Pos, X) ); 94 100 if B( Pos = 0 ) then 95 101 { ··· 148 154 }; 149 155 150 156 // START THE GAME!!! 151 - selectturn() 157 + selectturn() 152 158 } 153 159 154 160 /** ··· 158 164 { 159 165 if B( X = 5 ) then 160 166 { 161 - RemoveTrun(X); 167 + RemoveTurn(X); 162 168 UpdateTurn(0); 163 169 B( assigned(0, P)); 164 170 print("Round over!"); 165 - countpoints() 171 + [ countpoints() ]; 172 + 173 + B( rounds(N) ); 174 + RemoveRounds(N); 175 + UpdateRounds(N - 1); 176 + 177 + if B( rounds(N) and N = 0 ) then 178 + { 179 + while B ( assigned(POS, Y) ) do 180 + { 181 + send(Y, inform, gameisover(0)); 182 + RemoveAssigned(POS, Y) 183 + } 184 + } 166 185 } 167 186 else 168 187 { 169 188 B( assigned(X, P)); 170 189 send(P, inform, yourturn(X)); 171 - RemoveTrun(X); 190 + RemoveTurn(X); 172 191 UpdateTurn(X + 1) 173 192 } 174 193 } 175 194 176 195 event(cardPlayed(S, R, N), cardtable) <- true | 177 196 { 178 - //TODO add card played to can count points 179 197 AddCardPlayed(S, R, N); 180 198 selectturn() 181 199 } ··· 201 219 202 220 if B( briscolaPlayed(_)) then 203 221 { 204 - B( briscola(S,_) and getwinner(W, S)) 222 + B( briscola(S,_) and getroundwinner(W, S)) 205 223 } 206 224 else 207 225 { 208 - B( getwinner(W, S0)) 226 + B( getroundwinner(W, S0)) 209 227 }; 210 228 211 229 //Send point to the winner 212 230 send(W, inform, yourpoints( X0 + X1 + X2 + X3 + X4)); 213 - //@cardtable(updatePoints(W, X0 + X1 + X2 + X3 + X4)); 214 231 B( points(W, POINTS) ); 215 232 RemovePoints(W, POINTS); 216 233 AddPoints(W, POINTS + X0 + X1 + X2 + X3 + X4); ··· 248 265 send(X, inform, youlose(P)) 249 266 } 250 267 } 251 - 252 -
+33 -23
code/2apl_platform/briscola_chiamata/player.2apl
··· 7 7 { hand(X) } RemoveHand(X) { not hand(X) } 8 8 { not lastbid(X) } AddLastBid(X) { lastbid(X) } 9 9 { lastbid(X) } RemoveLastBid(X) { not lastbid(X) } 10 - 11 - { not points(X) } AddPoints(X) { points(X) } 10 + { not points(X) } SetPoints(X) { points(X) } 12 11 { points(X) } RemovePoints(X) { not points(X) } 13 - 14 12 { true } SetPartner(X) { partner(X) } 15 - 16 - { true } AddBriscola(X) { briscola(X) } 13 + { true } SetBriscola(S,R) { briscola(S,R) } 17 14 18 15 Beliefs: 19 16 notary(n). ··· 21 18 dealer(d). 22 19 player(X) :- assigned(POS, X). 23 20 24 - getcard([], 0, []). 25 - getcard([X], 0, []). 26 - getcard([ S, R | REST ], 0, [S, R]). 27 - getcard([ S, R | REST ], I, X) :- Y is I - 1, getcard(REST, Y, X). 21 + getfirstcard([], 0, []). 22 + getfirstcard([X], 0, []). 23 + getfirstcard([ S, R | REST ], 0, [S, R]). 24 + getfirstcard([ S, R | REST ], I, X) :- Y is I - 1, getfirstcard(REST, Y, X). 28 25 29 - iscard([], []). 30 - iscard([Card1, Card2 | REST ], [Card1, Card2]). 31 - iscard([ X, Y | REST ], Q) :- iscard(REST, Q). 26 + hascard([], []). 27 + hascard([Card1, Card2 | REST ], [Card1, Card2]). 28 + hascard([ X, Y | REST ], Q) :- hascard(REST, Q). 32 29 33 30 deletehandcard(R, S, [R, S|T], T). 34 - deletehandcard(R, S, [X, Y|T], [H|T1]):- deletehandcard(R, S, T, T1). 31 + deletehandcard(R, S, [X, Y|T], [X, Y|T1]):- deletehandcard(R, S, T, T1). 35 32 36 33 points(0). 37 34 ··· 182 179 message(X, inform, _, _, bidwinner(Y)) <- hand(H) | 183 180 { 184 181 print("I've the Briscola!"); 185 - AddBriscola(0); 186 182 //TODO: The knowledge of a general deck must be included into NPC belief base to be able to 187 183 //chose a random card of the deck 188 184 send(d, inform, askforacard(0)) 189 185 } 190 186 191 - message(d, inform, _, _, acard(X)) <- briscola(B) | 187 + message(d, inform, _, _, acard(X)) <- true | 192 188 { 193 189 B(X = [S, R]); 194 190 // --- Declare Briscola 195 191 send(n, inform, declarebriscola([S, R])); 196 192 @cardtable(briscolaDeclared(S, R)); 197 - if B( iscard(H, [S, R]) ) then 193 + if B( hascard(H, [S, R]) ) then 198 194 { 199 195 print("I go alone!"); 200 196 SetPartner(Me) // The player goes alone ··· 203 199 204 200 message(X, inform, _, _, declarebriscola(Briscola, Y)) <- hand(H) | 205 201 { 202 + B(Briscola = [S,R]); 203 + SetBriscola(S, R); 206 204 // Update knowledge about the team 207 - if B( iscard(H, Briscola) ) then 205 + if B( hascard(H, Briscola) ) then 208 206 { 209 207 print("is the parter of the declarer"); 210 208 SetPartner(Y) ··· 217 215 message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] | 218 216 { 219 217 220 - print("My turn!"); 221 - B( getcard(H, 0, X ) ); //TODO Get a ramdom card. 218 + print("My turn as default!"); 219 + B( getfirstcard(H, 0, X ) ); 222 220 B( X = [S, R] ); 223 221 @cardtable(playCard(S, R)); 224 222 225 223 // Update hand 226 224 B( deletehandcard(S, R, H, RES ) ); 227 225 RemoveHand(H); 228 - SetHand(RES); 226 + SetHand(RES) 229 227 228 + /* 230 229 // Check if hand is ended 231 230 if B(RES = []) then 232 231 { 233 232 endhand() 234 233 } 234 + */ 235 + 235 236 } 236 237 237 238 message(n, inform, _, _, yourpoints(Y)) <- true | ··· 239 240 print("I received the points"); 240 241 B( points(P) ); 241 242 RemovePoints(P); 242 - AddPoints(P + Y) 243 + SetPoints(P + Y) 243 244 } 244 245 246 + /***** 245 247 endhand() <- hand([]) | 246 248 { 247 249 print("I finish my hand!"); ··· 249 251 B( points(P) ); 250 252 send(n, inform, doiwin(P)) 251 253 } 254 + *****/ 255 + 256 + message(n, inform, _, _, gameisover(X)) <- hand([]) | 257 + { 258 + RemoveHand([]); 259 + B( points(P) ); 260 + send(n, inform, doiwin(P)) 261 + } 252 262 253 263 /** 254 - * updateScore() should be moved in the notary agent? 264 + * The updateScore external actions have to be moved into the notary agent. 265 + * They are defined here for semplicity, at the moment. 255 266 */ 256 267 message(n, inform, _, _, youwin(Y)) <- briscola(_) | 257 268 { ··· 276 287 B( assigned(Pos, Me) ); 277 288 @cardtable(updateScore(Me, -1)) 278 289 } 279 -