Clover Coverage Report - HeartsSkyThread Coverage Report
Coverage timestamp: gio dic 18 2014 15:52:24 EST
../../../../img/srcFileCovDistChart6.png 46% of files have more coverage
354   657   161   8,23
84   545   0,45   43
43     3,74  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Player       Line # 16 354 161 58,8% 0.58835757
 
No Tests
 
1    package game.shad.tempus.hearts;
2   
3    import java.util.ArrayList;
4   
5    import android.annotation.SuppressLint;
6    import android.graphics.Color;
7    import android.util.Log;
8    import android.view.LayoutInflater;
9    import android.view.View;
10    import android.widget.Button;
11    import android.widget.TableRow;
12    import android.widget.TextView;
13    import android.widget.Toast;
14   
15    @SuppressLint("ParserError")
 
16    public class Player {
17    public static final String TAG = "Hearts--Player";
18    private Game game;
19    ArrayList<Card> hand;
20    public ArrayList<ArrayList<Card>> takenHands = new ArrayList<ArrayList<Card>>();
21    public Deck deck =new Deck();
22    public int seat=0; //position
23    public String realName = "";
24    public int colorInt = 0;
25    public int state = 0; //using 1-4
26    public Player curPlayer;
27    public int score = 0;
28    public int totalScore=0;
29    public int passTo = 0;
30    public Deck clubs = new Deck(); //0
31    int highClub = 0;
32    int lowClub = 0;
33    public Deck diamonds = new Deck(); //1
34    int highDiamonds = 0;
35    int lowDiamonds = 0;
36    public Deck spades = new Deck(); //2
37    int highSpades = 0;
38    int lowSpades = 0;
39    public Deck hearts = new Deck(); //
40    int highHearts = 0;
41    int lowHearts = 0;
42    boolean winner = false;
43    boolean voidClubs;
44    boolean voidDiamonds;
45    boolean voidHearts;
46    boolean voidSpades;
47    private int IQ; //Then just a simple slider to change it and easy greater than if statments to do bot AI.
48    //This will let the IQ be changed in game. just Pust a slider around the AI portrait.
49    public LayoutInflater factory;
50   
51    public View textEntryView;
52    public Card twoOfClubs = null;
53   
 
54  32 toggle public Player(Game game, Deck deck, int score, int seat, String name, int color){
55  32 this.game = game;
56  32 this.deck = deck;
57  32 this.score = score;
58  32 this.seat = seat;
59  32 this.realName = name;
60  32 this.colorInt = color;
61  32 sortHand();
62   
63   
64    }
65    /**Checks if void in said suit.....Should be redone.
66    *
67    * this is not called from HeartsActivity but is an internal method.
68    * @param i the suit value.
69    * @return true if void in that suit.
70    */
71   
 
72  23 togglepublic boolean checkVoid(int i){;
73  23 switch(i){
74  23 case 0:
75  23 if(voidClubs)
76  0 return voidClubs;
77  23 break;
78  0 case 1:
79  0 if(voidDiamonds)
80  0 return voidDiamonds;
81  0 break;
82  0 case 2:
83  0 if(voidSpades)
84  0 return voidSpades;
85  0 break;
86  0 case 3:
87  0 if(voidHearts)
88  0 return voidHearts;
89  0 break;
90    }
91  23 return false;
92    }
93   
94   
 
95  0 toggle public boolean canPlaySuit(int i){
96  0 switch (i){
97  0 case 0:
98  0 return(voidClubs);
99  0 case 1:
100  0 return (voidDiamonds);
101  0 case 2:
102  0 return (voidSpades);
103  0 case 3:
104  0 return(voidHearts);
105    }
106  0 return false;
107    }
 
108  31 toggle public Card go(int round, ArrayList<Card> pile , Player p){
109  31 curPlayer=p;
110  31 Log.d(TAG, "player.go ="+curPlayer.getRealName());
111  31 if(pile.size()==0){
112  8 return playLow(0); //get two of clubs
113    //TODO add AI smarts.
114    //TODO start on different suits. aka go for voids.
115    }
116  23 int suit=pile.get(0).getSuit();
117  23 if(checkVoid(suit)){//This is the void CODE
118  0 Log.d(TAG, "void--PlayHigh("+suit+")");
119  0 if(suit<3){
120    //playing next suit
121  0 suit++;
122    }
123    else{ //suit is too high try for clubs
124    //No real problems with sending the wrong suit the call for play high and play low are recursive
125  0 suit=0;
126    }
127  0 Log.d(TAG, "going for void state="+state);
128  0 return playHigh(suit);
129    //TODO do all code for voids
130    }
131  23 Log.d(TAG, "state ="+state);
132  23 switch (state){ //REPLACED ps with STATE, removed call for it in constructor
133  5 case 1:{
134  5 switch (round){
135  0 case 0:
136  0 return playHigh(0);
137  0 case 1:
138  0 return playHigh(0);
139  5 case 2:
140   
141  0 case 3:
142   
143  0 case 4:
144  0 case 5:
145  0 case 6:
146  0 case 7:
147  5 Log.d(TAG, "round 0-7 --PlayLow("+suit+")");
148  5 return playLow(suit);
149  0 case 8:
150  0 case 9:
151  0 case 10:
152  0 case 11:
153  0 case 12:
154  0 case 13:
155  0 Log.d(TAG, "round 8-12 --PlayLow("+suit+")");
156  0 return playLow(suit);
157    }
158    }
159  8 case 2:
160   
161  8 switch (round){
162  0 case 0:
163  7 case 1:
164  1 case 2:
165  0 case 3:
166  0 case 4:
167  0 case 5:
168  0 case 6:
169  0 case 7:
170  8 Log.d(TAG, "round 0-7 --PlayLow("+suit+")");
171  8 return playLow(suit);
172  0 case 8:
173  0 case 9:
174  0 case 10:
175  0 case 11:
176  0 case 12:
177  0 case 13:
178   
179  0 Log.d(TAG, "round 8-12 --PlayLow("+suit+")");
180  0 return playLow(suit);
181    }
182  3 case 3:
183  3 switch (round){
184  0 case 0:
185  1 case 1:
186  2 case 2:
187  0 case 3:
188  0 case 4:
189  0 case 5:
190  0 case 6:
191  0 case 7:
192  3 Log.d(TAG, "round 8-12 --PlayLow("+suit+")");
193  3 return playLow(suit);
194  0 case 8:
195  0 case 9:
196  0 case 10:
197  0 case 11:
198  0 case 12:
199  0 case 13:
200  0 Log.d(TAG, "round 0-7 --PlayLow("+suit+")");
201  0 return playLow(suit);
202    }
203  7 case 4:
204  7 if(checkForPoints(pile)){
205  0 Log.d(TAG, "Play low--POINTS!!");
206  0 return playLow(suit);
207    }
208    else{
209  7 Log.d(TAG, "Play high--no points");
210  7 return playHigh(suit);
211    }
212    /*
213    switch (round){
214    case 0:
215    case 1:
216    case 2:
217    case 3:
218    case 4:
219    case 5:
220    case 6:
221    case 7:
222    Log.d(TAG, "round 0-7 --PlayLow("+suit+")", 175);
223    return playLow(suit);
224    case 8:
225    case 9:
226    case 10:
227    case 11:
228    case 12:
229    case 13:
230    Log.d(TAG, "round 8-12 --PlayHigh("+suit+")", 183);
231    return playHigh(suit);
232   
233    }
234    */
235    }
236  0 Log.d(TAG, "Out of all Loops !!SHOULD NOT HAPPEN!!--PlayHigh("+suit+")");
237  0 return playHigh(suit);
238    }
239   
240    /**
241    *
242    * @param suit
243    * @return the lowest card of a given suit.
244    */
 
245  25 toggle public Card playLow(int suit){
246  25 int outOfCards=0; //TODO
247  25 Card nextCard = null;
248  25 switch(suit){
249  24 case 0:
250  24 if(clubs.getSize()==0){
251  1 return playLow(++suit);
252    }
253  23 nextCard=clubs.getCard(0);
254  23 clubs.removeCardAtIndex(0);
255  23 return nextCard;
256  1 case 1:
257  1 if(diamonds.getSize()==0){
258  0 return playLow(++suit);
259    }
260  1 nextCard=diamonds.getCard(0);
261  1 diamonds.removeCardAtIndex(0);
262  1 return nextCard;
263  0 case 2:
264  0 if(spades.getSize()==0){
265  0 return playLow(++suit);
266    }
267  0 nextCard=spades.getCard(0);
268  0 spades.removeCardAtIndex(0);
269  0 return nextCard;
270  0 case 3:
271  0 if(hearts.getSize()==0){
272  0 return playLow(0);
273    }
274  0 nextCard=hearts.getCard(0);
275  0 hearts.removeCardAtIndex(0);
276  0 return nextCard;
277  0 case 4:
278  0 Log.d(TAG, "something Broken");
279  0 break;
280    }
281   
282  0 return nextCard;
283    }
 
284  7 toggle public Card playHigh(int suit){
285  7 Card nextCard = null;
286  7 switch(suit){
287  7 case 0:
288  7 if(clubs.getSize()==0){ //if suit is empty just recall this method with a higher suit.
289  0 return playHigh(++suit);
290    }
291    else{
292  7 nextCard = clubs.getCard(clubs.getSize()-1);
293  7 clubs.removeCardAtIndex(clubs.getSize()-1);
294  7 Log.d(TAG, nextCard.cardToString());
295  7 return nextCard;
296    }
297  0 case 1:
298  0 if(diamonds.getSize()==0){
299  0 return playHigh(++suit);
300    }
301    else{
302  0 nextCard=diamonds.getCard(diamonds.getSize()-1);
303  0 diamonds.removeCardAtIndex(diamonds.getSize()-1);
304  0 Log.d(TAG, nextCard.cardToString());
305  0 return nextCard;
306    }
307  0 case 2:
308  0 if(spades.getSize()==0){
309  0 return playHigh(++suit);
310    }
311  0 nextCard=spades.getCard(spades.getSize()-1);
312  0 spades.removeCardAtIndex(spades.getSize()-1);
313  0 Log.d(TAG, nextCard.cardToString());
314  0 return nextCard;
315  0 case 3:
316  0 if(hearts.getSize()==0){
317  0 return playHigh(0);
318    }
319  0 nextCard=hearts.getCard(hearts.getSize()-1);
320  0 hearts.removeCardAtIndex(hearts.getSize()-1);
321  0 Log.d(TAG, nextCard.cardToString());
322  0 return nextCard;
323    }
324  0 return nextCard;
325    }
326   
327   
 
328  0 toggle public void setRealName(String name){
329  0 realName = name;
330    }
331   
 
332  241 toggle public String getRealName(){
333  241 return realName;
334    }
335   
 
336  0 toggle public void setColor(int c){
337  0 colorInt=c;
338    }
339   
 
340  0 toggle public int getColor(){
341  0 return colorInt;
342    }
 
343  0 toggle public void setSeat(int s) {
344  0 seat=s;
345    }
 
346  80 toggle public int getSeat() {
347  80 return seat;
348    }
 
349  0 toggle public void setValue(int c) {
350  0 seat = c;
351    }
 
352  0 toggle public int getState() {
353  0 return state;
354    }
 
355  32 toggle public void setState(int c) {
356  32 state = c;
357    }
358   
 
359  10 toggle public void addDeckItem(ArrayList<Card> h){
360  10 takenHands.add(h); //deck.
361    }
362   
 
363  56 toggle public Deck getDeck(){
364  56 return deck;
365    }
366   
 
367  10 toggle public void addToScore(int score){
368  10 this.score += score;
369    }
 
370  0 toggle public void addToTotalScore(int i){
371  0 totalScore+=i;
372    }
 
373  18 toggle public int getScore(){
374  18 return score;
375    }
376   
 
377  96 toggle public Deck gethand() {
378  96 return deck;
379    }
 
380  0 toggle public void sethand(Deck deck1) {
381  0 this.deck.clearALL();
382  0 this.deck=deck1;
383  0 sortHand();
384    }
 
385  0 toggle public int getPass() {
386  0 return passTo;
387    }
 
388  0 toggle public void setPass(int passTo) {
389  0 this.passTo=passTo;
390    }
391   
 
392  32 toggle public void setClubs(Deck c){
393  32 this.clubs.addAllCards(c);
394  32 Log.d(TAG, "clubs.size="+clubs.getSize());
395    }
 
396  32 toggle public void setDiamonds(Deck d){
397  32 this.diamonds.addAllCards(d);
398  32 Log.d(TAG, "Diamonds.size="+diamonds.getSize());
399    }
 
400  32 toggle public void setSpades(Deck s){
401  32 this.spades.addAllCards(s);
402  32 Log.d(TAG, "Spades.size="+spades.getSize());
403    }
 
404  32 toggle public void setHearts(Deck h){
405  32 this.hearts.addAllCards(h);
406  32 Log.d(TAG, "Hearts.size="+hearts.getSize());
407    }
408   
 
409  0 toggle public void setClubsVoid(boolean c){
410  0 voidClubs=c;
411    //Is there was easy mode On show that they are void to help Player.
412    //Button p4ClubsB =(Button)findViewById(R.id.p4clubsButton);
413    //p4ClubsB.setText("c=VOID");
414    }
 
415  0 toggle public void setDiamondsVoid(boolean d){
416  0 voidDiamonds=d;
417    }
 
418  0 toggle public void setSpadesVoid(boolean s){
419  0 voidSpades=s;
420   
421    //Button p4SpadesB =(Button)findViewById(R.id.p4spadesButton);
422    //p4SpadesB.setText("c=VOID");
423    }
 
424  0 toggle public void setHeartsVoid(boolean h){
425  0 voidHearts=h;
426    }
 
427  8 toggle public Deck getClubs(){
428  8 return clubs;
429    }
 
430  8 toggle public Deck getDiamonds(){
431  8 return diamonds;
432    }
 
433  8 toggle public Deck getSpades(){
434  8 return spades;
435    }
 
436  8 toggle public Deck getHearts(){
437  8 return hearts;
438    }
 
439  19 toggle public boolean checkForTwo(){
440  19 int i;
441  163 for (i=0;i<13;i++){//Should only need to check the first two the rest is overkill.
442  152 if(this.deck.getCard(i).getValue()==(2)&&this.deck.getCard(i).getSuit()==(0)){
443  8 twoOfClubs = this.deck.getCard(i);
444  8 return true;
445    }
446    }
447  11 return false;
448    }
449   
 
450  32 toggle public void checkForVoids(){
451  32 int empty =0;
452  32 if(clubs.getSize()==0){
453  0 empty++;
454  0 setClubsVoid(true);
455    }
456  32 if(spades.getSize()==0){
457  0 empty++;
458  0 setSpadesVoid(true);
459    }
460  32 if(diamonds.getSize()==0){
461  0 empty++;
462  0 setDiamondsVoid(true);
463    }
464  32 if(hearts.getSize()==0){
465  0 empty++;
466  0 setHeartsVoid(true);
467    }
468  32 if(empty==4){
469  0 Log.d(TAG, "The ship is SINKING!!, we are out of cards");
470    }
471    //could this game be used to teach people hearts?
472    /*
473    if(voidHelper){
474    clubsButton.setText("c="+clubs.size());
475    clubsButton.setBackgroundColor(Color.MAGENTA);
476    diamondsButton.setText("d="+diamonds.size());
477    diamondsButton.setBackgroundColor(Color.MAGENTA);
478    spadesButton.setText("s="+spades.size());
479    spadesButton.setBackgroundColor(Color.MAGENTA);
480    heartsButton.setText("h="+hearts.size());
481    heartsButton.setBackgroundColor(Color.MAGENTA);
482    }
483    */
484   
485    }
486    /**
487    * Takes the deck and assigns all cards to the player
488    * then sorts them into suits
489    * and updates the DeckHolder.
490    * or it should....
491    */
 
492  32 toggle public void sortHand() {
493  32 Log.d(TAG, "sorting hand for "+this.realName);
494  32 Deck thand = new Deck();
495  32 thand.addAllCards(deck);
496  32 int z=0;
497  448 while(thand.getSize()>z){ //Lets the cards be kept and reviewed later
498  416 thand.getCard(z).setOwner(this);//had some issues this fixed them.
499  416 z++;
500    }
501  32 if(z!=13){
502    //if this is called the bots are probably cheating!
503  0 Log.d(TAG, "Hand was not 13 cards!!!");
504    }
505  32 int hc = 0; //high club
506  32 int hd = 0; //high diamond
507  32 int hs = 0; //high spade
508  32 int hh = 0; //high heart/
509  32 int clubsCounter = 0;
510  32 int diamondsCounter = 0;
511  32 int spadesCounter = 0;
512  32 int heartsCounter = 0;
513  32 int cc2 = 0; //(clubs counter 2) keep track of counters when rearranging deck
514  32 int dc2 = 0;
515  32 int sc2 = 0;
516  32 int hc2 = 0;
517  32 Deck c = new Deck();
518  32 Deck d = new Deck();
519  32 Deck s = new Deck();
520  32 Deck h = new Deck();
521  448 for(int i=0;i<thand.getSize();i++){
522  416 int ncard=thand.getCard(i).getValue();
523  416 switch(thand.getCard(i).getSuit()){
524  104 case 0:
525  104 cc2=clubsCounter;
526  104 if(hc>ncard){
527  43 while(clubsCounter>0&&ncard<c.getCard(clubsCounter-1).getValue()){
528  25 clubsCounter--;
529    }
530   
531    }
532  104 c.addCardAtIndex(clubsCounter, thand.getCard(i));
533  104 hc=c.getCard(c.getSize()-1).getValue();
534  104 clubsCounter=cc2;
535  104 clubsCounter++;
536   
537  104 break;
538  104 case 1:
539   
540  104 dc2=diamondsCounter;
541  104 if(hd>ncard){
542  31 while(diamondsCounter>0&&ncard<d.getCard(diamondsCounter-1).getValue()){
543  18 diamondsCounter--;
544    }
545   
546    }
547  104 d.addCardAtIndex(diamondsCounter, thand.getCard(i));
548  104 hd=d.getCard(d.getSize()-1).getValue();
549  104 diamondsCounter=dc2;
550  104 diamondsCounter++;
551   
552  104 break;
553  104 case 2:
554   
555  104 sc2=spadesCounter;
556  104 if(hs>ncard){
557  38 while(spadesCounter>0&&ncard<s.getCard(spadesCounter-1).getValue()){
558  23 spadesCounter--;
559    }
560   
561    }
562  104 s.addCardAtIndex(spadesCounter, thand.getCard(i));
563  104 hs=s.getCard(s.getSize()-1).getValue();
564  104 spadesCounter=sc2;
565  104 spadesCounter++;
566   
567  104 break;
568  104 case 3:
569   
570  104 hc2=heartsCounter;
571  104 if(hh>ncard){
572  46 while(heartsCounter>0&&ncard<h.getCard(heartsCounter-1).getValue()){
573  28 heartsCounter--;
574    }
575   
576    }
577  104 h.addCardAtIndex(heartsCounter, thand.getCard(i));
578  104 hh=h.getCard(h.getSize()-1).getValue();
579  104 heartsCounter=hc2;
580  104 heartsCounter++;
581  104 break;
582    }
583    }
584  32 setClubs(c);
585  32 setDiamonds(d);
586  32 setSpades(s);
587  32 setHearts(h);
588  32 updateDeck();
589    }
590   
 
591  87 toggle public void updateDeck(){
592  87 Deck newDeck = new Deck();
593  87 newDeck.addAllCards(this.clubs);
594  87 newDeck.addAllCards(this.diamonds);
595  87 newDeck.addAllCards(this.spades);
596  87 newDeck.addAllCards(this.hearts);
597  87 updateDeckCards(newDeck);
598    }
 
599  40 toggle public void updateSuits(){
600  40 clubs.clearALL();
601  40 diamonds.clearALL();
602  40 spades.clearALL();
603  40 hearts.clearALL();
604  40 for(Card card : deck.getDeck()){
605  462 switch(card.getSuit()){
606  87 case Card.CLUBS:
607  87 clubs.addCard(card);
608  87 break;
609  122 case Card.DIAMONDS:
610  122 diamonds.addCard(card);
611  122 break;
612  128 case Card.SPADES:
613  128 spades.addCard(card);
614  128 break;
615  125 case Card.HEARTS:
616  125 hearts.addCard(card);
617  125 break;
618    }
619    }
620    }
621   
 
622  87 toggle public void updateDeckCards(Deck cards){
623  87 deck.clearALL();
624  1119 for(int i = 0; i<cards.getSize();i++){
625  1032 this.deck.addCard(cards.getCard(i));
626    }
627    }
 
628  7 toggle public boolean checkForPoints(ArrayList<Card> c) {
629  7 int points=0;
630  28 for(int i=0; i<c.size();i++){
631  21 int curCard = c.get(i).getValue();
632  21 int curSuit = c.get(i).getSuit();
633  21 if(curSuit==1){ //Diamonds check for jack.
634  1 if(curCard==11){
635  1 points-=10;
636   
637    }
638    }
639  21 if(curSuit==2){//Spades check for queen
640  0 if(curCard==12){
641  0 points+=13;
642   
643    }
644    }
645  21 if(curSuit==3){//heart--add points
646  0 points++;
647    }
648   
649   
650    }
651  7 if(points>0){
652  0 return true;
653    }
654  7 return false;
655    }
656   
657    }