#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;
}