2-APL UPC project.
0
fork

Configure Feed

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

keep track of rounds, points on the table for each rounds plus simple strategy with plan repair rules

fdesan 3a9e3b39 41b14108

+115 -23
+107 -20
code/2apl_platform/briscola_chiamata/fabrizio.2apl
··· 1 1 Include: player.2apl 2 2 3 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 */ 4 + { true } AddCardPlayed(S, R, X) { cardplayed(S, R, X) } /* Keep track of history of cards */ 5 + { true } AddCardOnTable(S, R, X) { cardontable(S, R, X) } /* Keep track of cards on table */ 6 + { cardontable(S,R,X) } RemoveCardOnTable(S,R,X) { not cardontable(S,R,X) } 8 7 { not hasplayed(_) } SetHasPlayed(X) { hasplayed(X) } /* Keep track of who is playing */ 9 8 { hasplayed(X) } RemoveHasPlayed(X) { not hasplayed(X) } 9 + { not round(_) } SetRound(X) { round(X) } /* Keep track of round */ 10 + { round(X) } RemoveRound(X) { not round(X) } 11 + { not pointsontable(_) } SetPoints(X) { pointsontable(X) } /* Keep track of points on table */ 12 + { pointsontable(X) } RemovePoints(X) { not pointsontable(X) } 10 13 11 14 Beliefs: 12 15 nopoints(X) :- (X=two;X=four;X=five;X=six;X=seven). 13 16 fewpoints(X) :- (X=jack;X=queen;X=king). 14 17 manypoints(X) :- (X=ace;X=three). 15 18 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 + getlowcard(H, [S, R]) :- hascard(H, [S,R]), nopoints(R), not briscola(S, _), !. 20 + getlowcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), not briscola(S, _), !. 21 + getlowcard(H, [S, R]) :- hascard(H, [S,R]), not briscola(S, _). 19 22 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 + gethighcard(H, [S, R]) :- hascard(H, [S,R]), manypoints(R), not briscola(S, _), !. 24 + gethighcard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), not briscola(S, _), !. 25 + gethighcard(H, [S, R]) :- hascard(H, [S,R]), not briscola(S, _). 23 26 24 - hasplayed(0). 27 + getlowbriscolacard(H, [S, R]) :- hascard(H, [S,R]), nopoints(R), briscola(S, _), !. 28 + getlowbriscolacard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), briscola(S, _), !. 29 + getlowbriscolacard(H, [S, R]) :- hascard(H, [S,R]), briscola(S, _). 25 30 31 + gethighbriscolacard(H, [S, R]) :- hascard(H, [S,R]), manypoints(R), briscola(S, _), !. 32 + gethighbriscolacard(H, [S, R]) :- hascard(H, [S,R]), fewpoints(R), briscola(S, _), !. 33 + gethighbriscolacard(H, [S, R]) :- hascard(H, [S,R]), not briscola(S, _). 34 + 35 + hasplayed(0). 36 + pointsontable(0). 37 + round(1). 38 + firstrounds(X) :- (X=1,X=2). 26 39 27 40 PC-rules: 28 41 /* track all the cards played by other players _before_ me */ 29 42 event(cardPlayed(S, R, N), cardtable) <- true | 30 43 { 44 + [ 45 + B( hasplayed(P1)); 46 + AddCardPlayed(S, R, P1); 31 47 if B( assigned(P0, _) and hasplayed(P1) and P0 > P1 ) then 32 48 { 33 - AddCardPlayed(S, R, N) 49 + B( hasplayed(P1)); 50 + AddCardOnTable(S, R, P1); 51 + B( pointsontable(PT)); 52 + B(getpoints(R, R1)); 53 + RemovePoints(PT); 54 + SetPoints(PT + R1) 34 55 }; 35 56 36 57 if B( hasplayed(P1) and P1 = 4) then 37 58 { 59 + B (hasplayed(P1)); 38 60 RemoveHasPlayed(P1); 39 - SetHasPlayed(0) 61 + SetHasPlayed(0); 62 + B(round(R1)); 63 + RemoveRound(R1); 64 + SetRound(R1+1); 65 + B( pointsontable(PT)); 66 + RemovePoints(PT); 67 + SetPoints(0) 40 68 } 41 69 else 42 70 { 43 71 B ( hasplayed(P1)); 44 72 RemoveHasPlayed(P1); 45 73 SetHasPlayed(P1 + 1) 46 - } 47 - 74 + } ] 48 75 } 49 76 50 77 /* it's my turn playing */ 51 78 message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] | 52 79 { 53 - 80 + [ 54 81 /* find out the best card to play */ 55 - B( getlowcard(H, [S, R]) ); 56 - 57 - /* play the card */ 82 + if B(pointsontable(PT) and PT > 15) then 83 + { 84 + B( gethighbriscolacard(H, [S, R]) ) 85 + } 86 + else 87 + { 88 + if B(assigned(POS, _) and POS = 4 and briscola(BS, _) and not cardontable(BS, _, _) and pointontable(PT) and PT > 5) then 89 + { 90 + B( cardontable(S, _, 0)); 91 + B( gethighcard(H, [S, R]) ) 92 + } 93 + else 94 + { 95 + if B(round(RND) and firstrounds(RND) and not briscola(S,_)) then 96 + { 97 + B( getlowcard(H, [S, R]) ) 98 + } 99 + else 100 + { 101 + B( getlowcard(H, [S, R]) ) 102 + } 103 + } 104 + }; 58 105 @cardtable(playCard(S, R)); 106 + cleanup(S, R, H) 107 + ] 108 + } 59 109 110 + cleanup(S, R, H) <- true | 111 + { 112 + [ 60 113 /* discard beliefs about cards on the table */ 61 114 while B( cardontable(S1, R1, X1) ) do 62 115 { 63 - [ RemoveCardOnTable(S1,R1,X1) ] 116 + RemoveCardOnTable(S1,R1,X1) 64 117 }; 65 118 66 119 /* update beliefs about the cards I have */ 67 120 B( deletehandcard(S, R, H, RES ) ); 68 121 RemoveHand(H); 69 122 SetHand(RES) 123 + ] 124 + 125 + } 70 126 127 + PR-rules: 128 + B(getlowcard(H, [S0,R0])); @cardtable(playCard(S0,R0)); REST <- true | 129 + { 130 + print("Plan Repair rule 1!"); 131 + B(getlowbriscolacard(H, [S, R])); 132 + @cardtable(playCard(S, R)); 133 + cleanup(S, R, H) 134 + } 135 + 136 + B(gethighcard(H, [S0,R0])); @cardtable(playCard(S0,R0)); REST <- true | 137 + { 138 + print("Plan Repair rule 2!"); 139 + B(getlowbriscolacard(H, [S, R])); 140 + @cardtable(playCard(S, R)); 141 + cleanup(S, R, H) 142 + } 143 + 144 + B(getlowbriscolacard(H, [S0,R0])); @cardtable(playCard(S0,R0)); REST <- true | 145 + { 146 + print("Plan Repair rule 3!"); 147 + B(getlowcard(H, [S, R])); 148 + @cardtable(playCard(S, R)); 149 + cleanup(S, R, H) 150 + } 151 + 152 + B(gethighbriscolacard(H, [S0,R0])); @cardtable(playCard(S0,R0)); REST <- true | 153 + { 154 + print("Plan Repair rule 4!"); 155 + B(getlowcard(H, [S, R])); 156 + @cardtable(playCard(S, R)); 157 + cleanup(S, R, H) 71 158 }
+1 -3
code/2apl_platform/briscola_chiamata/player.2apl
··· 27 27 hascard([ X, Y | REST ], Q) :- hascard(REST, Q). 28 28 29 29 deletehandcard(R, S, [R, S|T], T). 30 - deletehandcard(R, S, [X, Y|T], [X, Y|T1]):- deletehandcard(R, S, T, T1). 30 + deletehandcard(R, S, [X, Y|T], [X, Y|T1]) :- deletehandcard(R, S, T, T1). 31 31 32 32 points(0). 33 33 ··· 213 213 */ 214 214 message(n, inform, _, _, yourturn(Y)) <- hand(H) and not H = [] | 215 215 { 216 - 217 - print("My turn as default!"); 218 216 B( getfirstcard(H, 0, X ) ); 219 217 B( X = [S, R] ); 220 218 @cardtable(playCard(S, R));
+7
code/2apl_platform/environments/cardtable/Table.java
··· 190 190 } 191 191 192 192 public void updatePoints(String name, int position, int points) { 193 + java.net.URL imgURL = getClass().getResource("cards/b.gif"); 194 + ImageIcon cardBack = new ImageIcon(imgURL); 195 + 193 196 Integer pointsInt = new Integer(points); 194 197 JLabel pointsLab = (JLabel) playersPane[position].getComponent(2); 195 198 pointsLab.setText("Points: "+pointsInt.toString()); ··· 198 201 if(round<9) { 199 202 Integer roundInt = new Integer(round); 200 203 roundLab.setText("Round : "+roundInt.toString()); 204 + } 205 + for (int i = 0; i < 5; i++) { 206 + JLabel cardLab = (JLabel) layeredPane.getComponent(i); 207 + cardLab.setIcon(cardBack); 201 208 } 202 209 setVisible( true ); 203 210 }