⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 suoha_algri.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
   case FOUR_DUIZI:
      for (i=0; i<=3; i++)
      {
         if (FirstNum(whoCards[4])==FirstNum(whoCards[i]))
         {
            samenum++;        
            same = whoCards[i];
         }
      }
      if (samenum==2)
      {
         pc_Ct.cardType = SHANTIAO;
         pc_Ct.bigcard = whoCards[4];
         return pc_Ct;
      } else if (samenum==1)
      {
         if (FirstNum(whoCards[4])<FirstNum(fourStatus.bigcard))
         {
            pc_Ct.bigcard = fourStatus.bigcard;
            pc_Ct.smallcard = whoCards[4];
         } else
         {
            if (SecondNum(same)<SecondNum(whoCards[4]))
               pc_Ct.bigcard = whoCards[4];
            else
               pc_Ct.bigcard = same;
            pc_Ct.smallcard = fourStatus.bigcard;
         }
         pc_Ct.cardType = LIANGDUI;
         return pc_Ct;
      } else
      {
         pc_Ct.bigcard = fourStatus.bigcard;
         pc_Ct.cardType = DUIZI;
         return pc_Ct;
      }
      break;
   case FOUR_SHANPAI:
      for (i=0; i<=3; i++)
      {
         if (FirstNum(whoCards[4])==FirstNum(whoCards[i]))
         {
            samenum++;        
            same = whoCards[i];
         }
      }
      if (samenum==1)
      {
         if (SecondNum(same)<SecondNum(whoCards[4]))
            pc_Ct.bigcard = whoCards[4];
         else
            pc_Ct.bigcard = same;
         pc_Ct.cardType = DUIZI;
         return pc_Ct;
      } else
      {
         CT_shanpaiclass = ClassifyShanPai(whoCards);
         pc_Ct.cardType = CT_shanpaiclass.cardType;
         pc_Ct.bigcard = CT_shanpaiclass.bigcard;
         return pc_Ct;
      }
      break;
   }
   return pc_Ct;
}

CardType ClassifyShanPai( unsigned short* whoCards)
{
   int bigCard=0;
   int smallCard=0;
   int i=0;
   BOOL colorsame;
   CardType pc_shanpai;
//get the greatest and smallest cards of five cards
   if (FirstNum(whoCards[0])<FirstNum(whoCards[1]))
   {
      smallCard = whoCards[0];
      bigCard = whoCards[1];
   } else
   {
      smallCard = whoCards[1];
      bigCard = whoCards[0];
   }
   for (i=2; i<=4; i++)
   {
      if (FirstNum(whoCards[i])>FirstNum(bigCard))
         bigCard = whoCards[i];
      if (FirstNum(whoCards[i])<FirstNum(smallCard))
         smallCard = whoCards[i];
   }
//are colors of five cards the same?
   if ((SecondNum(whoCards[0])==SecondNum(whoCards[1])) &&
       (SecondNum(whoCards[0])==SecondNum(whoCards[2])) &&
       (SecondNum(whoCards[0])==SecondNum(whoCards[3])) &&
       (SecondNum(whoCards[0])==SecondNum(whoCards[4])) )
      colorsame = true;
   else
      colorsame = FALSE;
//decide whether the cards form TONGHUASUN or SUNZI
   if (((FirstNum(bigCard)==4)||(FirstNum(smallCard)==2)||
        ((FirstNum(bigCard)==5)&&(FirstNum(smallCard)==1)))&&colorsame)
   {
      pc_shanpai.bigcard = bigCard;
      pc_shanpai.cardType = TONGHUASUN;
      return pc_shanpai;
   } else
      if (((FirstNum(bigCard)==4)||(FirstNum(smallCard)==2)||
           ((FirstNum(bigCard)==5)&&(FirstNum(smallCard)==1)))&&!colorsame)
   {
      pc_shanpai.bigcard = bigCard;
      pc_shanpai.cardType = SUNZI;
      return pc_shanpai;
   } else if (colorsame)
   {
      pc_shanpai.bigcard = bigCard;
      pc_shanpai.cardType = TONGHUA;
      return pc_shanpai;
   } else
   {
      pc_shanpai.bigcard = bigCard;
      pc_shanpai.cardType = SHANPAI;
      return pc_shanpai;
   }

}

///////////////////////////////////////////////////////////////////////////////
//According the card types classified by above module, the computer will take an action.
//This module will guide the compute how to do? There are some conditions,such as 
//two, three, four, five cards to discuss.
//the action of computer is returned!
//////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
/*******************************************************************************************************
    
   This module is used to decide to how to act when the computer is chipping in or following or quiting
    Input the card types of the player and computer, and who is being turned
    output the actions of the computer

********************************************************************************************************/
//4 判断两张牌的时候电脑和玩家的大小,然后决定下多少的注
unsigned long Two_Greater(CardType c_CT, unsigned short turnwho)
{
   int randnum, possible, actionnum;
   switch (c_CT.cardType)
   {
   case TWO_DUIZI:
      if (turnwho==COMPUTER)
      {
         if (c_M>=100)
         {
//				srand((unsigned)rvf_get_tick_count());
            randnum = rand();
            possible = randnum-(randnum/100)*100;
            if (possible>70)
               return TWOCARDS50;  //the possibility of computer chips $50 in is 30% 
            else
               return TWOCARDS100;
         } else if (c_M>=50)
            return TWOCARDS50;
         else if (c_M>=10)
            return TWOCARDS10;
         else
            return NOMONEY;
      } else
         return TWOCARDSFOLL;
      break;
   case TWO_SHANPAI:
      if (turnwho==COMPUTER)
      {
         if ((FirstNum(c_CT.bigcard)>FirstNum(p_Cards[1])) ||
             ((FirstNum(c_CT.bigcard)==FirstNum(p_Cards[1])) &&
              (SecondNum(c_CT.bigcard)>SecondNum(p_Cards[1]))))
            actionnum = Produce3Poss(30,40,30);
         else
            actionnum = Produce3Poss(40,40,20);
         return ClassifyStake(2, actionnum);   //2 means the action is taken after sending the second cards 
      } else
      {
         return TWOCARDSFOLL;
      }
      break;
   }
   return 0;
}

unsigned long Three_Greater(CardType c_CT, CardType p_CT, unsigned short turnwho)
{
   int bigger=0, actionnum;
   unsigned char Poss32[11][5];
   if (focus_opp==1)
      strcpy((char *)& Poss32, (char *)& Poss32_opp1);
   else if (focus_opp==2)
      strcpy((char *)& Poss32, (char *)& Poss32_opp2);
   else
      strcpy((char *)& Poss32, (char *)& Poss32_opp3);


   switch (c_CT.cardType)
   {
   case THREE_SHANTIAO:
      switch (p_CT.cardType)
      {
      case TWO_DUIZI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[0][0],Poss32[0][1],Poss32[0][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[1][0],Poss32[1][1],Poss32[1][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         }
         break;
      case TWO_SHANPAI:
         if (turnwho==COMPUTER)
         {
            actionnum = Produce3Poss(Poss32[2][0],Poss32[2][1],Poss32[2][2]);
            return ClassifyStake(3, actionnum);
         } else
         {
            return THREECARDSFOLL;
         }
         break;
      }
      break;
   case THREE_DUIZI:
      switch (p_CT.cardType)
      {
      case TWO_DUIZI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[3][0],Poss32[3][1],Poss32[3][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[4][0],Poss32[4][1],Poss32[4][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               actionnum = Produce2Poss(Poss32[4][3],Poss32[4][4]);
               return ClassifyFollorQuit(3,actionnum);
            }
         }
         break;
      case TWO_SHANPAI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[5][0],Poss32[5][1],Poss32[5][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[6][0],Poss32[6][1],Poss32[6][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL; //zhangzg 08/22/2002
//					actionnum = Produce2Poss(Poss32[6][3],Poss32[6][4]);
//					return ClassifyFollorQuit(3,actionnum);
            }
         }
         break;
      }
      break;
   case THREE_SHANPAI:
      switch (p_CT.cardType)
      {
      case TWO_DUIZI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[7][0],Poss32[7][1],Poss32[7][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               actionnum = Produce2Poss(Poss32[7][3],Poss32[7][4]);
               return ClassifyFollorQuit(3,actionnum);
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[8][0],Poss32[8][1],Poss32[8][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               actionnum = Produce2Poss(Poss32[8][3],Poss32[8][4]);
               return ClassifyFollorQuit(3,actionnum);
            }
         }
         break;
      case TWO_SHANPAI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[9][0],Poss32[9][1],Poss32[9][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[10][0],Poss32[10][1],Poss32[10][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               return THREECARDSFOLL;
            }
         }
         break;
      }
      break;
   }
   return 0;
}
//follow or quit are the same with three_greater when player put stake. But it is different when computer firstly put stake
unsigned long Three_Greater_Opp1(CardType c_CT, CardType p_CT, unsigned short turnwho, unsigned long pMoney) //zhangzg 08/23/2002
{
   int bigger=0, actionnum;
   unsigned char Poss32[11][5];
//	if(focus_opp==1)
   strcpy((char *)& Poss32, (char *)& Poss32_opp1);
   //else if(focus_opp==2)
   //strcpy((char *)& Poss32, (char *)& Poss32_opp2);
//	else
   //	strcpy((char *)& Poss32, (char *)& Poss32_opp3);


   switch (c_CT.cardType)
   {
   case THREE_SHANTIAO:
      switch (p_CT.cardType)
      {
      case TWO_DUIZI:
         bigger = CompareTwo(c_CT.bigcard, p_CT.bigcard);
         if (c_CT.bigcard==bigger)
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[0][0],Poss32[0][1],Poss32[0][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               actionnum = Produce3Poss(Poss32[0][0],Poss32[0][1],Poss32[0][2]);                
               if (c_M>(pMoney*(actionnum+1)))
                  return pMoney*(actionnum+1); //return more stake!
               else
                  return THREECARDSFOLL;
            }
         } else
         {//corresponds to a composite of both card types
            if (turnwho==COMPUTER)
            {
               actionnum = Produce3Poss(Poss32[1][0],Poss32[1][1],Poss32[1][2]);
               return ClassifyStake(3,actionnum);
            } else
            {
               actionnum = Produce3Poss(Poss32[1][0],Poss32[1][1],Poss32[1][2]);
               if (c_M>(pMoney*(actionnum+1)))
                  return pMoney*(actionnum+1); //return more stake!
               else
                  return THREECARDSFOLL;
            }
         }
         break;
      case TWO_SHANPAI:
         if (turnwho==COMPUTER)
         {
            actionnum = Produce3Poss(Poss32[2][0],Poss32[2][1],Poss32[2][2]);
            return ClassifyStake(3, actionnum);
         } else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -