···11-Include: player.2apl11+Include: player.2apl
22+33+BeliefUpdates:
44+ { true } AddCardPlayed(S, R, X) { cardontable(S, R, X), cardplayed(S, R, X) } /* Keep track of cards on the table
55+ as well as the history of cards played */
66+ { true } RemoveCardOnTable(S,R,X) { not cardontable(S,R,X) } /* Discard beliefs about the cards on the table
77+ as soon as they are not neeed anymore */
88+99+Beliefs:
1010+ nopoints(X) :- (X=two;X=four;X=five;X=six;X=seven).
1111+ fewpoints(X) :- (X=jack;X=queen;X=king).
1212+ getlowestcard(H, [S, R]) :- hascard(H, [S,R]), nopoints(R), !.
1313+ getlowestcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), !.
1414+ getlowestcard(H, [S, R]) :- hascard(H, [S,R]).
1515+1616+PC-rules:
1717+ /* track all the cards played by other players */
1818+ event(cardPlayed(S, R, N), cardtable) <- true |
1919+ {
2020+ AddCardPlayed(S, R, N)
2121+ }
2222+2323+2424+ /* it's my turn playing */
2525+ message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] |
2626+ {
2727+2828+ /* find out the best card to play */
2929+ B( getlowestcard(H, [S, R]) );
3030+3131+ /* play the card */
3232+ @cardtable(playCard(S, R));
3333+3434+ /* discard beliefs about cards on the table */
3535+ while B( cardontable(S1, R1, X1) ) do
3636+ {
3737+ RemoveCardOnTable(S1,R1,X1)
3838+ };
3939+4040+ /* update beliefs about the cards I have */
4141+ B( deletehandcard(S, R, H, RES ) );
4242+ RemoveHand(H);
4343+ SetHand(RES)
4444+4545+ }
+41-26
code/2apl_platform/briscola_chiamata/notary.2apl
···33 { true } RemoveAssigned(POS, X) { not assigned(POS, X) }
44 { true } SetDealer(X) { dealer(X) }
55 { not currentturn(_) } UpdateTurn(X) { currentturn(X) }
66- { currentturn(X) } RemoveTrun(X) { not currentturn(X) }
66+ { currentturn(X) } RemoveTurn(X) { not currentturn(X) }
77+ { not rounds(_) } UpdateRounds(X) { rounds(X) }
88+ { rounds(X) } RemoveRounds(X) { not rounds(X) }
79 { true } PlayerPass(X) { playerpass(X) }
88- { true } AddCardPlayed(S, R, X) { cardontable(S, R, X) } /* Player X has played card of rank R and suit S */
99- { true } AddBriscola(S, R) { briscola(S, R) } /* Set the riscola to be a card of rank R and suit S */
1010+ { true } SetBriscola(S, R) { briscola(S, R) } /* Set the briscola to be a card of rank R and suit S */
1111+ { true } AddCardPlayed(S, R, X) { cardontable(S, R, X) } /* Keep track of cards on the table */
1012 { true } RemoveCardPlayed(S, R, X) { not cardontable(S, R, X) }
11131214 { not points(P, X) } AddPoints(P, X) { points(P, X) }
1315 { points(P, X) } RemovePoints(P, X) { not points(P, X) }
14161517Beliefs:
1616- gatekeeper(gk). /* we know who the gatekeeper is, for simplicity */
1818+ gatekeeper(gk). /* we know who the gatekeeper is, for simplicity */
1719 dealer(d).
1820 currentturn(0). /* the first turn is for the agent in postion 0 */
2121+ rounds(8). /* there are 8 rounds */
19222023 getpoints(jack, X) :- X is 2.
2124 getpoints(queen, X) :- X is 3.
···2427 getpoints(ace, X) :- X is 11.
2528 getpoints(Y, X) :- X is 0.
26292727- briscolaPlayed(X) :- cardontable(S, _, X), briscola(S, _). /* Keep track of who played a briscola */
3030+ 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 */
28312929- getwinner(Winner, Suit) :- cardontable(Suit, ace, Winner), !.
3030- getwinner(Winner, Suit) :- cardontable(Suit, three, Winner), !.
3131- getwinner(Winner, Suit) :- cardontable(Suit, king, Winner), !.
3232- getwinner(Winner, Suit) :- cardontable(Suit, queen, Winner), !.
3333- getwinner(Winner, Suit) :- cardontable(Suit, jack, Winner), !.
3434- getwinner(Winner, Suit) :- cardontable(Suit, seven, Winner), !.
3535- getwinner(Winner, Suit) :- cardontable(Suit, six, Winner), !.
3636- getwinner(Winner, Suit) :- cardontable(Suit, five, Winner), !.
3737- getwinner(Winner, Suit) :- cardontable(Suit, four, Winner), !.
3838- getwinner(Winner, Suit) :- cardontable(Suit, two, Winner), !.
3232+ getroundwinner(W, S) :- cardontable(S, ace, W), !.
3333+ getroundwinner(W, S) :- cardontable(S, three, W), !.
3434+ getroundwinner(W, S) :- cardontable(S, king, W), !.
3535+ getroundwinner(W, S) :- cardontable(S, queen, W), !.
3636+ getroundwinner(W, S) :- cardontable(S, jack, W), !.
3737+ getroundwinner(W, S) :- cardontable(S, seven, W), !.
3838+ getroundwinner(W, S) :- cardontable(S, six, W), !.
3939+ getroundwinner(W, S) :- cardontable(S, five, W), !.
4040+ getroundwinner(W, S) :- cardontable(S, four, W), !.
4141+ getroundwinner(W, S) :- cardontable(S, two, W), !.
39424343+ /*
4444+ * 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.
4545+ */
4046 major(X, Y) :- X >= Y.
4147 win(X, P1, [X, P1]).
4248 win(X, P1, [X, P1|T]) :- win(Y, P2, T), major(P1, P2).
···8995 message(X, inform, _, _, declarebriscola(Briscola)) <- true |
9096 {
9197 B( Briscola = [S, R] );
9292- AddBriscola(S, R);
9898+ SetBriscola(S, R);
9399 B( assigned(Pos, X) );
94100 if B( Pos = 0 ) then
95101 {
···148154 };
149155150156 // START THE GAME!!!
151151- selectturn()
157157+ selectturn()
152158 }
153159154160 /**
···158164 {
159165 if B( X = 5 ) then
160166 {
161161- RemoveTrun(X);
167167+ RemoveTurn(X);
162168 UpdateTurn(0);
163169 B( assigned(0, P));
164170 print("Round over!");
165165- countpoints()
171171+ [ countpoints() ];
172172+173173+ B( rounds(N) );
174174+ RemoveRounds(N);
175175+ UpdateRounds(N - 1);
176176+177177+ if B( rounds(N) and N = 0 ) then
178178+ {
179179+ while B ( assigned(POS, Y) ) do
180180+ {
181181+ send(Y, inform, gameisover(0));
182182+ RemoveAssigned(POS, Y)
183183+ }
184184+ }
166185 }
167186 else
168187 {
169188 B( assigned(X, P));
170189 send(P, inform, yourturn(X));
171171- RemoveTrun(X);
190190+ RemoveTurn(X);
172191 UpdateTurn(X + 1)
173192 }
174193 }
175194176195 event(cardPlayed(S, R, N), cardtable) <- true |
177196 {
178178- //TODO add card played to can count points
179197 AddCardPlayed(S, R, N);
180198 selectturn()
181199 }
···201219202220 if B( briscolaPlayed(_)) then
203221 {
204204- B( briscola(S,_) and getwinner(W, S))
222222+ B( briscola(S,_) and getroundwinner(W, S))
205223 }
206224 else
207225 {
208208- B( getwinner(W, S0))
226226+ B( getroundwinner(W, S0))
209227 };
210228211229 //Send point to the winner
212230 send(W, inform, yourpoints( X0 + X1 + X2 + X3 + X4));
213213- //@cardtable(updatePoints(W, X0 + X1 + X2 + X3 + X4));
214231 B( points(W, POINTS) );
215232 RemovePoints(W, POINTS);
216233 AddPoints(W, POINTS + X0 + X1 + X2 + X3 + X4);
···248265 send(X, inform, youlose(P))
249266 }
250267 }
251251-252252-
+33-23
code/2apl_platform/briscola_chiamata/player.2apl
···77 { hand(X) } RemoveHand(X) { not hand(X) }
88 { not lastbid(X) } AddLastBid(X) { lastbid(X) }
99 { lastbid(X) } RemoveLastBid(X) { not lastbid(X) }
1010-1111- { not points(X) } AddPoints(X) { points(X) }
1010+ { not points(X) } SetPoints(X) { points(X) }
1211 { points(X) } RemovePoints(X) { not points(X) }
1313-1412 { true } SetPartner(X) { partner(X) }
1515-1616- { true } AddBriscola(X) { briscola(X) }
1313+ { true } SetBriscola(S,R) { briscola(S,R) }
17141815Beliefs:
1916 notary(n).
···2118 dealer(d).
2219 player(X) :- assigned(POS, X).
23202424- getcard([], 0, []).
2525- getcard([X], 0, []).
2626- getcard([ S, R | REST ], 0, [S, R]).
2727- getcard([ S, R | REST ], I, X) :- Y is I - 1, getcard(REST, Y, X).
2121+ getfirstcard([], 0, []).
2222+ getfirstcard([X], 0, []).
2323+ getfirstcard([ S, R | REST ], 0, [S, R]).
2424+ getfirstcard([ S, R | REST ], I, X) :- Y is I - 1, getfirstcard(REST, Y, X).
28252929- iscard([], []).
3030- iscard([Card1, Card2 | REST ], [Card1, Card2]).
3131- iscard([ X, Y | REST ], Q) :- iscard(REST, Q).
2626+ hascard([], []).
2727+ hascard([Card1, Card2 | REST ], [Card1, Card2]).
2828+ hascard([ X, Y | REST ], Q) :- hascard(REST, Q).
32293330 deletehandcard(R, S, [R, S|T], T).
3434- deletehandcard(R, S, [X, Y|T], [H|T1]):- deletehandcard(R, S, T, T1).
3131+ deletehandcard(R, S, [X, Y|T], [X, Y|T1]):- deletehandcard(R, S, T, T1).
35323633 points(0).
3734···182179 message(X, inform, _, _, bidwinner(Y)) <- hand(H) |
183180 {
184181 print("I've the Briscola!");
185185- AddBriscola(0);
186182 //TODO: The knowledge of a general deck must be included into NPC belief base to be able to
187183 //chose a random card of the deck
188184 send(d, inform, askforacard(0))
189185 }
190186191191- message(d, inform, _, _, acard(X)) <- briscola(B) |
187187+ message(d, inform, _, _, acard(X)) <- true |
192188 {
193189 B(X = [S, R]);
194190 // --- Declare Briscola
195191 send(n, inform, declarebriscola([S, R]));
196192 @cardtable(briscolaDeclared(S, R));
197197- if B( iscard(H, [S, R]) ) then
193193+ if B( hascard(H, [S, R]) ) then
198194 {
199195 print("I go alone!");
200196 SetPartner(Me) // The player goes alone
···203199204200 message(X, inform, _, _, declarebriscola(Briscola, Y)) <- hand(H) |
205201 {
202202+ B(Briscola = [S,R]);
203203+ SetBriscola(S, R);
206204 // Update knowledge about the team
207207- if B( iscard(H, Briscola) ) then
205205+ if B( hascard(H, Briscola) ) then
208206 {
209207 print("is the parter of the declarer");
210208 SetPartner(Y)
···217215 message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] |
218216 {
219217220220- print("My turn!");
221221- B( getcard(H, 0, X ) ); //TODO Get a ramdom card.
218218+ print("My turn as default!");
219219+ B( getfirstcard(H, 0, X ) );
222220 B( X = [S, R] );
223221 @cardtable(playCard(S, R));
224222225223 // Update hand
226224 B( deletehandcard(S, R, H, RES ) );
227225 RemoveHand(H);
228228- SetHand(RES);
226226+ SetHand(RES)
229227228228+/*
230229 // Check if hand is ended
231230 if B(RES = []) then
232231 {
233232 endhand()
234233 }
234234+*/
235235+235236 }
236237237238 message(n, inform, _, _, yourpoints(Y)) <- true |
···239240 print("I received the points");
240241 B( points(P) );
241242 RemovePoints(P);
242242- AddPoints(P + Y)
243243+ SetPoints(P + Y)
243244 }
244245246246+/*****
245247 endhand() <- hand([]) |
246248 {
247249 print("I finish my hand!");
···249251 B( points(P) );
250252 send(n, inform, doiwin(P))
251253 }
254254+*****/
255255+256256+ message(n, inform, _, _, gameisover(X)) <- hand([]) |
257257+ {
258258+ RemoveHand([]);
259259+ B( points(P) );
260260+ send(n, inform, doiwin(P))
261261+ }
252262253263 /**
254254- * updateScore() should be moved in the notary agent?
264264+ * The updateScore external actions have to be moved into the notary agent.
265265+ * They are defined here for semplicity, at the moment.
255266 */
256267 message(n, inform, _, _, youwin(Y)) <- briscola(_) |
257268 {
···276287 B( assigned(Pos, Me) );
277288 @cardtable(updateScore(Me, -1))
278289 }
279279-