biji

#include <stdio.h>

#define TRUE 1
#define FALSE 0


typedef struct
 {
  char scoreA;
  char scoreB;
 }Match_t;
typedef struct
 {
  char An;
  char Bn;
  Match_t Match[7];
 }Score_t;
 
int shot()
{
 FILE *fp;
 static int nIndex = 0;
 static int inputData[200] = {-1};
 static int isfirst = 1;
 int i;
 if (isfirst)
 {
  fp = fopen("D://book1.txt", "r");
  for (i = 0; i < 200; i++)
  {
   if (fscanf(fp,"%d", &inputData[i]) == EOF)
   break;
  }
  isfirst = 0;
  fclose(fp);
 }
 if (nIndex == 200)
 {
  return -1;
 }
 return inputData[nIndex++];
}

void Output(Score_t *p)
{
 FILE *fp = fopen("D://scores.txt", "w");
 int i;
 fprintf(fp, "==================A VS B Result=================/n");
 fprintf(fp, "A VS B = %d:%d/n",  p->An, p->Bn);
 for ( i = 0; i < (p->An + p->Bn); i++)
 {
  fprintf(fp, "%dst Match Scores is %d: %d/n", i+1, p->Match[i].scoreA,
   p->Match[i].scoreB);
 }
 fprintf(fp, "/n");
 fclose(fp);
}

 
int main()
{
 Score_t Score;
 Score_t *pScore;
 pScore = &Score;
 int iChange = TRUE;
 int iWhoFirst = 0;
 
 //struct initalization
 int i = 0;
 for (i = 0; i < 7; i++)
 {
  pScore->Match[i].scoreA = 0;
  pScore->Match[i].scoreB = 0;
 }
 pScore->An = 0;
 pScore->Bn = 0;
 
 int iFlag = 2;
 char *pWinScore = NULL;
 int iGetScore = 0;
 int k = 0;
 int m = 0;
 while( m < 77)
 { 
  iGetScore = shot();
  m++;
  printf("%d次取得%d/n", m,iGetScore);
  if (pScore->Match[pScore->An + pScore->Bn].scoreA == 10 &&
   pScore->Match[pScore->An + pScore->Bn].scoreB == 10 )
  {
   iFlag=1;
  }
  //=================================================
   if ( iWhoFirst % 2 == 0)//A开局
   {
    //int k = 0;
    //k++;
    //printf("=======================================/n");
    if ( iGetScore == (1 && iChange))
    pWinScore = &(pScore->Match[pScore->An + pScore->Bn].scoreA);
    else
    pWinScore = &(pScore->Match[pScore->An + pScore->Bn].scoreB);
    
    *pWinScore = *pWinScore + 1;
    k++;
    if (k == 2 && iFlag == 1)
     k = 1;
    if (k == iFlag)
    {
     k = 0;
     if (iChange == TRUE)
     {
      iChange = FALSE;
      printf("==========轮到B了/n");
     }
     else
     {
      iChange=TRUE;
      printf("===============轮到A了/n");
     }
     
    };
 
   }
   else//B开局
   {
   //printf("=======================================/n");
    if ( iGetScore == (1 && iChange))
    pWinScore = &(pScore->Match[pScore->An + pScore->Bn].scoreB);
    else
    pWinScore = &(pScore->Match[pScore->An + pScore->Bn].scoreA);
    
    *pWinScore += 1;
    k++;
    if (k == 2 && iFlag == 1)
     k = 1;
    if (k == iFlag)
    {
     k = 0;
     if (iChange == TRUE)
     {
      iChange = FALSE;
      printf("===========轮到B了/n");
     }
     else
     {
      iChange=TRUE;
      printf("===========轮到A了/n");
     }
    };
   }
  //===================================================
  
    
    if ((pScore->Match[pScore->An + pScore->Bn].scoreA >=11) &&
     ((pScore->Match[pScore->An + pScore->Bn].scoreA -
     pScore->Match[pScore->An + pScore->Bn].scoreB) >=2))
     {
      pScore->An += 1;
      iWhoFirst += 1;
      k = 0;
      iChange = TRUE;
      int b = (pScore->Match[pScore->An + pScore->Bn].scoreA);
      printf("A=================%d===============%d/n",b, pScore->An);
     }
    else
    {
     if ((pScore->Match[pScore->An + pScore->Bn].scoreB >=11) &&
     ((pScore->Match[pScore->An + pScore->Bn].scoreB -
     pScore->Match[pScore->An + pScore->Bn].scoreA) >=2))
     {
      pScore->Bn += 1;
      iWhoFirst += 1;
      k = 0;
      iChange = TRUE;
      int a = pScore->Match[ pScore->An + pScore->Bn].scoreB;
      printf("B================%d================%d/n", a,pScore->Bn);
     }
    }
    if (pScore->An == 4 || pScore->Bn == 4)
    {
     Output(pScore);
     exit(0);
    }
  }
  return 0;
 }
 
 
 
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值