Отчет_Владимиров_П_А_1363
.pdfreturn 2;
}
}
if (printf("\n") < 0)
{
printf("Error\n"); return 2;
}
}
return 5;
}
int main()
{
if (printf("Welcome to the Tic Tac toe game!\n")<0)
{
printf("Error!\n"); return 2;
}
if (printf("Your goal is to make a line of three ")<0)
{
printf("Error!\n"); return 2;
}
if (printf("crosses vertically or horizontally or diagonally!\n")<0)
31
{
printf("Error!\n"); return 2;
}
if (printf("You go first! Enter the number from 0 to 8 to make move!\n")<0)
{
printf("Error!\n"); return 2;
}
if (printf("Good luck!\n")<0)
{
printf("Error!\n"); return 2;
}
srand(time(NULL));
char field[3][3]= {{'_','_','_'},{'_','_','_'},{'_','_','_'}};
if (PrintField(field) != 5)
{
if(printf("Error while printing board\n")<0){
printf("Error\n"); return 2;
}
return 7;
}
32
if (printf("________\n") < 0)
{
printf("Error\n"); return 2;
}
while (1)
{
int posIndex;
if (scanf("%d", &posIndex) != 1)
{
if(printf("Incorrect
index\n")<0){
printf("Error\n"); return 2;
}
continue;
}
if (posIndex<0 || posIndex>8)
{
if(printf("Incorrect
index\n")<0){
printf("Error\n"); return 2;
}
continue;
}
if (field[posIndex / 3][posIndex %
33
3] != '_')
{
if(printf("Incorrect
index\n")<0){
printf("Error\n"); return 2;
}
continue;
}
field[posIndex / 3][posIndex % 3] =
'X';
if (PrintField(field) != 5)
{
if(printf("Error while printing
board\n")<0){
printf("Error\n"); return 2;
}
return 7;
}
if (printf("________\n") < 0)
{
printf("Error\n"); return 2;
}
int result = GameResult(field);
34
switch(result)
{
case 10:
if(printf(" You win\n")<0){ printf("Error\n"); return 2;
}
return 0; break;
case -10: if(printf("Computer
win\n")<0){
printf("Error\n"); return 2;
}
return 0; break;
case 0: if(printf("Draw\n")<0){
printf("Error\n"); return 2;
}
return 0; break;
}
if (ComputerMove(field) != 3)
35
{
if(printf("Error while making
move\n")<0){
printf("Error\n"); return 2;
}
return 6;
}
result = GameResult(field); if (PrintField(field) != 5)
{
printf("Error while printing
board\n");
return -1;
}
if (printf("________\n") < 0)
{
printf("Error while printing
board\n");
return -1;
}
switch(result)
{
case 10:
if(printf(" You win\n")<0){ printf("Error\n"); return 2;
36
}
return 0; break;
case -10: if(printf("Computer
win\n")<0){
printf("Error\n"); return 2;
}
return 0; break;
case 0: if(printf("Draw\n")<0){
printf("Error\n"); return 2;
}
return 0; break;
}
}
}
37
