Домино(линейный вариант)

 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
89
90
91
92
93
94
95
96
#define SIZE 28
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <locale.h>
typedef struct
{
char num1;
char num2;
char flag;
} domino;
int main()
{
setlocale(0, "");
int i, j, f;
domino domarr[SIZE];
domino tmp;
srand(time(0));
domarr[0].num1 = 0;
domarr[0].num2 = 0;
domarr[0].flag = 1;
for (i = 1; i != SIZE; ++i)
{
domarr[i].flag = 1;
if (domarr[i - 1].num1 == domarr[i - 1].num2)
{
domarr[i].num1 = domarr[i - 1].num1 + 1;
domarr[i].num2 = 0;
}
else
{
domarr[i].num1 = domarr[i - 1].num1;
domarr[i].num2 = domarr[i - 1].num2 + 1;
}
}
//Перемешивание
for (i = 1; i != SIZE; ++i)
{
j = rand() % SIZE;
tmp.num1 = domarr[i].num1;
tmp.num2 = domarr[i].num2;
domarr[i].num1 = domarr[j].num1;
domarr[i].num2 = domarr[j].num2;
domarr[j].num1 = tmp.num1;
domarr[j].num2 = tmp.num2;
}
//Играем
for (i = 0; i != SIZE; ++i)
printf("%d) %d; %d\n", i, domarr[i].num1, domarr[i].num2);
printf("\nНачинаем\n");
domarr[0].flag = 0;
j = 0;
printf("(%d : %d)", domarr[0].num1, domarr[0].num2);
while (1)
{
f = 0;
for (i = 1; i != SIZE; ++i)
{
if (domarr[i].flag)
{
if (domarr[j].num2 == domarr[i].num1)
{
f = 1;
j = i;
domarr[i].flag = 0;
printf(" - (%d : %d)", domarr[i].num1, domarr[i].num2);
break;
}
else
if (domarr[j].num2 == domarr[i].num2)
{
f = 1;
j = i;
domarr[i].flag = 0;
domarr[i].num1 += domarr[i].num2;
domarr[i].num2 = domarr[i].num1 - domarr[i].num2;
domarr[i].num1 = domarr[i].num1 - domarr[i].num2;
printf(" - (%d : %d)", domarr[i].num1, domarr[i].num2);
break;
}
}
}
if (!f) break;
}
printf("\n");
return 0;
}