C |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| #include <stdio.h>
#include <stdlib.h>
int a[3][3];
void pole ()
{
int i, j;
system (" ");
printf("_______\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("|");
if (a[i][j] == 1) printf("X");
else if (a[i][j] == -1) printf("0");
else printf(" ");
}
printf("|\n_______\n");
}
}
int test(int x,int y)
{
if((a[y][0] == a[y][1]) && (a[y][1] == a[y][2]) && (a[y][0] != 0)) return 1;
if((a[0][x] == a[1][x]) && (a[1][x] == a[2][x]) && (a[0][x] != 0)) return 1;
if((((a[0][0] == a[1][1]) && (a[1][1] == a[2][2]) && (a[0][0] != 0)) || ((a[0][2] == a[1][1]) && (a[1][1] == a[2][0]) && a[0][2] != 0))) return 1;
return 0;
}
int main(int argc, char *argv[])
{
char krestik_name[16];
char nolik_name[16];
int i, j, krok = 0;
printf("wprowadz nazwe gracza krzyze: ");
scanf("%s", krestik_name);
printf("wprowadz nazwe gry kolko: ");
scanf("%s", nolik_name);
while( krok<9 )
{
if(krok % 2 == 0)
printf ( "%s\n",nolik_name);
else
printf ("%s\n",krestik_name);
printf("koordynaty: ");
scanf("%d %d", &i, &j);
if (i < 1 || i > 3 || j< 1 || j > 3)
{
printf("blad \n");
continue;
}
if (a[i-1][j-1] != 0)
{
printf("Juz istnieje\n");
continue;
}
if(krok % 2 == 0) a[i-1][j-1] = -1;
else a[i-1][j-1] = 1;
pole ();
if (test(j-1, i-1))
{
if(krok % 2 == 0)
{printf ( "___________________\n");
printf ( "WIN____%s\n" ,nolik_name);
printf ( "___________________\n");}
else
{printf ( "___________________\n");
printf ("WIN_____%s\n",krestik_name);
printf ( "___________________\n");}
break;
}
krok++;
}
return 0;
} |
|
вот вариант этой проги - как-то дошла к нему..
может кому-то пригодиться
счас хочу 10на10 сделать, но вот где -то в "тест" ошибку допустила...
C |
1
2
3
4
5
6
7
8
| int test(int x,int y)
{ int i,j;
if((a[y][j] == a[y][j+1]) && (a[y][j+1] == a[y][j+2]) && (a[y][j+2] == a[y][j+3]) && (a[y][j+3] == a[y][j+4])&&(a[y][j] != 0)) return 1;
if((a[i][x] == a[i+1][x]) && (a[i+1][x] == a[i+2][x]) &&(a[i+2][x] == a[i+3][x]) && (a[i+3][x] == a[i+4][x]) && (a[i][x] != 0)) return 1;
if((((a[i][j] == a[i+1][j+1])&&(a[i+1][j+1] == a[i+2][j+2])&&(a[i+2][j+2] == a[i+3][j+3])&&(a[i+3][j+3] == a[i+4][j+4])&&(a[i][j] != 0)))||((a[i][j+4] == a[i+1][j+3]) && (a[i+1][j+3] == a[i+2][j+2]) &&(a[i+2][j+2] == a[i+3][j+1]) && (a[i+3][j+1] == a[i][j+4]) && a[i][j+4] != 0)) return 1;
return 0;
} |
|
может вы поймете где?