/
vertical_black.c
133 lines (123 loc) · 3.13 KB
/
vertical_black.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <gtk/gtk.h>
#include <stdio.h>
#include "base.h"
int found_bot_black(t_terrain* terrain, GtkWidget* button, int count)
{
int i;
t_terrain* move;
t_terrain* begin;
i = 1;
begin = terrain;
move = begin;
while (terrain->button != button)
terrain = terrain->next;
if (terrain->color == 0 && terrain->y <= 5)
{
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y + i))
move = move->next;
while (move->color == 1)
{
move = begin;
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y + i))
move = move->next;
count = count + 1;
i = i + 1;
}
}
if (check_end_black(move) == 0)
return (0);
return (count);
}
int found_top_black(t_terrain* terrain, GtkWidget* button, int count)
{
int i;
t_terrain* move;
t_terrain* begin;
i = 1;
begin = terrain;
move = begin;
while (terrain->button != button)
terrain = terrain->next;
if (terrain->color == 0 && terrain->y >= 2)
{
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y - i))
move = move->next;
while(move->color == 1)
{
move = begin;
while (move->x != terrain->x || move->y != terrain->y - i)
{
move = move->next;
if (move->next == 0)
break;
}
count = count + 1;
i = i + 1;
}
}
if (check_end_black(move) == 0)
return (0);
return (count);
}
void bot_capture_black(t_terrain* terrain, GtkWidget* button, int count)
{
t_terrain* move;
t_terrain* begin;
GdkColor black;
move = terrain;
begin = terrain;
gdk_color_parse ("black", &black);
while (terrain->button != button)
terrain = terrain->next;
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y + count))
move = move->next;
while (count != 0)
{
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y + count))
move = move->next;
gtk_widget_modify_bg(GTK_WIDGET(move->button), GTK_STATE_NORMAL, &black);
move->color = 2;
move = begin;
count = count - 1;
}
gtk_widget_modify_bg(GTK_WIDGET(terrain->button), GTK_STATE_NORMAL, &black);
terrain->color = 2;
}
void top_capture_black(t_terrain* terrain, GtkWidget* button, int count)
{
t_terrain* move;
t_terrain* begin;
GdkColor black;
move = terrain;
begin = terrain;
gdk_color_parse ("black", &black);
while (terrain->button != button)
terrain = terrain->next;
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y - count))
move = move->next;
while (count != 0)
{
while (move->next != 0 && (move->x != terrain->x || move->y != terrain->y - count))
move = move->next;
gtk_widget_modify_bg(GTK_WIDGET(move->button), GTK_STATE_NORMAL, &black);
move->color = 2;
move = begin;
count = count - 1;
}
gtk_widget_modify_bg(GTK_WIDGET(terrain->button), GTK_STATE_NORMAL, &black);
terrain->color = 2;
}
int found_vertical_black(t_terrain* terrain, GtkWidget* button)
{
int count;
int count2;
count = found_top_black(terrain, button, 0);
if (count != 0)
top_capture_black(terrain, button, count);
count2 = found_bot_black(terrain, button, 0);
if (count2 != 0)
bot_capture_black(terrain, button, count2);
if (count == 0 && count2 == 0)
return (0);
return (1);
}