-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGOL.ks
97 lines (97 loc) · 2.53 KB
/
GOL.ks
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
parameter height is 11, width is 11.
clearguis().
set options to gui(32 * width, 37 * height).
for x in range(height)
{
options:addhlayout().
for y in range(width)
{
options:widgets[x]:addcheckbox("", false).
local temp is options:widgets[x]:widgets[y]:style.
set temp:height to 0.
set temp:width to 0.
}
}
local start is options:addbutton("start").
options:show().
wait until start:takepress.
set start:text to "stop".
local gameStatus is list().
for x in range(height)
{
gameStatus:add(list()).
for y in range(width)
{
gameStatus[x]:add(options:widgets[x]:widgets[y]:pressed).
}
}
until false
{
if start:takepress
break.
for x in range(height)
{
for y in range(width)
{
local neighbours is 0.
local upwards is 0.
local sideways is 0.
if true
{
if x > 0
{
if options:widgets[x-1]:widgets[y]:pressed = true
set neighbours to neighbours + 1.
}
else set upwards to 1.
if x < height - 1
{
if options:widgets[x+1]:widgets[y]:pressed = true
set neighbours to neighbours + 1.
}
else set upwards to -1.
if y > 0
{
if options:widgets[x]:widgets[y-1]:pressed = true
set neighbours to neighbours + 1.
}
else set sideways to -1.
if y < width - 1
{
if options:widgets[x]:widgets[y+1]:pressed = true
set neighbours to neighbours + 1.
}
else set sideways to 1.
if upwards >= 0
{
if sideways >= 0
if options:widgets[x+1]:widgets[y-1]:pressed = true
set neighbours to neighbours + 1.
if sideways <= 0
if options:widgets[x+1]:widgets[y+1]:pressed = true
set neighbours to neighbours + 1.
}
if upwards <= 0
{
if sideways >= 0
if options:widgets[x-1]:widgets[y-1]:pressed = true
set neighbours to neighbours + 1.
if sideways <= 0
if options:widgets[x-1]:widgets[y+1]:pressed = true
set neighbours to neighbours + 1.
}
}
if neighbours > 3 or neighbours < 2
set gameStatus[x][y] to false.
if neighbours = 3
set gameStatus[x][y] to true.
}
}
for x in range(height)
{
for y in range(width)
{
set options:widgets[x]:widgets[y]:pressed to gameStatus[x][y].
}
}
}