Advertisement
Kali_prasad

cards game by kaka

Mar 9th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //code AUTHOR:KAKA
  4. bool checknext(int p,vector<int> v,int i,int temp)
  5. {
  6.     bool flag=true;
  7.     int j;
  8.     for(j=i+1;j<=temp&&j<=p+i;j++)
  9.     {
  10.         if(v[j]>=11||v[j]==1)
  11.         {
  12.             flag=false;
  13.             break;
  14.         }
  15.     }
  16.    
  17.     return flag&&(j<=temp+1);
  18. }
  19. int main()
  20. {
  21.     int n;
  22.    // cin>>n;
  23.     //int temp=n;
  24.     vector<int> v={3,2,1,5,6,4,8,11,2,3,2,13,6,10,6};//vector is similar to array except we need not to specify its size
  25.    /* while(n)
  26.     {
  27.         int dummy;
  28.         cin>>dummy;
  29.       v.push_back(dummy);//loading the vector or array with n cards  
  30.       n--;
  31.     }*/
  32.     n=v.size();
  33.     int temp=n;
  34.     int a=0,b=0,i=0;
  35.     bool flag=true;
  36.     while(n>0)
  37.     {
  38.        
  39.         int points=0,next=1;
  40.         cout<<v[i];
  41.         switch(v[i]){
  42.             case 1:checknext(4,v,i,temp)?(points=4,next=5):(points=0,next=1);break;
  43.             case 11:checknext(1,v,i,temp)?(points=1,next=2):(points=0,next=1);break;
  44.             case 12:checknext(2,v,i,temp)?(points=2,next=3):(points=0,next=1);break;
  45.             case 13:checknext(3,v,i,temp)?(points=3,next=4):(points=0,next=1);break;
  46.         }
  47.         //cout<<points;
  48.         if(flag)
  49.         {
  50.            cout<<":a"<<endl;
  51.           a+=points;
  52.           if(points)
  53.           cout<<"a scores:"<<points<<endl;
  54.         }
  55.         else
  56.         {
  57.            cout<<":b"<<endl;
  58.            b+=points;
  59.            if(points)
  60.           cout<<"b scores:"<<points<<endl;
  61.         }
  62.         n=n-next;
  63.         i=i+next;
  64.         flag=!flag; //toggling the chance
  65.     }
  66.     cout<<"a points:"<<a<<endl;
  67.     cout<<"b points:"<<b<<endl;
  68.    
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement