-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablice.c
72 lines (64 loc) · 1.44 KB
/
tablice.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
#include <stdio.h>
#include <time.h>
void flip_the_light(int x, int y, int tab[5][5], int size)
{
if(x <= size && x >= 0 && y <= size && y >= 0 )
{
tab[x][y] = (tab[x][y] == 0) ? 1:0;
if(x != 0)
tab[x-1][y] = (tab[x-1][y] == 0) ? 1:0;
if(x != size-1)
tab[x+1][y] = (tab[x+1][y] == 0) ? 1:0;
if(y != 0)
tab[x][y-1] = (tab[x][y-1] == 0) ? 1:0;
if(y != size-1)
tab[x][y+1] = (tab[x][y+1] == 0) ? 1:0;
}
}
void fill_randomly(int size, int table[5][5])
{
srand(time(NULL));
int temp_w, temp_h;
for(temp_w = 0; temp_w < size; temp_w++)
{
for(temp_h = 0; temp_h < size; temp_h++)
{
table[temp_w][temp_h] = (rand()%100)%2;
}
}
}
void empty(int size, int table[5][5])
{
int temp_w, temp_h;
for(temp_w = 0; temp_w < size; temp_w++)
{
for(temp_h = 0; temp_h < size; temp_h++)
{
table[temp_w][temp_h] = 0;
}
}
}
void full(int size, int table[5][5])
{
int temp_w, temp_h;
for(temp_w = 0; temp_w < size; temp_w++)
{
for(temp_h = 0; temp_h < size; temp_h++)
{
table[temp_w][temp_h] = 1;
}
}
}
int did_i_win(int table[5][5])
{
int i,j,suma=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
suma = suma+table[i][j];
}
}
if(suma==0){return 1;}
else {return 0;}
}