-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbinary.c
More file actions
53 lines (46 loc) · 763 Bytes
/
Copy pathbinary.c
File metadata and controls
53 lines (46 loc) · 763 Bytes
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
/* binary.c
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "binary.h"
extern struct field field[XMAX][YMAX];
void set_value(struct field *f, int value)
{
f->value = value;
init_link(f);
}
void init_link(struct field *f)
{
f->link.x = -1;
f->link.y = -1;
}
void init_field(int x, int y, int value)
{
set_value(&(field[x][y]), value);
field[x][y].initial = (value == -1 ? 0 : 1);
}
int get_left(void)
{
int count=0;
int x,y;
for (y=0; y<YMAX; y++) {
for (x=0; x<XMAX; x++) {
if (field[x][y].value == -1)
count++;
}
}
return count;
}
int is_solved(void)
{
int x,y;
for (y=0; y<YMAX; y++) {
for (x=0; x<XMAX; x++) {
if (field[x][y].value == -1)
return 0;
}
}
return 1;
}