Advertisement
VRonin

Scopa

Feb 4th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #define clear system("cls") //questo è per windows, elimina il contenuto della console
  6. #define QUADRI 1
  7. using namespace std;
  8.  
  9. const string NomiSemi[4]={"Cuori","Quadri","Fiori","Picche"};
  10.  
  11. void pausa(){
  12.     string fake;
  13.     cout << endl << "Premere Invio Per continuare...";
  14.     cin.ignore(1000,'\n');
  15.     getline(cin,fake,'\n');
  16. }
  17.  
  18. struct carta /*definisco la lista linkata*/
  19.  {
  20.     int seme;
  21.     int numero;
  22.     carta *Next;
  23.  };
  24.  
  25.  int length(carta* Head) /*calcola quanti elementi ci sono nella lista linkata*/
  26.  {
  27.     carta *cur_ptr; /*il puntatore che attraverserà la lista*/
  28.     int count=0; //il contatore degli elementi in lista
  29.  
  30.     cur_ptr=Head;
  31.  
  32.     while(cur_ptr != NULL) //finchè non raggiungo la fine della lista
  33.     {
  34.        cur_ptr=cur_ptr->Next; //vai avanti di un passo
  35.        count++; //incrementa il contatore di 1
  36.     }
  37.     return count;
  38.  }
  39.  
  40. carta* addBeg(carta* Head, int sem, int num) //aggiunge l'elemento di seme sem e valore num all'inizio della lista Head
  41.  {
  42.     struct carta *temp; /*creo un nuovo elemento della lista allocando la memoria on the heap e inserendoci i dati*/
  43.     temp= new carta;
  44.     temp->numero=num;
  45.     temp->seme=sem;
  46.  
  47.     if (Head == NULL) //se la lista è vuota
  48.     {
  49.        Head=temp; //La lista inizierà dal nuovo elemento
  50.        Head->Next=NULL; //L'elemento successivo è NULL
  51.     }
  52.     else //se c'era già qualcosa in lista
  53.     {
  54.        temp->Next=Head; //l'elemento successivo al nuovo elemento è quello con cui iniziava la lista
  55.        Head=temp; //la lista inizia dal nuovo elemento
  56.     }
  57.     return Head;
  58.  }
  59.  
  60. void display(carta* Head){ //visualizza la lista linkata
  61.     carta* curr=Head;
  62.     if (curr==NULL) cout << endl << "Il mazzo e' vuoto";
  63.     else cout << endl;
  64.     while(curr!=NULL){
  65.         cout << curr->numero << " di " << NomiSemi[curr->seme] << '\t';
  66.         curr=curr->Next;
  67.     }
  68. }
  69.  
  70.  carta* Libera(carta* Head){ //svuota la lista liberando la memoria allocata
  71.      carta* temp;
  72.      while (Head!=NULL){ //finchè la lista non è vuota
  73.          temp=Head->Next; //elimina il primo elemento e passa a quello successivo
  74.          delete Head;
  75.          Head=temp;
  76.      }
  77.      return Head;
  78.  }
  79.  
  80.  carta* CreaMazzo(carta* Head){
  81.     if (Head!=NULL) Head=Libera(Head);
  82.     for (int i=0;i<4;i++){ //ciclo i semi
  83.         for(int j=1;j<=10;j++){ //ciclo i numeri
  84.             Head=addBeg(Head, i, j);
  85.         }
  86.     }
  87.     return Head;
  88.  }
  89.  
  90. carta* Mescola(carta *list) //Classico algoritmo mergesort (il più efficiente con le liste linkate) con operatore di confronto un random
  91. {
  92.     if (!list || !list->Next) return list;
  93.     carta *right=list,*temp=list,*last=list,*result=0,*Next=0,*tail=0;
  94.     while (temp && temp->Next) {last=right;right=right->Next,temp=temp->Next->Next;}
  95.     last->Next=0;
  96.     list=Mescola(list);
  97.     right=Mescola(right);
  98.     while (list || right)
  99.     {
  100.         if (!right)                     {Next=list;list=list->Next;}
  101.         else if (!list)                 {Next=right;right=right->Next;}
  102.         else if (rand()%2==0)             {Next=list;list=list->Next;}
  103.         else                            {Next=right;right=right->Next;}
  104.         if (!result) result=Next; else tail->Next=Next;
  105.         tail=Next;
  106.     }
  107.     return result;
  108. }
  109.  
  110. carta* EstraiPrima(carta* sorgente, carta* &destinazione){ //mette la prima carta presente nel mazzo sorgente nel mazzo destinazione
  111.     if (sorgente==NULL) return NULL;
  112.     carta* sor=sorgente;
  113.     destinazione=addBeg(destinazione, sor->seme, sor->numero);
  114.     sorgente=sor->Next;
  115.     delete sor;
  116.     return sorgente;
  117. }
  118.  
  119. bool Presa(carta* &tavolo, carta* &gioca, carta* &mazzo){
  120.     /*Se la carta gioca prende, le carte prese in tavolo vengono spostate in mazzo e se il tavolo è vuoto scopa viene incrementato.
  121.     Ritorna 0 se la carta non prende nulla, e 1 se prende*/
  122.     carta* tv1=tavolo;
  123.     carta* tv2=NULL;
  124.     carta* tv3;
  125.     carta* tv4;
  126.     carta* tv5;
  127.     carta* tv6;
  128.     carta* tv7;
  129.     carta* tv8;
  130.     carta* tv9;
  131.     carta* tv10;
  132.     while(tv1!=NULL){ //cerco le carte con lo stesso numero
  133.         if (gioca->numero==tv1->numero){
  134.             mazzo=addBeg(mazzo,tv1->seme,tv1->numero);
  135.             if(tv2==NULL){
  136.                 tavolo=tv1->Next;
  137.                 delete tv1;
  138.             }
  139.             else{
  140.                 tv2->Next=tv1->Next;
  141.                 delete tv1;
  142.             }
  143.             return true;
  144.  
  145.         }
  146.         tv2=tv1;
  147.         tv1=tv1->Next;
  148.     }
  149.     //somme
  150.     if (tavolo!=NULL && tavolo->Next!=NULL){ //se ci sono almeno 2 carte in tavola
  151.         tv1=tavolo;
  152.         tv2=NULL;
  153.         while(tv1!=NULL){
  154.             tv3=tv1->Next;
  155.             tv4=tv1;
  156.             while(tv3!=NULL){
  157.                 if(gioca->numero==tv1->numero+tv3->numero){
  158.                     mazzo=addBeg(mazzo,tv1->seme,tv1->numero);
  159.                     mazzo=addBeg(mazzo,tv3->seme,tv3->numero);
  160.                     tv4->Next=tv3->Next;
  161.                     delete tv3;
  162.                     if(tv2==NULL){
  163.                         tavolo=tv1->Next;
  164.                         delete tv1;
  165.                     }
  166.                     else{
  167.                         tv2->Next=tv1->Next;
  168.                         delete tv1;
  169.                     }
  170.                     return true;
  171.                 }
  172.                 tv4=tv3;
  173.                 tv3=tv3->Next;
  174.             }
  175.             tv2=tv1;
  176.             tv1=tv1->Next;
  177.         }
  178.     }
  179.     if (length(tavolo)>=3){ //se ci sono almeno 3 carte in tavola
  180.         tv1=tavolo;
  181.         tv2=NULL;
  182.         while(tv1!=NULL){
  183.             tv3=tv1->Next;
  184.             tv4=tv1;
  185.             while(tv3!=NULL){
  186.                 tv5=tv3->Next;
  187.                 tv6=tv3;
  188.                 while (tv5!=NULL){
  189.                     if(gioca->numero==tv1->numero+tv3->numero+tv5->numero){
  190.                         mazzo=addBeg(mazzo,tv1->seme,tv1->numero);
  191.                         mazzo=addBeg(mazzo,tv3->seme,tv3->numero);
  192.                         mazzo=addBeg(mazzo,tv5->seme,tv5->numero);
  193.                         tv6->Next=tv5->Next;
  194.                         delete tv5;
  195.                         tv4->Next=tv3->Next;
  196.                         delete tv3;
  197.                         if(tv2==NULL){
  198.                             tavolo=tv1->Next;
  199.                             delete tv1;
  200.                         }
  201.                         else{
  202.                             tv2->Next=tv1->Next;
  203.                             delete tv1;
  204.                         }
  205.                         return true;
  206.                     }
  207.                     tv6=tv5;
  208.                     tv5=tv5->Next;
  209.                 }
  210.                 tv4=tv3;
  211.                 tv3=tv3->Next;
  212.             }
  213.             tv2=tv1;
  214.             tv1=tv1->Next;
  215.         }
  216.     }
  217.     if (length(tavolo)>=4){ //se ci sono almeno 4 carte in tavola
  218.         tv1=tavolo;
  219.         tv2=NULL;
  220.         while(tv1!=NULL){
  221.             tv3=tv1->Next;
  222.             tv4=tv1;
  223.             while(tv3!=NULL){
  224.                 tv5=tv3->Next;
  225.                 tv6=tv3;
  226.                 while (tv5!=NULL){
  227.                     tv7=tv5->Next;
  228.                     tv8=tv5;
  229.                     while (tv7!=NULL){
  230.                         if(gioca->numero==tv1->numero+tv3->numero+tv5->numero+tv7->numero){
  231.                             mazzo=addBeg(mazzo,tv1->seme,tv1->numero);
  232.                             mazzo=addBeg(mazzo,tv3->seme,tv3->numero);
  233.                             mazzo=addBeg(mazzo,tv5->seme,tv5->numero);
  234.                             mazzo=addBeg(mazzo,tv7->seme,tv7->numero);
  235.                             tv8->Next=tv7->Next;
  236.                             delete tv7;
  237.                             tv6->Next=tv5->Next;
  238.                             delete tv5;
  239.                             tv4->Next=tv3->Next;
  240.                             delete tv3;
  241.                             if(tv2==NULL){
  242.                                 tavolo=tv1->Next;
  243.                                 delete tv1;
  244.                             }
  245.                             else{
  246.                                 tv2->Next=tv1->Next;
  247.                                 delete tv1;
  248.                             }
  249.                             return true;
  250.  
  251.                         }
  252.                         tv8=tv7;
  253.                         tv7=tv7->Next;
  254.                     }
  255.                     tv6=tv5;
  256.                     tv5=tv5->Next;
  257.                 }
  258.                 tv4=tv3;
  259.                 tv3=tv3->Next;
  260.             }
  261.             tv2=tv1;
  262.             tv1=tv1->Next;
  263.         }
  264.     }
  265.     if (length(tavolo)>=5){ //se ci sono almeno 5 carte in tavola
  266.         tv1=tavolo;
  267.         tv2=NULL;
  268.         while(tv1!=NULL){
  269.             tv3=tv1->Next;
  270.             tv4=tv1;
  271.             while(tv3!=NULL){
  272.                 tv5=tv3->Next;
  273.                 tv6=tv3;
  274.                 while (tv5!=NULL){
  275.                     tv7=tv5->Next;
  276.                     tv8=tv5;
  277.                     while (tv7!=NULL){
  278.                         tv9=tv7->Next;
  279.                         tv10=tv7;
  280.                         while (tv9!=NULL){
  281.                             if(gioca->numero==tv1->numero+tv3->numero+tv5->numero+tv7->numero+tv9->numero){
  282.                                 mazzo=addBeg(mazzo,tv1->seme,tv1->numero);
  283.                                 mazzo=addBeg(mazzo,tv3->seme,tv3->numero);
  284.                                 mazzo=addBeg(mazzo,tv5->seme,tv5->numero);
  285.                                 mazzo=addBeg(mazzo,tv7->seme,tv7->numero);
  286.                                 mazzo=addBeg(mazzo,tv9->seme,tv9->numero);
  287.                                 tv10->Next=tv9->Next;
  288.                                 delete tv9;
  289.                                 tv8->Next=tv7->Next;
  290.                                 delete tv7;
  291.                                 tv6->Next=tv5->Next;
  292.                                 delete tv5;
  293.                                 tv4->Next=tv3->Next;
  294.                                 delete tv3;
  295.                                 if(tv2==NULL){
  296.                                     tavolo=tv1->Next;
  297.                                     delete tv1;
  298.                                 }
  299.                                 else{
  300.                                     tv2->Next=tv1->Next;
  301.                                     delete tv1;
  302.                                 }
  303.                                 return true;
  304.                             }
  305.                             tv10=tv9;
  306.                             tv9=tv9->Next;
  307.                         }
  308.                         tv8=tv7;
  309.                         tv7=tv7->Next;
  310.                     }
  311.                     tv6=tv5;
  312.                     tv5=tv5->Next;
  313.                 }
  314.                 tv4=tv3;
  315.                 tv3=tv3->Next;
  316.             }
  317.             tv2=tv1;
  318.             tv1=tv1->Next;
  319.         }
  320.     }
  321.  
  322.     return false;
  323. }
  324.  
  325. int ContaPunti(carta* Mazzo){
  326.     carta* curr=Mazzo;
  327.     int result=0;
  328.     int ori=0;
  329.     if (length(Mazzo)>20) result++; //carte
  330.     while(curr!=NULL){
  331.         if (curr->seme==QUADRI){
  332.             ori++;
  333.             if (curr->numero==7) result++; //settebello
  334.         }
  335.         curr=curr->Next;
  336.     }
  337.     if (ori>5) result++; //ori
  338.     return result;
  339. }
  340.  
  341. bool MaggiorePrimiera(int a, int b){ //Ritorna vero se a vale di più di b nella primiera
  342.     if (a==b) return false;
  343.     if (a==0) return false;
  344.     if (b==0) return true;
  345.     if (a==7) return true;
  346.     if (b==7) return false;
  347.     if (a==6) return true;
  348.     if (b==6) return false;
  349.     if (a==1) return true;
  350.     if (b==1) return false;
  351.     if (a==5) return true;
  352.     if (b==5) return false;
  353.     if (a==4) return true;
  354.     if (b==4) return false;
  355.     if (a==3) return true;
  356.     if (b==3) return false;
  357.     if (a==2) return true;
  358.     if (b==2) return false;
  359.     if (a==10) return true;
  360.     if (b==10) return false;
  361.     if (a==9) return true;
  362.     if (b==9) return false;
  363.     if (a==8) return true;
  364.     if (b==8) return false;
  365.     return false;
  366. }
  367.  
  368. int ValorePrimiera(int n){ //ritorna il valore, in punti della primiera, del numero n
  369.     if (n==7) return 21;
  370.     if (n==6) return 18;
  371.     if (n==1) return 16;
  372.     if (n==5) return 15;
  373.     if (n==6) return 14;
  374.     if (n==1) return 13;
  375.     if (n==5) return 12;
  376.     if (n>=8 && n<=10) return 10;
  377.     return 0;
  378. }
  379.  
  380. int Primiera(carta* Mazzo1, carta* Mazzo2){ //ritorna 1 se la primiera è del mazzo 1, 2 se è del mazzo 2, 0 se è patta
  381.     int maxG1 [4]={0,0,0,0}; //per i due giocatori registro il massimo valore di carta (secondo l'ordinamento della primiera) per ogni seme
  382.     int maxG2 [4]={0,0,0,0};
  383.     carta* M1=Mazzo1;
  384.     carta* M2=Mazzo2;
  385.     int totG1=0;
  386.     int totG2=0;
  387.     while (M1!=NULL){
  388.         if (MaggiorePrimiera(M1->numero,maxG1[M1->seme])) maxG1[M1->seme]=M1->numero;
  389.         M1=M1->Next;
  390.     }
  391.     while (M2!=NULL){
  392.         if (MaggiorePrimiera(M2->numero,maxG2[M2->seme])) maxG1[M2->seme]=M2->numero;
  393.         M2=M2->Next;
  394.     }
  395.     for (int i=0;i<4;i++){
  396.         totG1+=ValorePrimiera(maxG1[i]);
  397.         totG2+=ValorePrimiera(maxG2[i]);
  398.     }
  399.     if (totG1==totG2) return 0;
  400.     if (totG1>totG2) return 1;
  401.     return 2;
  402. }
  403.  
  404.  int main(){
  405.      int scelta;
  406.      int last; //memorizza chi ha preso per ultimo
  407.      carta* temp;
  408.      carta* Mazzo=NULL;
  409.      carta* Tavolo=NULL;
  410.      carta* Giocatore1=NULL;
  411.      carta* PreseG1=NULL;
  412.      int scopeG1=0;
  413.      int puntiG1=0;
  414.      carta* Giocatore2=NULL;
  415.      carta* PreseG2=NULL;
  416.      int scopeG2=0;
  417.      int puntiG2=0;
  418.      srand(time(NULL));
  419.      while (puntiG1<21 && puntiG2<21){
  420.          Mazzo=CreaMazzo(Mazzo);
  421.          Mazzo=Mescola(Mazzo);
  422.          for (int i=0;i<4;i++){ //distribuisco le carte
  423.             if(i<3){
  424.                 Mazzo=EstraiPrima(Mazzo,Giocatore1);
  425.                 Mazzo=EstraiPrima(Mazzo,Giocatore2);
  426.             }
  427.             Mazzo=EstraiPrima(Mazzo,Tavolo);
  428.          }
  429.          while (Mazzo!=NULL){
  430.             //Round
  431.              while(Giocatore1!=NULL && Giocatore2!=NULL){
  432.                  clear;
  433.                  cout << "Carte in tavola:";
  434.                  display(Tavolo);
  435.                  cout << endl << "Carte nella mano di Giocatore 1:" << endl;
  436.                  for (int i=0; i<length(Giocatore1); i++) cout << (char)('1'+i) << '\t' << '\t'; //numera le carte
  437.                  display(Giocatore1);
  438.                  scelta=1;
  439.                  do{ //mi assicuro che la scelta sia valida
  440.                      if (scelta<=0 || scelta>length(Giocatore1)) cout << endl << "Scelta non Valida!";
  441.                      cout << endl << "Quale Carta vuoi Giocare? "; cin >> scelta;
  442.                  }while(scelta<=0 || scelta>length(Giocatore1));
  443.                  switch(scelta){
  444.                     case 1:
  445.                         if (Presa(Tavolo,Giocatore1,PreseG1)){ //se prende sposta la carta dalla mano al mazzo
  446.                             last=1;
  447.                             if (Tavolo==NULL) scopeG1++; //se non ci sono più carte in tavola hai fatto scopa
  448.                             PreseG1=addBeg(PreseG1,Giocatore1->seme,Giocatore1->numero);
  449.                             temp=Giocatore1;
  450.                             Giocatore1=Giocatore1->Next;
  451.                             delete temp;
  452.                         }
  453.                         else { //se no aggiungila in tavola
  454.                             Tavolo=addBeg(Tavolo,Giocatore1->seme,Giocatore1->numero);
  455.                             temp=Giocatore1;
  456.                             Giocatore1=Giocatore1->Next;
  457.                             delete temp;
  458.                         }
  459.                         break;
  460.                     case 2:
  461.                         if (Presa(Tavolo,Giocatore1->Next,PreseG1)){ //se prende sposta la carta dalla mano al mazzo
  462.                             last=1;
  463.                             if (Tavolo==NULL) scopeG1++; //se non ci sono più carte in tavola hai fatto scopa
  464.                             PreseG1=addBeg(PreseG1,Giocatore1->Next->seme,Giocatore1->Next->numero);
  465.                             temp=Giocatore1->Next;
  466.                             Giocatore1->Next=Giocatore1->Next->Next;
  467.                             delete temp;
  468.                         }
  469.                         else { //se no aggiungila in tavola
  470.                             Tavolo=addBeg(Tavolo,Giocatore1->Next->seme,Giocatore1->Next->numero);
  471.                             temp=Giocatore1->Next;
  472.                             Giocatore1->Next=Giocatore1->Next->Next;
  473.                             delete temp;
  474.                         }
  475.                         break;
  476.                     case 3:
  477.                         if (Presa(Tavolo,Giocatore1->Next->Next,PreseG1)){ //se prende sposta la carta dalla mano al mazzo
  478.                             last=1;
  479.                             if (Tavolo==NULL) scopeG1++; //se non ci sono più carte in tavola hai fatto scopa
  480.                             PreseG1=addBeg(PreseG1,Giocatore1->Next->Next->seme,Giocatore1->Next->Next->numero);
  481.                             temp=Giocatore1->Next->Next;
  482.                             Giocatore1->Next->Next=Giocatore1->Next->Next->Next;
  483.                             delete temp;
  484.                         }
  485.                         else { //se no aggiungila in tavola
  486.                             Tavolo=addBeg(Tavolo,Giocatore1->Next->Next->seme,Giocatore1->Next->Next->numero);
  487.                             temp=Giocatore1->Next->Next;
  488.                             Giocatore1->Next->Next=Giocatore1->Next->Next->Next;
  489.                             delete temp;
  490.                         }
  491.                         break;
  492.                  }
  493.                  clear;
  494.                  cout << "Carte in tavola:";
  495.                  display(Tavolo);
  496.                  cout << endl << "Carte nella mano di Giocatore 2:" << endl;
  497.                  for (int i=0; i<length(Giocatore2); i++) cout << (char)('1'+i) << '\t' << '\t'; //numera le carte
  498.                  display(Giocatore2);
  499.                  scelta=1;
  500.                  do{ //mi assicuro che la scelta sia valida
  501.                      if (scelta<=0 || scelta>length(Giocatore2)) cout << endl << "Scelta non Valida!";
  502.                      cout << endl << "Quale Carta vuoi Giocare? "; cin >> scelta;
  503.                  }while(scelta<=0 || scelta>length(Giocatore2));
  504.                  switch(scelta){
  505.                     case 1:
  506.                         if (Presa(Tavolo,Giocatore2,PreseG2)){ //se prende sposta la carta dalla mano al mazzo
  507.                             last=2;
  508.                             if (Tavolo==NULL) scopeG2++; //se non ci sono più carte in tavola hai fatto scopa
  509.                             PreseG2=addBeg(PreseG2,Giocatore2->seme,Giocatore2->numero);
  510.                             temp=Giocatore2;
  511.                             Giocatore2=Giocatore2->Next;
  512.                             delete temp;
  513.                         }
  514.                         else { //se no aggiungila in tavola
  515.                             Tavolo=addBeg(Tavolo,Giocatore2->seme,Giocatore2->numero);
  516.                             temp=Giocatore2;
  517.                             Giocatore2=Giocatore2->Next;
  518.                             delete temp;
  519.                         }
  520.                         break;
  521.                     case 2:
  522.                         if (Presa(Tavolo,Giocatore2->Next,PreseG2)){ //se prende sposta la carta dalla mano al mazzo
  523.                             last=2;
  524.                             if (Tavolo==NULL) scopeG2++; //se non ci sono più carte in tavola hai fatto scopa
  525.                             PreseG2=addBeg(PreseG2,Giocatore2->Next->seme,Giocatore2->Next->numero);
  526.                             temp=Giocatore2->Next;
  527.                             Giocatore2->Next=Giocatore2->Next->Next;
  528.                             delete temp;
  529.                         }
  530.                         else { //se no aggiungila in tavola
  531.                             Tavolo=addBeg(Tavolo,Giocatore2->Next->seme,Giocatore2->Next->numero);
  532.                             temp=Giocatore2->Next;
  533.                             Giocatore2->Next=Giocatore2->Next->Next;
  534.                             delete temp;
  535.                         }
  536.                         break;
  537.                     case 3:
  538.                         if (Presa(Tavolo,Giocatore2->Next->Next,PreseG2)){ //se prende sposta la carta dalla mano al mazzo
  539.                             last=2;
  540.                             if (Tavolo==NULL) scopeG2++; //se non ci sono più carte in tavola hai fatto scopa
  541.                             PreseG2=addBeg(PreseG2,Giocatore2->Next->Next->seme,Giocatore2->Next->Next->numero);
  542.                             temp=Giocatore2->Next->Next;
  543.                             Giocatore2->Next->Next=Giocatore2->Next->Next->Next;
  544.                             delete temp;
  545.                         }
  546.                         else { //se no aggiungila in tavola
  547.                             Tavolo=addBeg(Tavolo,Giocatore2->Next->Next->seme,Giocatore2->Next->Next->numero);
  548.                             temp=Giocatore2->Next->Next;
  549.                             Giocatore2->Next->Next=Giocatore2->Next->Next->Next;
  550.                             delete temp;
  551.                         }
  552.                         break;
  553.                  }
  554.              }
  555.              // ridò le carte
  556.              for (int i=0;i<3;i++){
  557.                 Mazzo=EstraiPrima(Mazzo,Giocatore1);
  558.                 Mazzo=EstraiPrima(Mazzo,Giocatore2);
  559.             }
  560.          }
  561.          //fine round
  562.          //tutto quello che c'è nel tavolo va all'ultimo che ha preso:
  563.          if (last==1){
  564.             while(Tavolo!=NULL){
  565.                 Tavolo=EstraiPrima(Tavolo,PreseG1);
  566.             }
  567.          }
  568.          else{
  569.             while(Tavolo!=NULL){
  570.                 Tavolo=EstraiPrima(Tavolo,PreseG2);
  571.             }
  572.          }
  573.          //calcolo i punti
  574.          scelta=Primiera(PreseG1,PreseG2);
  575.          scopeG1+=ContaPunti(PreseG1);
  576.          scopeG2+=ContaPunti(PreseG2);
  577.          if (scelta==1) scopeG1++;
  578.          if (scelta==2) scopeG2++;
  579.          puntiG1+=scopeG1;
  580.          puntiG2+=scopeG2;
  581.          clear;
  582.          cout << endl << "Punteggio di questa partita:" << endl << "Giocatore 1: " << scopeG1 << " Punti" << endl << "Giocatore 2: " << scopeG2 << " Punti"
  583.          << endl << endl << "Punteggio Totale:" << endl << "Giocatore 1: " << puntiG1 << " Punti" << endl << "Giocatore 2: " << puntiG2 << " Punti";
  584.          //resetto
  585.          Giocatore1=Libera(Giocatore1);
  586.          Giocatore2=Libera(Giocatore2);
  587.          PreseG1=Libera(PreseG1);
  588.          PreseG2=Libera(PreseG2);
  589.          Mazzo=Libera(Mazzo);
  590.          Tavolo=Libera(Tavolo);
  591.          scopeG1=0;
  592.          scopeG2=0;
  593.          pausa();
  594.      }
  595.      clear;
  596.      cout << endl << "Partita Terminata, Ha vinto il Giocatore " << (puntiG1>puntiG2 ? '1' : '2');
  597.      Giocatore1=Libera(Giocatore1);
  598.      Giocatore2=Libera(Giocatore2);
  599.      PreseG1=Libera(PreseG1);
  600.      PreseG2=Libera(PreseG2);
  601.      Mazzo=Libera(Mazzo);
  602.      Tavolo=Libera(Tavolo); //libero la memoria
  603.      pausa();
  604.      return 0;
  605.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement